1.0.0 • Published 4 years ago

@yelysei/react-files-drag-and-drop v1.0.0

Weekly downloads
155
License
MIT
Repository
github
Last release
4 years ago

@yelysei/react-files-drag-and-drop

A light-weighted and customizable React Component that handles Files Drag & Drop.

Installation

Install with npm:

npm i @yelysei/react-files-drag-and-drop

or with yarn:

yarn add @yelysei/react-files-drag-and-drop

Usage

First you need to import FilesDragAndDrop component:

import FilesDragAndDrop from '@yelysei/react-files-drag-and-drop';

And then use it like this:

<FilesDragAndDrop
    onUpload={(files) => console.log(files)}
    count={3}
    formats={['jpg', 'png', 'svg']}
    containerStyles={{
        width: '200px',
        height: '200px',
        border: '1px solid #cccccc',
    }}
    openDialogOnClick
>
    <div style={{
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
    }}>
        Drop files here
    </div>
</FilesDragAndDrop>

Props

Here is the list of all available props:

NameTypeRequiredDescription
onUploadfunction+Function that will be called when files are dropped into the component and successfully validated. Receives list of files
childrennode+Inner content of the component
countnumberMax count of files
formatsstring[]List of available file formats
openDialogOnClickbooleanIf enabled, file dialog will be opened on click at the component
hoverTextstring or functionMessage that will appear when files are dragged over the component. Function receives available file formats and max files count.Default value: 'Drop files here'
successTextstring or functionMessage that will appear when files are successfully uploaded. Function receives list of uploaded files.Default value: 'Successfully uploaded'
errorCountTextstring or functionMessage that will appear when more files than available are dropped into the component. Function receives available max files count.Default value: ({count}) => `Only ${count} file${count !== 1 ? 's' : ''} can be uploaded at a time`
errorFormatTextstring or functionMessage that will appear when files with incorrect formats are dropped into the component. Function receives available file formats.Default value: ({formats}) => `Only following file formats are acceptable: ${formats.join(', ')}`
containerStylesCSS propertiesCustom styles for container
hoverMessageStylesCSS propertiesCustom styles for hover message
successMessageStylesCSS propertiesCustom styles for success message
errorMessageStylesCSS propertiesCustom styles for error message
successTimenumberTime duration in milliseconds when the success message will be displayed.Default value: 1000
errorTimenumberTime duration in milliseconds when the error message will be displayed.Default value: 2000
onDropfunctionFunction that will be called when files are dropped into the component but not validated yet. Receives list of files
onDragEnterfunctionFunction that will be called when dragged files entered the component
onDragLeavefunctionFunction that will be called when dragged files leaved the component