```js import FileInput from '@invisionag/iris-react-file-input'; ```
npm install @invisionag/iris-react-file-input``js`
import FileInput from '@invisionag/iris-react-file-input';
FileInput is a generalized Component to handle file selections made by the user. To this end, we make use of the "dropzone" pattern, wherein a file can simply be dragged into the designated zone to fill an element with a filepath.
Usage:
``
Can be passed to indicate that the selected files are currently being processed. It will cause:
* Any interactivity with the dropzone to be disabled
* A spinner to be displayed in the dropzone instead of the regular logic
* The remove-buttons in the FileList to be hidden, so no files can be added or removed while isLoading is true
onChange is called on any state change, including when a file is removed.
Callback that is invoked every time a file is selected, either via drop or traditional file explorer selection. First (and only) argument is an array of selected files:
`jsx
handleDrop = files => {
files.forEach(file =>console.log("file", file))
}
render() {
return
}
`
By default, only one file can be selected. If you want the user to be able to select multiple files, you can provide the multiple prop like so:``
Mime-Type-String or Array of Mime-Type-Strings. If set, the file input will only accept files with the
matching mime-type. Other files will simply be ignored; this is also true if
multiple and accept is set: if a user drops multiple files with different`
mime-types, those with the correct type will be accepted whereas the others
will simply be ignored.`
Via this prop all customizable texts can be set. It should be a polyglot
object following the implementataion in e.g. forecast-ui.
Following text items can be customized in the FileInput by implementing the
corresponding key. If the key is not provided, a default text will be displayed.
| Description | key | default |
|---------------------------------------|----------------------------------------------|------------------- |
| message in initial screen for multiple| file_input.description.multiple | Drag your files here |file_input.description.single
| message in initial screen | | Drag your file here |file_input.joiner
| conjunction before file explorer link | | or |file_input.loading
| displayed in zone when isLoading is passed | | Uploading... |file_input.link
| file explorer link | | choose files |file_input.active_description.valid
| dragging with valid files | | Drop files here |file_input.active_description.invalid
| dragging with invalid files | | Cannot select this file type |file_input.file_limit_warning
| when file limit is reached | | 1 of 1 file selected |
Provides a class name for the react Dropzone.
With the validate prop, a custom validator can be passed to the component.
The component will run the validator function for each file that was added, passing the file as the only argument.
The file will only be added to the selection if the validator function returns true.
```