File Uploader

Click, drag, or paste target for files with consumer-owned validation. Defaults to images. Use the tile variant for compact square or circle add and replace controls such as profile photos.

Also known as: file uploader, file upload, image upload, image dropzone, image paste target, photo dropzone, dropzone, profile picture upload, avatar upload, add photo

Installation

Install with the CLI, or copy the component source into your project.

Add file-uploader (npm)

npx --yes -p github:itsvigneshv/default-file-ui#main df-ui add file-uploader

Default

Click, drag, or paste an image into the uploader.

Drop an image hereor click to browse. Paste also works.PNG, JPG, WEBP, or GIF up to 5 MB

Custom chrome

Solid border, token-backed colors, custom icon, and copy.

Upload a fileDrag in, click to browse, or paste.Any image up to 5 MB

Tile

Compact add control and a circular replace control with preview.

Add
Add

Tile sizes

Circular tiles in sm, md, lg, and xl.

Add
Add
Add
Add

Properties

Click, drag, or paste upload target. Defaults to images; pass pickFile for other media. Validation and copy stay with the consumer. Use variant tile for compact add or replace controls such as profile photos. Idle chrome is tokenized via --df-file-uploader-*.

FileUploader

PropTypeDefaultNotes
onFile(file: File) => void-Called when a file passes validation (required).
validateFile(file: File) => string | null-Return an error message to reject the file, or null to accept.
onReject(message: string) => void-Called with the rejection message from validateFile.
acceptstringimage/png,image/jpeg,image/webp,image/gifFile input accept attribute.
pickFile(files: FileList | null | undefined) => File | undefined-Choose a candidate from a drop or browse list. Defaults to the first image file.
enablePastebooleantrueListen for image paste on the window while mounted.
disabledbooleanfalseDisable interaction and paste handling.
variant"default" | "tile""default"default is a full-width drop target. tile is a fixed square or circle control for add and replace flows such as profile photos.
shape"rounded" | "circle""rounded"Tile corner shape. rounded uses radius-lg. circle uses a full pill radius. Ignored on default.
size"sm" | "md" | "lg" | "xl""md"Tile edge length. Maps to --df-file-uploader-tile-size-*. Ignored on default. Override with --df-file-uploader-tile-size for a custom length.
cornerShape"round" | "smooth"-Instance corner curve. Omit to inherit --df-corner-shape from the theme (set at create/init).
titleReactNode"Drop an image here" (default) or "Add" (tile)Primary heading inside the uploader.
descriptionReactNode"or click to browse. Paste also works." (default) or hidden (tile)Secondary line under the title. Pass null or an empty value to hide it.
hintReactNode-Optional tertiary hint (formats, size limits).
iconReactNode-Leading icon. Defaults to ImagePlus. Pass a custom node to replace it.
previewSrcstring-Image URL for a filled replace state. Covers the shell and hides the idle icon and copy. Host manages object URL lifecycle.
borderStyle"dashed" | "solid""dashed"Idle border style. Sets --df-file-uploader-border-style.
borderColorstring-Idle border color. Prefer tokens such as var(--border). Sets --df-file-uploader-border-color.
backgroundstring-Idle fill. Prefer tokens such as var(--muted) or transparent. Sets --df-file-uploader-bg.
classNamestring-Additional styles on the uploader shell.

Focus

PropTypeDefaultNotes
Browse dialogbehavior-After the native file dialog closes (file chosen or cancelled), focus leaves the file input when it is still the active element. Host shortcuts such as Space are not kept on the uploader.

Tokens

Theme defaults live on :root. Override these globally or on a local host.

TokenTypeDefaultNotes
--df-file-uploader-min-heightCSS lengthcalc(30 * var(--spacing-unit))Minimum height for the default variant.
--df-file-uploader-border-styleCSS border-styledashedIdle border style.
--df-file-uploader-border-colorCSS colorvar(--border)Idle border color.
--df-file-uploader-bgCSS colorcolor-mix(in oklch, var(--muted) 40%, transparent)Idle fill.
--df-file-uploader-border-color-hoverCSS colorcolor-mix(in oklch, var(--primary) 40%, transparent)Border color on hover.
--df-file-uploader-bg-hoverCSS colorcolor-mix(in oklch, var(--muted) 60%, transparent)Fill on hover.
--df-file-uploader-border-color-activeCSS colorvar(--primary)Border color while dragging a file over the uploader.
--df-file-uploader-bg-activeCSS colorcolor-mix(in oklch, var(--primary) 5%, transparent)Fill while dragging a file over the uploader.
--df-file-uploader-tile-sizeCSS lengthvar(--df-file-uploader-tile-size-md)Resolved tile edge length. Override for a custom tile size.
--df-file-uploader-tile-size-smCSS lengthcalc(16 * var(--spacing-unit))Tile size sm.
--df-file-uploader-tile-size-mdCSS lengthcalc(22 * var(--spacing-unit))Tile size md.
--df-file-uploader-tile-size-lgCSS lengthcalc(28 * var(--spacing-unit))Tile size lg.
--df-file-uploader-tile-size-xlCSS lengthcalc(36 * var(--spacing-unit))Tile size xl.
--df-file-uploader-tile-radiusCSS lengthvar(--radius-lg)Tile corner radius. Circle shape sets this to radius-full.
--radius-lgCSS length-Default and rounded-tile corner radius.
--radius-fullCSS length-Circle tile corner radius.
--df-corner-shapeCSS corner-shapevar(--df-corner-shape-round)Theme corner curve for all kit chrome. round = circular arcs; smooth = continuous squircle. Set with df-ui init --corner-shape, or override on :root. Default round.