File Upload
A drop zone that is also a button, with a file list that tracks progress.
Loading documentation…
FileUpload is a drop zone and a button, always both: drag and drop is
undiscoverable on its own and impossible on a phone. The whole zone is a
<label> for a hidden file input — one element, keyboard-focusable, and the
click path needs no JavaScript at all.
onFiles receives everything accepted, from both the drop and the picker,
after accept and maxSize have had their say.
Hand it files and it renders the list: name, size, a progress bar while the
upload runs, an error when it fails, and a remove control wired to onRemove.
Leave files out and render the list yourself.
A file with no progress draws no bar: undefined means "not tracking
progress", which is different from zero.
label is the headline inside the zone and description is the line beneath
it. Put the formats and the size limit in the description — a rejection after
the fact is a worse experience than a sentence before it.
The same helper the file list uses, exported so your own rows read identically.
Fires with everything accepted, for both the drop and the picker.
The accept attribute of the hidden input, for example "image/*,.pdf".
Allows more than one file per selection.
Rejects anything larger, in bytes, before onFiles sees it.
The glyph inside the zone.
The headline inside the zone.
The second line — formats, size limits.
The list to render under the zone.
Fires when a row's remove control is used.
Dims the zone and ignores drops.
Stable id, handed back to onRemove.
The file name shown in the row.
Size in bytes, formatted with formatBytes.
0–100. undefined means "not tracking progress" and draws no bar.
Drives the row's icon and tone.
The message shown under the row when the upload failed.