[ Forms ]
Dropzone & FileItem
Dropzone accepts files by drag-and-drop, click or keyboard, with type and size checks. FileItem shows each file with its progress and actions.
Import#
import { Dropzone, FileItem } from 'reusify-ui';When to use#
- Uploading attachments, imports or media. Pair the two: Dropzone collects files, FileItem lists them.
Examples#
Upload with progress#
Drop or browse files (they stay in your browser). Progress here is simulated.
File states#
<FileItem name="Report.pdf" size={2457600} status="uploading" progress={42} onRemove={cancel} />
<FileItem name="Logo.svg" size={18432} status="complete" />
<FileItem name="Video.mov" size={524288000} status="error" error="Too large (max 100MB)" onRemove={remove} />Used in designs#
Dropzone & FileItem in real layouts: this design uses it. Open one to try it and copy the code.
API reference#
<Dropzone />
Pass children to replace the default icon, title and description.
| Prop | Type | Default | Description |
|---|---|---|---|
onFiles | (files: File[]) => void | - | Accepted files. |
onReject | (items: { file, reason: 'type' | 'size' }[]) => void | - | Files that failed the checks. |
accept | string | - | e.g. "image/*,.pdf". Applied to the picker and to dropped files. |
multiple | boolean | true | Allow several files. |
maxSize | number | - | Max bytes per file. |
disabled | boolean | false | Disable the zone. |
icon / title / description | ReactNode | - | Override the default content. |
onFiles-(files: File[]) => voidAccepted files.
onReject-(items: { file, reason: 'type' | 'size' }[]) => voidFiles that failed the checks.
accept-stringe.g. "image/*,.pdf". Applied to the picker and to dropped files.
multipletruebooleanAllow several files.
maxSize-numberMax bytes per file.
disabledfalsebooleanDisable the zone.
icon / title / description-ReactNodeOverride the default content.
<FileItem />
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | - | File name (truncated with a title tooltip). |
size | number | string | - | Bytes (formatted) or a ready string. |
status | 'uploading' | 'complete' | 'error' | 'complete' | Row state. |
progress | number | 0 | Percent while uploading. |
icon | ReactNode | - | Custom file icon. |
error | ReactNode | - | Message shown when status is error. |
onRemove | () => void | - | Shows a remove / cancel button. |
action | ReactNode | - | Extra element on the right, e.g. a menu. |
name-stringFile name (truncated with a title tooltip).
size-number | stringBytes (formatted) or a ready string.
status'complete''uploading' | 'complete' | 'error'Row state.
progress0numberPercent while uploading.
icon-ReactNodeCustom file icon.
error-ReactNodeMessage shown when status is error.
onRemove-() => voidShows a remove / cancel button.
action-ReactNodeExtra element on the right, e.g. a menu.
Accessibility#
- The Dropzone is a focusable role="button"; Enter and Space open the file picker.
- Upload progress is a labelled progressbar, and the remove button names the file.
- formatBytes is exported if you need the same size formatting elsewhere.