Skip to main content
Version: 1.0.3

File Upload

Overview

The FileUpload component provides a modern, accessible interface for uploading files with support for drag-and-drop, file validation, previews, and progress tracking.

Installation

ignix add component file-upload

Usage

// Import the component:
import { FileUpload } from '@mindfiredigital/ignix-ui';

Basic File Upload

0 selected

Drag and Drop File Upload

Drag & drop files here, or click to browse

Supports: image/*, .pdf, .doc, .docx, .txt, .xls, .xlsx • Max size: 10 MB • Max files: 5

0 selected

Custom Validation

        function CustomValidationUpload() { 
const validateFile = (file: File) => {
// Custom validation rules const errors: string[] = []; // Check file name length
if (file.name.length > 50) {
errors.push('File name must be less than 50 characters');
}

// Check for special characters
if (/[<>:"/\\|?*]/.test(file.name)) {
errors.push('File name contains invalid characters');
}

// Custom size limit based on file type
if (file.type.startsWith('image/') && file.size > 2 * 1024 * 1024) {
errors.push('Images must be smaller than 2MB');
}

return {
isValid: errors.length === 0,
error: errors.join(', ')
};
};

return (
<FileUpload
mode="both"
multiple={true}
buttonText="Upload with Custom Rules"
dropzoneText="Files will be validated against custom rules"
validateFile={validateFile}
accept={""}
/>
);
}

Props

PropTypeDefaultDescription
mode'button' | 'dropzone' | 'both''both'Display mode for the upload interface
multiplebooleanfalseAllow multiple file selection
maxFilesnumber10Maximum number of files allowed
maxSizenumber10 * 1024 * 1024Maximum file size in bytes (10MB default)
acceptstring'/'Accepted file types (MIME types or extensions)
buttonTextstring'Upload Files'Custom upload button text
dropzoneTextstring'Drag & drop files here or click to browse'Custom dropzone text
showFileListbooleantrueShow file list after selection
disabledbooleanfalseDisable the component
buttonVariant'default' | 'primary' | 'secondary' | 'outline' | 'ghost''primary'Variant for the upload button
simulateUploadbooleanfalseShow simulated upload progress
validateFile(file: File) => { isValid: boolean; error?: string }-Custom validation function
onFilesChange(files: File[]) => void-Callback when files are selected
imageAvatarSize'xs' | 'sm' | 'md' | 'lg''md'Avatar size for image file previews
imageAvatarShape'circle' | 'square' | 'rounded' | 'hexagon' | 'diamond''circle'Avatar shape for image file previews
classNamestring-Additional CSS classes