FileUpload
BasicInputs
<co-file-upload>FileUpload is a drop zone with a file list, plus a photo variant for insurance cards and ID.
import { FileUpload } from 'health-components';
Examples
Showcase
With Files
Dragging
Photo
Photo Done
With Error
Usage
<FileUpload label="Referral Letter" accept=".pdf,.jpg,.png" files={uploads} onFiles={upload} />
<FileUpload variant="photo" label="Front of Card" />
When to use
- Attach referral letters, insurance card photos, scanned documents, outside records.
When not to use
- Signing a document: SignaturePad.
Variants and states
| Variant | What it is |
|---|---|
| default | Dashed line-soft border on canvas-soft. |
| dragging | Primary border and tint. |
| photo | Camera icon, opens the camera on phones. |
| done | Green solid border: "Photo captured". |
| file list | Uploading with progress, Uploaded, Failed with reason. |
| error | Message under the zone. |
Accessibility
- The whole zone is a label for a visually hidden file input, so keyboard and screen readers get the native picker.
- Each file row has a Remove button named with the file name.
Do and don't
- Do: "Front of insurance card" and "Back of insurance card" as two photo tiles.
- Don't: Accept any file type for an insurance card.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | none | Field label above the zone |
accept | string | none | File types the picker accepts (".pdf,.jpg,.png") |
multiple | boolean | false | Allows picking several files |
variant | 'default' | 'photo' | 'default' | 'default' drop zone | 'photo' camera capture for insurance cards and ID |
files | FileUploadItem[] | undefined (uncontrolled) | Controlled file list: Array<{name, size?, status: uploading|done|error, progress?, error?}> |
defaultFiles | FileUploadItem[] | [] | Initial file list (uncontrolled) |
onFilesChange | (files: FileUploadItem[]) => void | — | Called with the next list when files are added or removed |
dragging | boolean | false | Forced drag-over state for previews |
done | boolean | false | Forced done state (photo captured) for previews |
title | string | 'Drag a file here or choose one' | Zone title |
hint | string | 'PDF, JPG or PNG, up to 10 MB' | Hint under the title |
doneText | string | 'Photo captured' | Title in the done state |
error | string | none | Error message under the zone, role alert |
onFiles | (files: FileList) => void | none | Called with the picked or dropped files |
onRemove | (file: FileUploadItem, index: number) => void | none | Called when a file row's Remove button is pressed |
style | CSSProperties | — | Inline style of the root |
Also accepts native attributes, including defaultChecked, autoFocus, onInput, readOnly, disabled, name, max, step, placeholder, autoComplete, checked, maxLength, min, required, plus className and event handlers on the root element.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-file-upload>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-file-upload label="…" accept="…" [files]="files" (co-files-change)="onFilesChange($event.detail)"></co-file-upload>
| Kind | Name | Description |
|---|---|---|
| attribute | label | Field label above the zone; default none |
| attribute | accept | File types the picker accepts (".pdf,.jpg,.png"); default none |
| attribute | multiple | Allows picking several files; default false |
| attribute | variant | 'default' drop zone | 'photo' camera capture for insurance cards and ID; default 'default' |
| property / JSON attribute | files | Controlled file list: Array<{name, size?, status: uploading|done|error, progress?, error?}>; default undefined (uncontrolled) |
| property / JSON attribute | default-files / defaultFiles | Initial file list (uncontrolled); default [] |
| attribute | dragging | Forced drag-over state for previews; default false |
| attribute | done | Forced done state (photo captured) for previews; default false |
| attribute | title | Zone title; default 'Drag a file here or choose one' |
| attribute | hint | Hint under the title; default 'PDF, JPG or PNG, up to 10 MB' |
| attribute | done-text / doneText | Title in the done state; default 'Photo captured' |
| attribute | error | Error message under the zone, role alert; default none |
| property / JSON attribute | style | Inline style of the root |
| attribute | default-checked / defaultChecked | |
| attribute | auto-focus / autoFocus | |
| attribute | read-only / readOnly | |
| attribute | disabled | |
| attribute | name | |
| property / JSON attribute | max | |
| property / JSON attribute | step | |
| attribute | placeholder | |
| property / JSON attribute | auto-complete / autoComplete | |
| attribute | checked | |
| attribute | max-length / maxLength | |
| property / JSON attribute | min | |
| attribute | required | |
| event | co-files-change | Called with the next list when files are added or removed (React: onFilesChange) |
| event | co-files | Called with the picked or dropped files; default none (React: onFiles) |
| event | co-remove | Called when a file row's Remove button is pressed; default none (React: onRemove) |
| event | co-input | (React: onInput) |