react-dropzone 7.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -20
- package/dist/es/index.js +273 -370
- package/dist/es/utils/index.js +25 -1
- package/dist/index.js +2 -2
- package/examples/Accept/Readme.md +33 -30
- package/examples/Basic/Readme.md +59 -31
- package/examples/FileDialog/Readme.md +42 -25
- package/examples/Folders/Readme.md +21 -17
- package/examples/Fullscreen/Readme.md +38 -51
- package/examples/Nesting/Readme.md +16 -9
- package/examples/PluginArchitecture/Readme.md +19 -13
- package/examples/Previews/Readme.md +14 -14
- package/examples/Styling/Readme.md +81 -17
- package/package.json +2 -1
- package/src/__snapshots__/index.spec.js.snap +3 -3
- package/src/index.js +202 -277
- package/src/index.spec.js +948 -331
- package/src/utils/index.js +16 -1
- package/src/utils/index.spec.js +43 -4
- package/styleguide.config.js +4 -0
- package/typings/react-dropzone.d.ts +49 -35
- package/typings/tests/accept.tsx +25 -25
- package/typings/tests/all.tsx +6 -19
- package/typings/tests/basic.tsx +20 -53
- package/typings/tests/events.tsx +9 -4
- package/typings/tests/file-dialog.tsx +12 -23
- package/typings/tests/plugin.tsx +15 -5
- package/typings/tests/fullscreen.tsx +0 -88
- package/typings/tests/ref-object.tsx +0 -27
- package/typings/tests/styling.tsx +0 -18
package/README.md
CHANGED
|
@@ -33,36 +33,87 @@ yarn add react-dropzone
|
|
|
33
33
|
|
|
34
34
|
## Usage
|
|
35
35
|
|
|
36
|
-
Import `Dropzone` in your React component:
|
|
37
|
-
|
|
38
36
|
```javascript static
|
|
37
|
+
import React from 'react'
|
|
38
|
+
import classNames from 'classnames'
|
|
39
39
|
import Dropzone from 'react-dropzone'
|
|
40
|
+
|
|
41
|
+
class MyDropzone extends React.Component {
|
|
42
|
+
onDrop = (acceptedFiles, rejectedFiles) => {
|
|
43
|
+
// Do something with files
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
render() {
|
|
47
|
+
return (
|
|
48
|
+
<Dropzone onDrop={this.onDrop}>
|
|
49
|
+
{({getRootProps, getInputProps, isDragActive}) => {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
{...getRootProps()}
|
|
53
|
+
className={classNames('dropzone', {'dropzone--isActive': isDragActive})}
|
|
54
|
+
>
|
|
55
|
+
<input {...getInputProps()} />
|
|
56
|
+
{
|
|
57
|
+
isDragActive ?
|
|
58
|
+
<p>Drop files here...</p> :
|
|
59
|
+
<p>Try dropping some files here, or click to select files to upload.</p>
|
|
60
|
+
}
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}}
|
|
64
|
+
</Dropzone>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
40
68
|
```
|
|
41
69
|
|
|
42
|
-
|
|
70
|
+
## Render Prop Function
|
|
43
71
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
72
|
+
The render property function is what you use to render whatever you want to based on the state of `Dropzone`:
|
|
73
|
+
```jsx static
|
|
74
|
+
<Dropzone>
|
|
75
|
+
{({getRootProps}) => <div {...getRootProps()} />}
|
|
76
|
+
</Dropzone>
|
|
48
77
|
```
|
|
49
78
|
|
|
50
|
-
|
|
79
|
+
### Prop Getters
|
|
80
|
+
See https://react-dropzone.netlify.com/#proptypes `{children}` for more info.
|
|
81
|
+
|
|
82
|
+
These functions are used to apply props to the elements that you render.
|
|
51
83
|
|
|
52
|
-
|
|
84
|
+
This gives you maximum flexibility to render what, when, and wherever you like. You call these on the element in question (for example: `<div {...getRootProps()} />`).
|
|
53
85
|
|
|
54
|
-
|
|
86
|
+
You should pass all your props to that function rather than applying them on the element yourself to avoid your props being overridden (or overriding the props returned).
|
|
87
|
+
E.g.
|
|
88
|
+
```jsx static
|
|
89
|
+
<div
|
|
90
|
+
{...getRootProps({
|
|
91
|
+
onClick: evt => console.log(event)
|
|
92
|
+
})}
|
|
93
|
+
/>
|
|
94
|
+
```
|
|
55
95
|
|
|
56
|
-
|
|
96
|
+
### State
|
|
97
|
+
See https://react-dropzone.netlify.com/#proptypes `{children}` for more info.
|
|
98
|
+
|
|
99
|
+
### Custom refKey
|
|
100
|
+
|
|
101
|
+
Both `getRootProps` and `getInputProps` accept custom `refKey` (defaulted to `ref`) as one of the attributes passed down in the parameter.
|
|
57
102
|
|
|
58
103
|
```javascript static
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
104
|
+
const StyledDropArea = styled.div`
|
|
105
|
+
// Some styling here
|
|
106
|
+
`
|
|
107
|
+
const Example = () => (
|
|
108
|
+
<Dropzone>
|
|
109
|
+
{({ getRootProps, getInputProps }) => (
|
|
110
|
+
<StyledDropArea {...getRootProps({ refKey: 'innerRef' })}>
|
|
111
|
+
<input {...getInputProps()} />
|
|
112
|
+
<p>Drop some files here</p>
|
|
113
|
+
</StyledDropArea>
|
|
114
|
+
)}
|
|
115
|
+
</Dropzone>
|
|
116
|
+
);
|
|
66
117
|
```
|
|
67
118
|
|
|
68
119
|
**Warning**: On most recent browsers versions, the files given by `onDrop` won't have properties `path` or `fullPath`, see [this SO question](https://stackoverflow.com/a/23005925/2275818) and [this issue](https://github.com/react-dropzone/react-dropzone/issues/477).
|
|
@@ -109,14 +160,14 @@ it('tests drag state', async () => {
|
|
|
109
160
|
await flushPromises(dropzone)
|
|
110
161
|
dropzone.update()
|
|
111
162
|
|
|
112
|
-
const child =
|
|
163
|
+
const child = dropzone.find(DummyChildComponent)
|
|
113
164
|
expect(child).toHaveProp('isDragActive', true)
|
|
114
165
|
expect(child).toHaveProp('isDragAccept', false)
|
|
115
166
|
expect(child).toHaveProp('isDragReject', true)
|
|
116
167
|
})
|
|
117
168
|
```
|
|
118
169
|
|
|
119
|
-
Remember to update your mounted component before asserting any props. A complete example for this can be found in `react-dropzone`s own test suite.
|
|
170
|
+
Remember to update your mounted component before asserting any props. A complete example for this can be found in `react-dropzone`s own [test suite](https://github.com/react-dropzone/react-dropzone/blob/master/src/index.spec.js).
|
|
120
171
|
|
|
121
172
|
## Support
|
|
122
173
|
|