4.3.3 • Published 2 years ago

react-drop-zone v4.3.3

Weekly downloads
2,561
License
MIT
Repository
github
Last release
2 years ago

react-drop-zone

Simple and easily usable

This package offers a styled version of the component or a render-function version which allows you to control rendering. Both versions trigger an .onDrop(file: HTML5 File, content: String) (file reading can be disabled).

Styled version (open demo)

StyledDropZone

import { StyledDropZone } from 'react-drop-zone'
import 'react-drop-zone/dist/styles.css'

<StyledDropZone
  onDrop={(file, text) => console.log(file, text)}
/>

Bare version (open demo)

import DropZone from 'react-drop-zone'

<DropZone onDrop={(file, text) => console.log(file)}>
{
  ({ over, overDocument }) =>
    <div>
      {
        over ?
          'file is over element' :
        overDocument ?
          'file is over document' :
          'no file'
      }
    </div>
}
</DropZone>

Props

NameComponentDescriptionDefault
acceptbothRestricts downloads to an extension type.---
multiplebothAllows multiple files to be selected. (disables file reading!)---
onDrop (required)bothcalled when a file is dropped or selected. Signature: (file: HTML5File, text: String)
handleClickbothHandle click events on the rendered componenttrue
dontReadbothPrevents reading the file content, if it's causing problemsfalse
childrenDropZoneRender function that receives ({ over: Boolean, overDocument: Boolean})false
childrenStyledDropZoneLabel on the componentClick or drop your file here

Additional API

The function readFileAsText is exported if you need to read a file's text content:

import { StyledDropZone, readFileAsText } from 'react-drop-zone'
import 'react-drop-zone/dist/styles.css'

<StyledDropZone
  dontRead
  onDrop={(file) =>
    !file.name.endsWith('.txt') ?
      'Not a text file' :
      readFileAsText(file)
        .then(text => console.log(file, text))
  }
/>

Details

The component overwrites the onDrag/DragEnter/.../Drop props of the render function child.

The accept attribute

If you need more information, see here: (open developer)

The device allows, for example, accept = ".pdf, image/*"

4.3.3

2 years ago

4.3.2

3 years ago

4.3.1

3 years ago

4.3.0

3 years ago

4.2.3

4 years ago

4.2.2

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.1

4 years ago

3.0.7

5 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago