File upload
A drop target and file list for attaching documents such as receipts, referral letters and claim evidence.
Purpose
Two parts: FileUpload is the dashed drop target (click to browse, or drag and drop), and
FileUploadItem rows carry each attached file through its lifecycle — uploading, complete,
error. The pair is transport-agnostic: wire onFilesSelected to your upload client and drive
each row's status/progress from it. The progress bar inside a row is the
Progress component; for typed references rather than
attachments (a claim number, a URL) use an Input.
Example
Pick or drop a file — it lands in the list below the target:
import { FileUpload, FileUploadItem } from "@healthmetrics/ui/file-upload";
<FileUpload
hint="PDF or JPG, up to 10 MB each"
accept=".pdf,.jpg,.jpeg"
onFilesSelected={(files) => files.forEach(startUpload)}
/>
{uploads.map((u) => (
<FileUploadItem
key={u.id}
name={u.name}
size={u.size}
status={u.status} // "uploading" | "complete" | "error"
progress={u.progress} // 0–100 while uploading
errorMessage={u.error}
onRetry={() => retry(u.id)}
onRemove={() => remove(u.id)}
/>
))}multiple defaults on; every other native file-input attribute (accept, capture, name…)
passes through to the hidden input.
States
The drop target has default, drag-over, error and disabled states; drag-over turns the border
--primary with an --accent fill as the file crosses it.
Only PDF and JPG files are accepted.
Item rows carry the per-file lifecycle. uploading shows the progress bar with a percentage,
complete a success check, and error the message with a Retry action when onRetry is
passed; the Remove button appears whenever onRemove is passed:
referral-letter.jpg
3.8 MBreceipt-klinik-mediviron.pdf
1.2 MBmc-scan.pdf
12.4 MBFile exceeds the 10 MB limit.
Structure
| Property | Value |
|---|---|
| Drop target | 2px dashed --input, --radius-xl, 24px/32px padding |
| Drag-over | border --primary, --accent fill |
| Target error | border --destructive; 12px --destructive-text message below |
| Icon tile | 40px square, --accent fill, 22px upload_file glyph |
| Focus | 2px --ring with 2px offset (focus-within, the input is the tab stop) |
| Disabled | 50% opacity, not-allowed cursor |
| Item row | 1px border, --card fill, --radius-lg, 12px padding |
| Row icon tile | 36px square; draft glyph, or error on --destructive-subtle |
| Progress | 6px bar (h-1.5) + tabular percentage |
| Success mark | 20px check_circle glyph, --success-text |
Best practices
Do
- State the accepted formats and size limit in
hint— and enforce them withacceptplus your own size check inonFilesSelected. - Keep every selected file visible as a
FileUploadItemrow — silence after a drop reads as a failed upload. - Pass
onRetryon error rows — re-dragging the same file is the frustrating alternative. - Put row-level failures on the row (
errorMessage) and target-level failures on the target (error) — a rejected file type is the target's problem; a failed transfer is the row's.
Don't
- Rely on drag and drop alone — the click-to-browse path is the one that works everywhere, including for keyboard and screen-reader users.
- Fake
progresswith an animation — show real transfer progress or none. - Remove a failed row automatically — the user needs to see what failed and why.
Accessibility & keyboard
- The drop target is a
<label>wrapping the real (visually hidden) file input — clicking anywhere opens the picker, and the label text ("Click to upload or drag and drop" plus the hint) is the input's accessible name. No nested-interactive tricks. - The hidden input is the tab stop; focus draws the 2px ring on the whole target via
focus-within. - Drag and drop is an enhancement only — browse is the equivalent path, so no keyboard drop handling is needed.
- The target's
errorsetsaria-invalidon the input and is linked viaaria-describedby(id{id}-error); the message is a polite live region, so it is announced when it appears. - On rows, the progress bar is labelled "Uploading name" and the remove button "Remove name"; Retry is a plain labelled button.
- Keyboard: Tab to the target; Enter or Space opens the file picker; on rows, Tab reaches Retry and Remove.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
onFilesSelected | ((files: File[]) => void) | undefined | — | Called with the chosen files (from browse or drop). |
error | string | undefined | — | Error message rendered under the drop target (Figma "Error" state). |
hint | string | undefined | — | Helper line, e.g. accepted formats and size limit. |
className | string | undefined | — | — |
FileUploadItem renders one attached file:
| Prop | Type | Default | Description |
|---|---|---|---|
namerequired | string | — | File name shown on the row. |
size | string | undefined | — | Human-readable size, e.g. "2.4 MB". |
status | "uploading" | "complete" | "error" | undefined | "complete" | Row status (Figma variants): `uploading` shows the progress bar, `complete` a success check, `error` the message + retry. |
progress | number | undefined | — | Upload progress 0–100 (uploading only). |
errorMessage | string | undefined | — | Error message (error only). |
onRetry | (() => void) | undefined | — | — |
onRemove | (() => void) | undefined | — | — |