File Upload

Forms
Media

Drag-and-drop file upload with preview, validation, and multiple file support. Features image thumbnails, file size limits, and error handling.

Preview

Single file upload with drag and drop

Drop files here or click to upload

Max 10.0 MB per file • Up to 1 files

Variants

Dropzone and inline upload styles

Dropzone (Default)

Drop files here or click to upload

Max 10.0 MB per file • Up to 5 files

Inline

Choose a file...

Multiple Files

Upload multiple files at once

Drop files here or click to upload

Max 5.0 MB per file • Up to 5 files

Custom Limits

Custom file size and count limits

Drop files here or click to upload

Max 2.0 MB per file • Up to 3 files

Disabled State

File upload in disabled state

Drop files here or click to upload

Max 10.0 MB per file • Up to 5 files

Props

FileUpload component API reference

PropTypeDefaultDescription
onChange(files: File[]) => voidCallback when files are added/removed
labelstringLabel text above the upload area
variant'dropzone' | 'inline''dropzone'Upload style variant
acceptstring'*'Accepted file types (MIME or extensions)
multiplebooleanfalseAllow multiple file selection
maxSizenumber10485760Maximum file size in bytes (10MB)
maxFilesnumber5Maximum number of files
placeholderstringPlaceholder text (inline variant)
disabledbooleanfalseDisable the upload
classNamestringAdditional CSS classes

Usage

Import and implementation example

import { FileUpload } from '@/blocks/forms/file-upload'

export default function Example() {
  const handleFilesChange = (files: File[]) => {
    console.log('Files:', files)
    // Upload files to server
  }

  return (
    <>
      {/* Basic single file */}
      <FileUpload
        label="Upload Document"
        accept="image/*,.pdf"
        onChange={handleFilesChange}
      />

      {/* Inline variant */}
      <FileUpload
        variant="inline"
        label="Select File"
        placeholder="Choose a file..."
        onChange={handleFilesChange}
      />

      {/* Multiple with limits */}
      <FileUpload
        label="Upload Images"
        accept="image/*"
        multiple
        maxFiles={5}
        maxSize={5 * 1024 * 1024}
        onChange={handleFilesChange}
      />
    </>
  )
}

Features

Built-in functionality

  • Drag and drop: Drop files directly on the upload area
  • File type filtering: Accept specific file types via MIME or extensions
  • File size validation: Reject files exceeding size limit
  • Image preview thumbnails: Visual preview for uploaded images
  • Individual file removal: Remove files one at a time
  • Error messages: Clear feedback for validation failures
  • Inline variant: Compact input field style
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

File input is properly labeledDrag zone indicates drop target stateFile list announces updates to screen readers

Keyboard Navigation

KeyAction
TabFocus the upload button
Enter / SpaceOpen file picker dialog

Notes

  • Visual feedback when dragging files over drop zone
  • Error states communicated with color and text
  • File sizes displayed in human-readable format
  • Remove buttons clearly labeled for each file

Related Components