🚀ReacUI is currently in Beta. We're actively improving it! ❣️

File Input

A component for file uploads with enhanced styling and functionality

Installation

The FileInput component is part of the ReacUI library. Install the package to use it in your project.

npm install reacui

Import

Import the FileInput component into your React component.

import { FileInput } from 'reacui';

Basic Usage

The FileInput component provides a styled file input control.

<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  Upload file
</label>
<FileInput onChange={(files) => handleFiles(files)} />

Variants

Different styles and variants of the file input component.

No file selected

or drag and drop

PNG, JPG, GIF up to 10MB

{/* Standard (Default) */}
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  Standard (Default)
</label>
<FileInput variant="standard" onChange={(files) => handleFiles(files)} />

{/* Button Only */}
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  Button Only
</label>
<FileInput 
  variant="button" 
  buttonText="Choose file" 
  onChange={(files) => handleFiles(files)} 
/>

{/* Outline */}
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
  Outline
</label>
<FileInput 
  variant="outline" 
  accept="image/png,image/jpeg,image/gif"
  maxSize={10 * 1024 * 1024} // 10MB
  helperText="PNG, JPG, GIF up to 10MB"
  onChange={(files) => handleFiles(files)} 
/>

With Dropzone

Enable drag and drop functionality for file uploads.

or drag and drop

Up to 5 files, max 2MB each

<FileInput 
  variant="dropzone"
  multiple
  maxFiles={5}
  maxSize={2 * 1024 * 1024} // 2MB per file
  accept="image/*,application/pdf"
  helperText="Up to 5 files, max 2MB each"
  onChange={(files) => handleFiles(files)} 
  onDrop={(files) => handleDrop(files)}
/>

Validation

File input with validation states and error messages.

File meets all requirements

File too large (max 2MB)

<FileInput 
  state="valid"
  helperText="File meets all requirements"
  onChange={(files) => handleFiles(files)} 
/>

<FileInput 
  state="error"
  error="File too large (max 2MB)"
  onChange={(files) => handleFiles(files)} 
/>

API Reference

The following props are available for the FileInput component.

PropTypeDefaultDescription
variantenum'standard'The visual style: 'standard', 'button', 'outline', or 'dropzone'
multiplebooleanfalseWhether multiple files can be selected
acceptstring''File types that can be accepted (e.g., 'image/*,application/pdf')
maxSizenumberInfinityMaximum file size in bytes
maxFilesnumberInfinityMaximum number of files when multiple is true
buttonTextstring'Choose file'Text for the button in button variant
helperTextstring''Helper text shown below the input
stateenum'default'The validation state: 'default', 'valid', or 'error'
errorstring''Error message when state is 'error'
disabledbooleanfalseWhether the file input is disabled
onChangefunction-Callback function triggered when files are selected
onDropfunction-Callback function triggered when files are dropped (for dropzone variant)