FileUpload
A drag-and-drop file upload component with progress tracking, image previews, and validation.
Basic Usage
Image Upload
Drag and drop or click to upload images with progress tracking and preview.
import { FileUpload } from 'fluxo-ui';
<FileUpload
accept="image/*"
multiple
maxFileSize={5 * 1024 * 1024}
maxFiles={5}
showPreview
onFilesSelect={(files) => console.log('Selected:', files)}
onUpload={async (file, onProgress) => {
for (let i = 0; i <= 100; i += 10) {
await new Promise((r) => setTimeout(r, 200));
onProgress(i);
}
}}
/>Image Preview
Enable showPreview to display thumbnail previews for uploaded image files.
Image Preview
Uploaded images show thumbnail previews with progress bars during upload.
import { FileUpload } from 'fluxo-ui';
<FileUpload
accept="image/*"
multiple
maxFiles={4}
showPreview
onUpload={async (file, onProgress) => {
// simulate upload
for (let i = 0; i <= 100; i += 20) {
await new Promise((r) => setTimeout(r, 300));
onProgress(i);
}
}}
/>Validation
Use accept, maxFileSize, and customValidator to enforce file constraints.
File Validation
Restrict file types, enforce size limits, and add custom validation rules. Invalid files display inline error messages.
import { FileUpload } from 'fluxo-ui';
<FileUpload
accept=".pdf,.doc,.docx"
multiple
maxFileSize={2 * 1024 * 1024}
maxFiles={3}
customValidator={(file) => {
if (file.name.includes(' ')) {
return 'File name must not contain spaces';
}
return undefined;
}}
onFilesSelect={(files) => console.log('Valid files:', files)}
/>Import
import { FileUpload } from 'fluxo-ui';Props
acceptstringAccepted file types (e.g. "image/*", ".pdf,.doc").
acceptstringAccepted file types (e.g. "image/*", ".pdf,.doc").
multipleboolean"false"Allow multiple file selection.
multipleboolean"false"Allow multiple file selection.
maxFileSizenumberMaximum file size in bytes.
maxFileSizenumberMaximum file size in bytes.
maxFilesnumberMaximum number of files allowed.
maxFilesnumberMaximum number of files allowed.
disabledboolean"false"Disable the upload zone.
disabledboolean"false"Disable the upload zone.
showPreviewboolean"true"Show image previews for uploaded files.
showPreviewboolean"true"Show image previews for uploaded files.
dropzoneContentReactNodeCustom content for the dropzone area.
dropzoneContentReactNodeCustom content for the dropzone area.
onFilesSelect(files: File[]) => voidCalled when files are selected.
onFilesSelect(files: File[]) => voidCalled when files are selected.
onFileRemove(file: UploadFile) => voidCalled when a file is removed from the list.
onFileRemove(file: UploadFile) => voidCalled when a file is removed from the list.
onUpload(file: File, onProgress: (percent: number) => void) => Promise<void>Upload handler with progress callback.
onUpload(file: File, onProgress: (percent: number) => void) => Promise<void>Upload handler with progress callback.
customValidator(file: File) => string | undefinedCustom validation function returning an error message.
customValidator(file: File) => string | undefinedCustom validation function returning an error message.
classNamestringAdditional CSS class for the container.
classNamestringAdditional CSS class for the container.
Features
Drag & Drop
Drop files directly onto the upload zone with visual hover feedback.
Progress Tracking
Real-time upload progress bars for each file being uploaded.
Image Previews
Automatic thumbnail generation for uploaded image files.
File Validation
Built-in type and size validation plus custom validator support.
Multiple Files
Upload multiple files at once with configurable file count limits.
Accessibility
Keyboard accessible with ARIA labels and role attributes.