UNPKG

1.56 kBMarkdownView Raw
1---
2title: Drop Zone
3isExperimentalPackage: true
4---
5
6The `Dropzone` component lets users upload files by clicking on, or dragging and
7dropping onto the "drop zone". It can also be be triggered by clicking on the
8label.
9
10## Usage
11
12### Field
13
14Each `Dropzone` must be accompanied by a [`Field`](/package/field) with a label.
15Effective form labeling helps inform users which selection to make.
16
17## Examples
18
19### Accept
20
21By providing an `accept` prop, we can make the `Dropzone` only accept certain
22file types.
23
24The value must be an object with a common MIME type as keys and an array of file
25extensions as values (similar to
26[showOpenFilePicker's](https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker)
27types 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
42By default, once a file as been added to the Dropzone, a document icon will
43displayed next to the file name in the list below. If you have uploaded an
44image, 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" />