1 | ---
|
2 | title: Drop Zone
|
3 | isExperimentalPackage: true
|
4 | ---
|
5 |
|
6 | The `Dropzone` component lets users upload files by clicking on, or dragging and
|
7 | dropping onto the "drop zone". It can also be be triggered by clicking on the
|
8 | label.
|
9 |
|
10 | ## Usage
|
11 |
|
12 | ### Field
|
13 |
|
14 | Each `Dropzone` must be accompanied by a [`Field`](/package/field) with a label.
|
15 | Effective form labeling helps inform users which selection to make.
|
16 |
|
17 | ## Examples
|
18 |
|
19 | ### Accept
|
20 |
|
21 | By providing an `accept` prop, we can make the `Dropzone` only accept certain
|
22 | file types.
|
23 |
|
24 | The value must be an object with a common MIME type as keys and an array of file
|
25 | extensions as values (similar to
|
26 | [showOpenFilePicker's](https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker)
|
27 | types accept option).
|
28 |
|
29 | ```jsx live
|
30 | <Stack gap="large">
|
31 | <Field label="Upload image" description="Accepts common image file formats">
|
32 | <Dropzone accept={{ 'image/*': ['.png', '.jpg'] }} />
|
33 | </Field>
|
34 | <Field label="Upload PDF" description="Only accepts PDF files">
|
35 | <Dropzone accept={{ 'application/pdf': '.pdf' }} />
|
36 | </Field>
|
37 | </Stack>
|
38 | ```
|
39 |
|
40 | ### Show Image Thumbnails
|
41 |
|
42 | By default, once a file as been added to the Dropzone, a document icon will
|
43 | displayed next to the file name in the list below. If you have uploaded an
|
44 | image, you can use the `showImageThumbnails` to show an image preview instead.
|
45 |
|
46 | ```jsx live
|
47 | <Field label="Upload image" description="Drop an image here to see a preview">
|
48 | <Dropzone accept={{ 'image/*': ['.png', '.jpg'] }} showImageThumbnails />
|
49 | </Field>
|
50 | ```
|
51 |
|
52 | ## Props
|
53 |
|
54 | <PropsTable displayName="Dropzone" />
|