FileInput
The FileInput component allows users to upload files, supporting both a traditional input style and a dropzone style.
When To Use
- When you need to upload one or more files.
- When you need to upload files by dragging and dropping.
Drag and Drop
You can drag files to a specific area, to upload. Alternatively, you can also upload by selecting.
astro
---
import FileInput from '@/components/data-entry/FileInput.astro';
---
<FileInput variant="dropzone" label="Upload Avatar" /> Upload by clicking
Classic mode. File selection dialog pops up when upload button is clicked.
astro
---
import FileInput from '@/components/data-entry/FileInput.astro';
---
<FileInput variant="input" label="Resume" description="PDF or DOCX up to 5MB" /> Customize preview file
Customize local preview by using slots.
astro
---
import FileInput from '@/components/data-entry/FileInput.astro';
---
<FileInput variant="dropzone">
<span class="text-blue-500 underline">Click here</span> to select a file
<span slot="description" class="text-xs text-zinc-400">Supported formats: .jpg, .png</span>
</FileInput> Validation & Parameters
You can gain full control over filelist by configuring parameters like max files and max size.
astro
---
import FileInput from '@/components/data-entry/FileInput.astro';
---
<FileInput
variant="dropzone"
label="Upload Documents"
description="Max 2 files, up to 1MB each."
multiple
maxFiles={2}
maxSize={1}
/> Upload png file only
Limit file types that can be accepted.
astro
---
import FileInput from '@/components/data-entry/FileInput.astro';
---
<FileInput
variant="input"
label="Upload Image"
acceptType="images"
placeholder="Select image..."
/> API
| Property | Description | Type | Default |
|---|---|---|---|
| variant | Visual variant of the input | 'input' | 'dropzone' | 'input' |
| label | Label for the file input | string | '' |
| description | Description or help text | string | '' |
| multiple | Allow multiple file selection | boolean | false |
| maxFiles | Maximum number of files allowed | number | |
| maxSize | Maximum file size in MB | number | |
| acceptType | Predefined accepted file types | 'images' | 'spreadsheets' | 'documents' | 'pdfs' | 'videos' | 'audios' | 'all' | 'all' |
| placeholder | Placeholder text for input variant | string | 'Choose a file...' |
| error | Indicates an error state or displays an error message | string | boolean | |
| success | Indicates a success state or displays a success message | string | boolean | |
| disabled | Disables the component | boolean | false |