Drop or browse
Drag files over it (Stubby comes out with a sheet of paper), drop them, or click / Tab and press Enter to browse. Pick something that is not an image, or bigger than 2 MB, or a fifth file, and the reason appears in red.
A patch of paper, stitched round its edge, that files can be dropped on or picked into. It checks type, size and count and tells you why a file was refused; it hands you File objects and shows them in a ruled list with thumbnails and progress lines. It uploads nothing: that part is yours.
npx shadcn@latest add @wobko/dropzone第一次使用?先把 registry 加进 components.json。 如何安装
Drag files over it (Stubby comes out with a sheet of paper), drop them, or click / Tab and press Enter to browse. Pick something that is not an image, or bigger than 2 MB, or a fifth file, and the reason appears in red.
No upload is built in: you drive each row from your own request. Here a timer stands in for the network: rows fill their highlighter line, finish with a green tick, and one file is made to fail so you can see the red rule and its wavy line.
multiple={false}: one file, a new one replaces the old. A narrow zone whose own content follows the state through useDropzone (here: the chosen picture as a taped polaroid).
The zone is a plain form field: name puts the files in FormData, required stops the submit until one is chosen (the browser points at the input), and invalid draws the red stitches. Submit empty, then with a file.
The state and the layout (a flex column). Without children it is a `DropzoneArea` (icon, title, description), `DropzoneRejections` and `DropzoneList`. The accepted files are `File` objects; uncontrolled (`defaultFiles`) or controlled (`files` + `onFilesChange`, called with the whole list).
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| accept | string | string[] | - | What the picker offers and what is accepted: `image/*`, `image/png`, `.pdf`, comma separated or an array. Extensions are checked case-insensitively. |
| multiple | boolean | true | `false`: one file, a new one replaces the old, extra files in one drop are refused. |
| maxFiles / maxSize / minSize | number | - | How many files in all, and the size limits in bytes. |
| validator | (file: File) => FileError | null | - | Your own check per file; return `{ code, message }` to refuse it. |
| messages | Partial<Record<code, string | ((file) => string)>> | - | Your words for the reasons (`file-invalid-type`, `file-too-large`, `file-too-small`, `too-many-files`), for translation. |
| onDrop / onReject | (accepted, rejected) => void | - | Called for every drop or pick with what was taken and what was not (each rejection has its `file` and `errors[{ code, message }]`). |
| id / name / required | - | On the file input (`id` is for a Label). The accepted files are put in it (DataTransfer) so a plain <form> submits them, dropped ones included; a form reset empties the list with the input (or goes back to `defaultFiles`). | |
| disabled / invalid | boolean | - | Pale dashed stitches, nothing happens / red stitches on a pink wash (also `aria-invalid` on the input). |
The patch you drop on: a `<label>` (a click anywhere opens the picker) round the real, visually hidden file input (Tab reaches it, Enter and Space open the picker). Drawn as a paper-shade patch with a cut edge and an even running stitch a few pixels in (stitches of uneven length, even in calm); the stitches turn blue on a yellow wash while a file is over it, and the drawing wiggles. `inputProps` reaches the input.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| inputProps | InputHTMLAttributes | - | `aria-label`, `capture`, `webkitdirectory`... |
| seed | string | number | - | Pins the hand: the same seed always sews the same patch. |
One file: a polaroid thumbnail for images (a little crooked) or a file icon, name, size, an optional highlighter progress line and status, and a remove button. The ruled pencil line under the row is the drawing; an error makes it red and wavy.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| file | File | - | The file to show. |
| progress / status | number 0-100 / "idle" | "uploading" | "done" | "error" | - | Yours to drive from your upload. Uploading with a progress shows a `progressbar`. |
| error | string | - | Shown in red when `status` is "error". |
| thumbnail | boolean | true | Preview image files. |
| onRemove / removeLabel | - | Replace the default removal; name the x. |
CLI 会复制进你项目的文件。
正在加载源码