|
1 | | -react-files |
| 1 | +React Files |
2 | 2 | ======================= |
3 | 3 |
|
4 | | -> A file input (dropzone) management component for React |
| 4 | +A minimal, zero dependency, file input (dropzone) component for React. |
5 | 5 |
|
6 | | -## Demo |
| 6 | +If upgrading from version 1 or 2, see the [Upgrading to Version 3](#upgrading-to-version-3) section below. |
7 | 7 |
|
8 | 8 |  |
9 | 9 |
|
10 | 10 | ## Installation |
11 | 11 |
|
12 | | -Install from NPM and include it in your own React build process (using [Browserify](http://browserify.org), [Webpack](http://webpack.github.io/), etc). |
| 12 | +Install using npm or yarn. Requires React 16.8+. |
13 | 13 |
|
14 | 14 | ```bash |
15 | 15 | npm install react-files --save |
16 | 16 | ``` |
17 | 17 |
|
18 | | -## Usage |
19 | | - |
20 | | -#### Basic |
| 18 | +## Basic Usage |
21 | 19 |
|
22 | 20 | ```js |
23 | 21 | import React from 'react' |
24 | | -import ReactDOM from 'react-dom' |
25 | 22 | import Files from 'react-files' |
26 | 23 |
|
27 | | -var FilesDemo = React.createClass({ |
28 | | - onFilesChange: function (files) { |
| 24 | +const FileDropzone = () => { |
| 25 | + const handleChange = (files) => { |
29 | 26 | console.log(files) |
30 | | - }, |
| 27 | + } |
31 | 28 |
|
32 | | - onFilesError: function (error, file) { |
| 29 | + const handleError = (error, file) => { |
33 | 30 | console.log('error code ' + error.code + ': ' + error.message) |
34 | | - }, |
35 | | - |
36 | | - render: function() { |
37 | | - return ( |
38 | | - <div className="files"> |
39 | | - <Files |
40 | | - className='files-dropzone' |
41 | | - onChange={this.onFilesChange} |
42 | | - onError={this.onFilesError} |
43 | | - accepts={['image/png', '.pdf', 'audio/*']} |
44 | | - multiple |
45 | | - maxFiles={3} |
46 | | - maxFileSize={10000000} |
47 | | - minFileSize={0} |
48 | | - clickable |
49 | | - > |
50 | | - Drop files here or click to upload |
51 | | - </Files> |
52 | | - </div> |
53 | | - ) |
54 | 31 | } |
55 | | -}) |
56 | | - |
57 | | -ReactDOM.render(<FilesDemo />, document.getElementById('container')) |
58 | | -``` |
59 | | - |
60 | | -#### Advanced |
61 | | - |
62 | | -See "Tinker" instructions below to run and view all examples. |
63 | | - |
64 | | -### Tinker |
65 | 32 |
|
66 | | -``` |
67 | | -git clone https://github.com/mother/react-files |
68 | | -npm install |
69 | | -``` |
70 | | -And since React is just a peer dependency: |
71 | | -``` |
72 | | -npm install react |
73 | | -``` |
74 | | -Then: |
75 | | -``` |
76 | | -npm run dev |
| 33 | + return ( |
| 34 | + <div className="files"> |
| 35 | + <Files |
| 36 | + className='files-dropzone' |
| 37 | + onChange={handleChange} |
| 38 | + onError={handleError} |
| 39 | + accepts={['image/png', '.pdf', 'audio/*']} |
| 40 | + multiple |
| 41 | + maxFileSize={10000000} |
| 42 | + minFileSize={0} |
| 43 | + clickable> |
| 44 | + Drop files here or click to upload |
| 45 | + </Files> |
| 46 | + </div> |
| 47 | + ) |
| 48 | +} |
77 | 49 | ``` |
78 | 50 |
|
79 | | -Then visit http://localhost:8080/ |
| 51 | +## Upgrading to Version 3 |
80 | 52 |
|
81 | | -### Build |
| 53 | +Most of the changes made to version 3 are internal, but there are some notable and breaking changes: |
| 54 | +1. The most significant change is that `react-files` no longer manages state internally to track files that have been uploaded to a file list. This can be achieved quite simply however - please refer to the [`ListWithUpload` example](https://github.com/mother/react-files/blob/master/src/examples/ListWithUpload.js). |
| 55 | +2. `dropActiveClassName` prop has been renamed to `dragActiveClassName`. |
| 56 | +2. Removed unnecessary parent/wrapper `div` element. No more default values for `className` or `dragActiveClassName` props. |
| 57 | +3. Ability to pass in a render prop with a prop that indicates whether a drag is in progress. See the [`RenderProps` example](https://github.com/mother/react-files/blob/master/src/examples/RenderProps.js). |
82 | 58 |
|
83 | | -``` |
84 | | -npm run build |
85 | | -``` |
| 59 | +For a full list of changes, please checkout the [V3 PR](https://github.com/mother/react-files/pull/24). |
86 | 60 |
|
87 | 61 | ## Props |
88 | 62 |
|
@@ -159,20 +133,29 @@ Minimum file size allowed (in bytes) |
159 | 133 |
|
160 | 134 | --- |
161 | 135 |
|
162 | | -`dropActiveClassName` - *String* |
163 | | - |
164 | | -Default: `'files-dropzone-active'` |
| 136 | +`dragActiveClassName` - *String* |
165 | 137 |
|
166 | 138 | Class added to the Files component when user is actively hovering over the dropzone with files selected. |
167 | 139 |
|
168 | 140 | --- |
169 | 141 |
|
170 | | -### Test (todo) |
| 142 | +## Examples |
| 143 | + |
| 144 | +To run the examples locally, clone and install peer dependencies (React 16.8+) |
171 | 145 |
|
172 | 146 | ``` |
173 | | -npm test |
| 147 | +git clone https://github.com/mother/react-files |
| 148 | +npm install |
| 149 | +npm i react react-dom |
| 150 | +``` |
| 151 | + |
| 152 | +Then run the examples server: |
174 | 153 | ``` |
| 154 | +npm run examples |
| 155 | +``` |
| 156 | + |
| 157 | +Then visit http://localhost:8080/ |
175 | 158 |
|
176 | | -### License |
| 159 | +## License |
177 | 160 |
|
178 | | -MIT. Copyright (c) 2016 Jared Reich. |
| 161 | +MIT. Copyright (c) Mother Co. 2023 |
0 commit comments