Installation
Add Component
Copy the code snippet below into you components folder.
Integrate Recipe
Integrate this recipe in to your Panda config.
Usage
Shortcuts
The FileUpload component also provides a set of shortcuts for common use cases.
FileUpload.Items
By default, the FileUpload.Items shortcut renders the list of uploaded files.
This might be more concise if you don't need to customize the file upload items:
FileUpload.List
The FileUpload.List shortcut renders the list of uploaded files. It composes the FileUpload.ItemGroup and FileUpload.Items components.
is the same as:
Examples
Accepted Files
Specify the accepted file types for upload using the accept prop.
Multiple Files
Upload multiple files at once using the maxFiles prop.
Image Preview
Use the FileUpload.ItemPreviewImage component to render a preview of image files.
Directory
Use the directory prop to allow selecting a directory instead of a file.
Media Capture
Use the capture prop to capture and upload media directly from the device camera or microphone.
The capture prop is only supported on mobile devices.
Dropzone
Drop multiple files inside the dropzone. Use the maxFiles prop to limit the number of files that can be uploaded at once.
Input
Use the FileInput component to create a trigger that looks like a text input.
Props
Root
| Prop | Default | Type | 
|---|---|---|
| allowDrop | true | booleanWhether to allow drag and drop in the dropzone element | 
| locale | \en-US\ | stringThe current locale. Based on the BCP 47 definition. | 
| maxFiles | 1 | numberThe maximum number of files | 
| maxFileSize | Infinity | numberThe maximum file size in bytes | 
| minFileSize | 0 | numberThe minimum file size in bytes | 
| preventDocumentDrop | true | booleanWhether to prevent the drop event on the document | 
| accept | Record<string, string[]> | FileMimeType | FileMimeType[]The accept file types | |
| acceptedFiles | File[]The controlled accepted files | |
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. | |
| capture | 'user' | 'environment'The default camera to use when capturing media | |
| defaultAcceptedFiles | File[]The default accepted files when rendered. Use when you don't need to control the accepted files of the input. | |
| directory | booleanWhether to accept directories, only works in webkit browsers | |
| disabled | booleanWhether the file input is disabled | |
| ids | Partial<{
  root: string
  dropzone: string
  hiddenInput: string
  trigger: string
  label: string
  item: (id: string) => string
  itemName: (id: string) => string
  itemSizeText: (id: string) => string
  itemPreview: (id: string) => string
}>The ids of the elements. Useful for composition. | |
| invalid | booleanWhether the file input is invalid | |
| name | stringThe name of the underlying file input | |
| onFileAccept | (details: FileAcceptDetails) => voidFunction called when the file is accepted | |
| onFileChange | (details: FileChangeDetails) => voidFunction called when the value changes, whether accepted or rejected | |
| onFileReject | (details: FileRejectDetails) => voidFunction called when the file is rejected | |
| required | booleanWhether the file input is required | |
| transformFiles | (files: File[]) => Promise<File[]>Function to transform the accepted files to apply transformations | |
| translations | IntlTranslationsThe localized messages to use. | |
| validate | (file: File, details: FileValidateDetails) => FileError[] | nullFunction to validate a file | 
Dropzone
| Prop | Default | Type | 
|---|---|---|
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. | |
| disableClick | booleanWhether to disable the click event on the dropzone | 
Item
| Prop | Default | Type | 
|---|---|---|
| file* | File | |
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. | 
ItemPreview
| Prop | Default | Type | 
|---|---|---|
| type | '.*' | stringThe file type to match against. Matches all file types by default. | 
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. |