compacto-ui

Search documentation

Jump to a page or a component.

FileUpload

Dashed drop well and an upload list; accept, size and count enforced before you see a File.

peer: react-dropzone

Preview

  • Diamonds.xls18.20 MB · 60% · 24 sec left
  • Stone Parameter.csv5.30 MB · 42% · 60 sec left
  • Diamonds.xls10.50 MB · Uploaded
  • Diamonds.xlsUpload failed

Installation

No install — ask an AI agent to copy this component from registry.json, then pnpm add react-dropzone.

import { FileUpload, FileUploadDropzone, FileUploadItem, formatFileSize } from "@/components/ui/file-upload";

Notes

  • Transport-agnostic and fully controlled. It never uploads anything: onFilesAdded hands you the accepted Files, you start the request, and you mirror its state into files — each entry's status, progress and secondsLeft are what the list draws.
  • The well is react-dropzone's useDropzone. accept is its MIME-to-extensions map, checked on drop and pick alike and fed to the native picker; maxSize and maxFiles are its options too. Anything else — a validator, minSize, noPaste, getErrorMessage for localised errors — goes through dropzoneOptions.
  • maxFiles is per drop, not a running total: a batch larger than it is rejected whole with too-many-files. Cap the total in onFilesAdded if you need one.
  • Rejections are react-dropzone FileRejections (file + errors[].code), reported through onFilesRejected and never rendered. Show them the way the surrounding form shows its errors.
  • A drag whose every item is already known to be the wrong MIME type tints the well red (data-drag-reject). Extension and size failures are only knowable on drop, so a drag of a too-large file still highlights normally.
  • onRemove and onRetry are plain callbacks with the entry. Whether remove means abort, delete-from-server or drop-from-state is yours to decide; omit either and its button does not render.
  • The hint line is built from accept and maxSize in English by default. Pass your own to translate it.
  • A caller's data-testid lands on the column; ${base}-dropzone, ${base}-dropzone-input and ${base}-item-<id> derive from it, and each row's buttons add -remove-button / -retry-button.

Props

The props worth knowing. Everything else passes straight through to the underlying element, including className, which is merged last so it always wins.

PropTypeDefaultDescription
filesFileUploadEntry[][]Rows to draw: { id, name, size, status, progress?, secondsLeft?, error? }.
acceptAccept | AcceptGroup[]—react-dropzone map of MIME type to extensions: { "text/csv": [".csv"] }. Omit for anything.
maxSizenumber—Largest file allowed, in bytes.
maxFilesnumber—Most files one drop or pick may contain.
multiplebooleantrueLet the picker choose several at once.
onFilesAdded(files: File[]) => void—Files that passed every check. Start uploading them.
onFilesRejected(rejections: FileRejection[]) => void—Files that failed a check, each with react-dropzone's errors.
dropzoneOptionsDropzoneOptions—Anything else for useDropzone: validator, minSize, noPaste, getErrorMessage.
onRemove(entry: FileUploadEntry) => void—The row's trash button. Omit to hide it.
onRetry(entry: FileUploadEntry) => void—A failed row's retry button. Omit to hide it.
titlestring"Click or drag files to upload"Dropzone headline.
hintstringfrom accept + maxSizeDropzone second line.
removeLabel / retryLabel / uploadedLabel / failedLabelstring"Remove" / "Retry" / "Uploaded" / "Upload failed"Row copy. Pass translated strings from the call site.
formatTimeLeft(seconds: number) => string"24 sec left"Readout for an uploading row's remaining time.