3.0.3 • Published 11 months ago

react-drag-drop-browser v3.0.3

Weekly downloads
37
License
MIT
Repository
github
Last release
11 months ago

react-drag-drop-browser

Simple, customizable react drag and drop component. Also comes with a file browser.

Coverage Status

NPM page | Run example app on codesandbox

Installation

Installation can be done with yarn or npm

# yarn
yarn add react-drag-drop-browser

# npm
npm install react-drag-drop-browser

‼️ Important

The maximum allowed file size is set to 1MB by default and can be changed as required. This is worth mentiontioning because there is no feedback provided. If you need to do that you should do the check yourself. I only included it as a sensible default to prevent the inadvertent upload of very large files.

Usage

<DragAndDrop /> props

PropDefault valueDescription
zoneId (optional, string)hot-zoneA unique id to identify the hot zone
dataTestId (optional, string)hot-zonedata-testid of the hot zone
maxSizeInMB (optional, number)1maximum allowed file size
children (optional, string, ReactElement)Drop files here
zoneClassName (optional, string)hot-zoneClass to style the section element
inZoneClassName (optional, string)inside-hot-zoneThis class is applied when the dragged file is within the hot zone
render (optional, ReactElement)undefindedIf this is defined, it takes precedence. In that case you have to attach the event handlers defined in the DragAndDropRenderProps prop
onDropFiles (required, function)A callback function that receives the array of files dropped into the hot zone

<FileBrowser /> props

PropDefault valueDescription
dataTestId (optional, string)file-browserdata-testid of the trigger button
maxSizeInMB (optional, number)1maximum allowed file size
inputId (optional, string)input-idid of the input element
multiple (optional, boolean)falseWhether to allow selecting multiple files
allowedFileTypes (optional, string[])[".pdf", ".jpeg", ".png", ".jpg"]The kinds of files to select
pickerBtnText (optional, string)Click here to browse filesText of the file picker trigger button
pickerBtnClassName (optional, string)file-browser-buttonClass to style the trigger button
render (optional, ReactElement)undefinedIf this is defined, then the button is not rendered. It accepts an object with an onClick property
onSelectFiles (required, function)A callback function that receives the array of files dropped in the hot zone

Contributing

  1. Clone the repository
  2. Open a terminal and cd into the dev-app/ folder and package/ folder and run yarn install in both separately
  3. Linking for development. Inside package/ run npm link. Then navigate to the dev-app/ folder and run yarn link react-drag-drop-browser

Credits

  1. Publish a react component as npm module
  2. This inspired me to take a closer look at the implementation of the dragenter and dragleave events
3.0.3

11 months ago

3.0.1

11 months ago

3.0.0

11 months ago

2.0.1

5 years ago

1.1.9

5 years ago

2.0.0

5 years ago

1.1.8

5 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago