Loading component…
Loading component…
Drag files in and watch them upload – fanning documents, colored type badges, progress with time left, errors with retry
To reuse this local React demo, copy all files from the Code tab into the same folder, then import Dropzone from ./dropzone.
import { Dropzone } from "@/components/ui/dropzone";
export function Attachments() {
return (
<Dropzone
accept={[".pdf", ".png", ".jpg", ".xlsx"]}
maxSize={25 * 1024 * 1024}
onUpload={(file, onProgress) =>
new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.upload.onprogress = (e) => onProgress(e.loaded / e.total);
xhr.onload = () => (xhr.status < 300 ? resolve() : reject(new Error("Upload failed")));
xhr.onerror = () => reject(new Error("Upload failed – connection lost"));
xhr.open("POST", "/api/upload");
xhr.send(file);
})
}
onChange={(items) => setAttachments(items.filter((i) => i.status === "done"))}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| accept | string[] | Allowed extensions, e.g. [".pdf", ".png"]; any file when left out. Other files get a row with an error | |
| maxSize | number | 25 MB | Largest file in bytes; bigger files get a "Too large" row |
| onUpload | (file: File, onProgress: (p: number) => void) => Promise<void> | Uploads one file and reports progress from 0 to 1; reject to mark it as failed (the message is shown, Retry calls it again). Simulated when left out | |
| onChange | (items: UploadItem[]) => void | Every change of the list: { id, name, size, status, progress, error?, file? } | |
| hint | string | Text under the title; defaults to the accepted types and the size limit | |
| autoplay | boolean | false | Plays a sample drop of four files – for previews and landing pages |
| className | string | Extra class on the root |
Fills its container up to 520px; long file names are cut with an ellipsis
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"