File Upload
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
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
| Prop | Type | Default | Description |
|---|---|---|---|
onChange | (files: File[]) => void | — | Callback when files are added/removed |
label | string | — | Label text above the upload area |
variant | 'dropzone' | 'inline' | 'dropzone' | Upload style variant |
accept | string | '*' | Accepted file types (MIME or extensions) |
multiple | boolean | false | Allow multiple file selection |
maxSize | number | 10485760 | Maximum file size in bytes (10MB) |
maxFiles | number | 5 | Maximum number of files |
placeholder | string | — | Placeholder text (inline variant) |
disabled | boolean | false | Disable the upload |
className | string | — | Additional 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 readersKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Focus the upload button |
| Enter / Space | Open 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