Dropzone

Drop, paste or choose files, checked against types, size and count, with the reason for each file turned away.

Team offsite dinner

Harbor Café · November 21

$412.80

Drop files here or chooseChoose files

JPG, PNG, HEIC or PDF, up to 10 MB, 10 files at most

1 of 1 uploaded

1 uploaded · 1.8 MB

  • Harbor Café receipt.jpgUploaded

    1.8 MB

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/dropzone

Usage

import { Dropzone } from "./ui/uicontext/components/upload/Dropzone.ts"
const Message = UiSchema.TaggedEnum({ PickedReceipts: { files: Schema.Array(Schema.instanceOf(File)) } })// The zone checks the rules and hands over the files that pass; your app uploads themexport const ReceiptDrop = (h: Html.H<typeof Message.Type>) =>	Dropzone(h, {		props: {			label: "Upload receipts",			accept: { types: ["image/*", ".pdf"], typeLabel: "photos or PDFs", typeNoun: "a receipt we can read", maxSize: 10 * 1024 * 1024 },		},		onEmit: {			Picked: ({ files }) => Message.PickedReceipts({ files }),			Refused: () => undefined,		},	})

Examples

Import a CSV with a size limit

One CSV up to 5 MB. The file is read in the browser and previewed before anything is imported; a bigger file or a spreadsheet is turned away with the reason.

Drop a CSV here or choose one

CSV, up to 5 MB

API reference

Props

Dropzone props
NameTypeDescription
labelrequiredstringWhat the files are for, as a name for the zone: "Upload receipts"
promptstringThe line in the zone; "Drop files here or choose them" by default
acceptUploadAcceptThe rules files must pass
multiplebooleanTake several files at once; true unless accept.maxFiles is 1
countnumberHow many files are already added, for accept.maxFiles
pagebooleanTake drops and pastes anywhere on the page, and cover it while files are dragged over
disabledReasonstring | nullWhy files can't be added now ("Uploads are off for guests"); takes nothing while set
size"md" | "sm"sm is a one-line strip for tight spaces: a ticket's reply box, a table's empty state
localestring—

Events

Dropzone events
EventPayloadDescription
Picked{ files: instanceOf[] }Files that passed the rules, in the order given: upload them, or keep them for a form
Refused{ refused: UploadRefusal[] }Files the rules turned away; the zone shows these itself

Source