Skip to main content

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​

Storybook

With Files​

Storybook

Dragging​

Storybook

Photo​

Storybook

Photo Done​

Storybook

With Error​

Storybook

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​

VariantWhat it is
defaultDashed line-soft border on canvas-soft.
draggingPrimary border and tint.
photoCamera icon, opens the camera on phones.
doneGreen solid border: "Photo captured".
file listUploading with progress, Uploaded, Failed with reason.
errorMessage 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​

PropTypeDefaultDescription
labelstringnoneField label above the zone
acceptstringnoneFile types the picker accepts (".pdf,.jpg,.png")
multiplebooleanfalseAllows picking several files
variant'default' | 'photo''default''default' drop zone | 'photo' camera capture for insurance cards and ID
filesFileUploadItem[]undefined (uncontrolled)Controlled file list: Array<{name, size?, status: uploading|done|error, progress?, error?}>
defaultFilesFileUploadItem[][]Initial file list (uncontrolled)
onFilesChange(files: FileUploadItem[]) => void—Called with the next list when files are added or removed
draggingbooleanfalseForced drag-over state for previews
donebooleanfalseForced done state (photo captured) for previews
titlestring'Drag a file here or choose one'Zone title
hintstring'PDF, JPG or PNG, up to 10 MB'Hint under the title
doneTextstring'Photo captured'Title in the done state
errorstringnoneError message under the zone, role alert
onFiles(files: FileList) => voidnoneCalled with the picked or dropped files
onRemove(file: FileUploadItem, index: number) => voidnoneCalled when a file row's Remove button is pressed
styleCSSProperties—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>
KindNameDescription
attributelabelField label above the zone; default none
attributeacceptFile types the picker accepts (".pdf,.jpg,.png"); default none
attributemultipleAllows picking several files; default false
attributevariant'default' drop zone | 'photo' camera capture for insurance cards and ID; default 'default'
property / JSON attributefilesControlled file list: Array<{name, size?, status: uploading|done|error, progress?, error?}>; default undefined (uncontrolled)
property / JSON attributedefault-files / defaultFilesInitial file list (uncontrolled); default []
attributedraggingForced drag-over state for previews; default false
attributedoneForced done state (photo captured) for previews; default false
attributetitleZone title; default 'Drag a file here or choose one'
attributehintHint under the title; default 'PDF, JPG or PNG, up to 10 MB'
attributedone-text / doneTextTitle in the done state; default 'Photo captured'
attributeerrorError message under the zone, role alert; default none
property / JSON attributestyleInline style of the root
attributedefault-checked / defaultChecked
attributeauto-focus / autoFocus
attributeread-only / readOnly
attributedisabled
attributename
property / JSON attributemax
property / JSON attributestep
attributeplaceholder
property / JSON attributeauto-complete / autoComplete
attributechecked
attributemax-length / maxLength
property / JSON attributemin
attributerequired
eventco-files-changeCalled with the next list when files are added or removed (React: onFilesChange)
eventco-filesCalled with the picked or dropped files; default none (React: onFiles)
eventco-removeCalled when a file row's Remove button is pressed; default none (React: onRemove)
eventco-input (React: onInput)