import * as React from 'react'import { FileDrop } from '@welcome-ui/file-drop'const Example = () => {const handleChange = () => {// your code}return (<FileDrophandleAddFile={handleChange}handleRemoveFile={handleChange}isClearableisEditablename="file"value=""/>)}export default Example
Installation
Run the following command:
yarn add @welcome-ui/file-drop
Import component:
import { FileDrop } from '@welcome-ui/file-drop'
FileDrop uses render props to give you more flexibility on what to render at each state change:
isDefault
: No file uploaded and no user interactionisHoverAccept
: File is being dragged over and matches theaccept
stringisHoverReject
: File is being dragged over but does not match theaccept
string
You also have access to:
openFile
: To open the native file chooser dialog boxfileUrl
: URL of file if one has been opened/dropped (to show a preview)
By default, accept
: is set to { "image/*": [] }
. See more about showOpenFilePicker and media type.
Custom wordings
By default:
title
: is set to"Add file"
hint
: is set to"Drag & drop a file here or"
fileButtonText
: is set to"Browse file"
previewButtonText
: is set to"Preview"
You can override translations with a wordings
object.
With preview
Preview
Image
Other
Without type
Sometime in the url we don't have the type of the file, you can override with forceFileType
set to image
, audio
or video
.
With a custom filename
By default, the filename is retrieved from the url. If you want to display a custom filename, you can use the fileName
prop.