FileDropzone

Data input

Picks files: <FileDropzone> with bind:files (a File[]) takes files dropped on it or chosen by browsing (a click, or Enter or Space on its focused input). It turns away files that don't match accept, are larger than maxSize or exceed maxFiles, and says why; onReject hears it too. Chosen files are listed with a remove button, and with a bar for those in progress (a Map of file to 0โ€“1). The app does the upload; with name, a form posts the chosen files. Inside a Field it takes its id, label, description, error and invalid and disabled state from the Field.

import { FileDropzone } from '@limerdev/zest';
FileDropzone for AI tools (llms.txt)
Use for
Attaching receipts, invoices or images to a record; importing a CSV.
Don't
A single small file in a dense form: use Input with type="file". Uploading inside the component: upload from bind:files in the app, and show it with progress.

Examples

Basic

In a Field: images or PDFs up to 10 MB. Drop files on it, or click or press Enter to browse.

Upload

The app uploads: here a timer stands in for the request, and a SvelteMap of progress draws a bar per file.

States

One CSV at a time (a new one replaces it), with its own label text; and disabled in its Field.

Props

Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that renders your own element, with props to spread on it).

FileDropzone

Prop Type Default Description
accept string undefined The file types it takes, as for an input: image/*, .pdf, application/pdf.
files bindable File[] [] The chosen files, in the order they were added. Bindable.
label string the Config's `strings.dropFiles`, else 'Drop files here, or click to browse' The text in the drop area.
locale string the Config's `defaultLocale`, else the browser's The locale for file sizes (1,5 MB in sv-SE).
maxFiles number undefined How many files it holds at most; more are turned away.
maxSize number undefined The largest file it takes, in bytes.
multiple boolean false Takes several files. Without it a new file replaces the chosen one.
onReject ((rejections: FileRejection[]) => void) undefined Called with the files turned away when files are added.
progress Map<File, number> undefined Each file's upload progress, from 0 to 1, for files the app is uploading. A file without an entry shows no bar.
rejectionMessage ((rejection: FileRejection, maxSize: string) => string) the Config's `strings.fileRejected`, else English messages: "report.exe isn't a type this takes." The message for a turned-away file, given the rejection and the largest size, formatted.
removeLabel ((name: string) => string) the Config's `strings.removeFile`, else (name) => `Remove ${name} The remove button's accessible name, given the file's name.