[ 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.

2 examplesDark modeAccessible

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.

Drag & drop files hereor browse to choose files (max 10MB)
const [files, setFiles] = useState([]);

<Dropzone
  maxSize={10 * 1024 * 1024}
  onFiles={(list) => setFiles((all) => [...all, ...list.map(toUpload)])}
  onReject={(rejected) => toast.error(rejected[0].reason)}
/>
{files.map((f) => (
  <FileItem
    key={f.id}
    name={f.name}
    size={f.size}
    status={f.progress < 100 ? 'uploading' : 'complete'}
    progress={f.progress}
    onRemove={() => remove(f.id)}
  />
))}

File states#

Report.pdf
2.3MBUploading…
42%
Logo.svg
18KBCompleted
Video.mov
500MBToo large (max 100MB)
<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.

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.

multipletrue
boolean

Allow several files.

maxSize-
number

Max bytes per file.

disabledfalse
boolean

Disable the zone.

icon / title / description-
ReactNode

Override the default content.

<FileItem />

name-
string

File name (truncated with a title tooltip).

size-
number | string

Bytes (formatted) or a ready string.

status'complete'
'uploading' | 'complete' | 'error'

Row state.

progress0
number

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.

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.