summaryrefslogtreecommitdiff
path: root/src/lib/Dropzone.svelte
blob: 07cc0e9c2e4cdef150f0b1257c3631626fd4deeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script>
  export let files;
  export let supportedFormats;
  export let onKeydown;
  export let onClick;
  export let onDrop;
  export let onChange;
</script>

<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div
  id="dropzone"
  tabindex={0}
  on:keydown={onKeydown}
  on:click={onClick}
  on:dragover|preventDefault|stopPropagation
  on:drop|preventDefault|stopPropagation={onDrop}
>
  <label id="file-label" for="file-input"
    >Drag and drop files here or click to upload.</label
  >
  <input
    id="file-input"
    type="file"
    name="files[]"
    accept={supportedFormats.join(",")}
    multiple
    on:change={onChange}
    bind:files
  />
</div>

<style>
  #dropzone {
    display: flex;
    height: 100px;
    width: 100%;
    border: 5px dotted black;
    padding: 15px;
    z-index: 10;
  }

  #file-label {
    z-index: -1;
    font-weight: 600;
  }

  #file-input {
    display: none;
  }

  #dropzone:hover {
    cursor: pointer;
    border: 5px dotted #05345f;
    color: #05345f;
  }

  @media only screen and (max-device-width: 812px) {
    #dropzone {
      width: 100%;
    }
  }
</style>