File Upload

@allem-ui/file-upload

Drag-and-drop file upload with image previews, progress tracking, and validation.

Installation

npm install @allem-ui/file-upload

Add the @source directive to your CSS so Tailwind generates the component classes:

@source "@allem-ui/file-upload";

Drop Zone

Drag files onto the zone or click to browse. Supports type, size, and count validation.

Click to upload or drag and drop

image/*, .pdf

Custom Trigger

Use FileUploadTrigger to wrap any element as an upload button.

With Validation

Restrict to 2 files, max 1 MB each, only .png and .jpg. Files that exceed limits show an error state.

Click to upload or drag and drop

.png, .jpg

FileUpload Props

PropTypeDefaultDescription
onFilesSelected*(files: File[]) => voidCalled with selected files
acceptstringAccepted file types (e.g. "image/*,.pdf")
multiplebooleantrueAllow multiple files
maxFilesnumberMaximum number of files — shows count indicator when set
currentCountnumber0Current number of files — used with maxFiles for the count display
maxSizenumberMaximum file size in bytes — shows size hint in the drop zone
disabledbooleanfalseDisable the drop zone
classNamestringAdditional CSS classes
childrenReactNodeCustom drop zone content

FileUploadItem Props

Renders a single file row with thumbnail preview (for images), file icon with type-based coloring, progress bar, and status indicator. Used internally by FileUploadList — import it directly for custom list layouts.

PropTypeDefaultDescription
file*UploadFileThe file object to display
onRemove(id: string) => voidCallback when remove button is clicked
classNamestringAdditional CSS classes

FileUploadList Props

PropTypeDefaultDescription
files*UploadFile[]Array of files to display
onRemove(id: string) => voidCallback when a file is removed
classNamestringAdditional CSS classes

FileUploadTrigger Props

PropTypeDefaultDescription
onFilesSelected*(files: File[]) => voidCalled with selected files
acceptstringAccepted file types
multiplebooleantrueAllow multiple files
disabledbooleanfalseDisable the trigger
children*ReactNodeCustom trigger element

useFileUpload

Hook that manages file state, validation, and image previews.

Options

PropTypeDefaultDescription
maxFilesnumberMaximum number of files
maxSizenumberMaximum file size in bytes
acceptstring[]Accepted types (e.g. ["image/*", ".pdf"])

Return Value

PropTypeDefaultDescription
filesUploadFile[]Current array of managed files
addFiles(files: File[]) => RejectedFile[]Add files with validation — returns rejected files
removeFile(id: string) => voidRemove a file by ID
updateProgress(id: string, progress: number) => voidUpdate upload progress (0–100)
setStatus(id: string, status: Status, error?: string) => voidSet file status ("idle" | "uploading" | "success" | "error")
clearFiles() => voidRemove all files
rejectedFilesRejectedFile[]Files rejected from the last addFiles() call

Built-in Behavior

FeatureDescription
Keyboard accessibleEnter/Space triggers file selection on both FileUpload and FileUploadTrigger.
Image previewsObject URLs are automatically generated for image files and revoked on removal.
Type-based file iconsFileUploadItem shows color-coded icons — emerald for images, red for PDFs, purple for videos.
Smart validationSupports wildcard MIME matching (image/*), exact MIME, and extension matching (.pdf).

UploadFile Type

PropTypeDefaultDescription
idstringUnique file identifier
fileFileNative File object
namestringFile name
sizenumberFile size in bytes
typestringMIME type
previewstringPreview URL for images
progressnumberUpload progress (0–100)
status"idle" | "uploading" | "success" | "error"Current upload status
errorstringError message when status is error

RejectedFile Type

Returned by addFiles() for files that failed validation. Use this to show feedback (e.g. toast notifications).

PropTypeDefaultDescription
fileFileThe native File object that was rejected
reason"type" | "size" | "limit"Why the file was rejected — wrong type, too large, or file count exceeded