Skip to content

Commit d57d211

Browse files
authored
Merge pull request #32 from mother/v3
Version 3
2 parents 5f19c58 + 958f66d commit d57d211

25 files changed

+6589
-12572
lines changed

.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"presets": ["@babel/env", "@babel/stage-0", "@babel/react"]
2+
"presets": [
3+
["@babel/preset-env", { "modules": false }],
4+
"@babel/preset-react"
5+
]
36
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/*

.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "mother",
3+
"rules": {
4+
"import/no-extraneous-dependencies": [
5+
"error", {
6+
"devDependencies": true,
7+
"optionalDependencies": false,
8+
"peerDependencies": true
9+
}
10+
]
11+
}
12+
}

.eslintrc.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DS_Store
22
node_modules
33
npm-debug.log
4+
examples/.uploads/*
45
.tmp/*
5-
.uploads/*

README.md

Lines changed: 48 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,62 @@
1-
react-files
1+
React Files
22
=======================
33

4-
> A file input (dropzone) management component for React
4+
A minimal, zero dependency, file input (dropzone) component for React.
55

6-
## Demo
6+
If upgrading from version 1 or 2, see the [Upgrading to Version 3](#upgrading-to-version-3) section below.
77

88
![Alt text](/demo.gif?raw=true "Demo")
99

1010
## Installation
1111

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+.
1313

1414
```bash
1515
npm install react-files --save
1616
```
1717

18-
## Usage
19-
20-
#### Basic
18+
## Basic Usage
2119

2220
```js
2321
import React from 'react'
24-
import ReactDOM from 'react-dom'
2522
import Files from 'react-files'
2623

27-
var FilesDemo = React.createClass({
28-
onFilesChange: function (files) {
24+
const FileDropzone = () => {
25+
const handleChange = (files) => {
2926
console.log(files)
30-
},
27+
}
3128

32-
onFilesError: function (error, file) {
29+
const handleError = (error, file) => {
3330
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-
)
5431
}
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
6532

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+
}
7749
```
7850

79-
Then visit http://localhost:8080/
51+
## Upgrading to Version 3
8052

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).
8258

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).
8660

8761
## Props
8862

@@ -159,20 +133,29 @@ Minimum file size allowed (in bytes)
159133

160134
---
161135

162-
`dropActiveClassName` - *String*
163-
164-
Default: `'files-dropzone-active'`
136+
`dragActiveClassName` - *String*
165137

166138
Class added to the Files component when user is actively hovering over the dropzone with files selected.
167139

168140
---
169141

170-
### Test (todo)
142+
## Examples
143+
144+
To run the examples locally, clone and install peer dependencies (React 16.8+)
171145

172146
```
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:
174153
```
154+
npm run examples
155+
```
156+
157+
Then visit http://localhost:8080/
175158

176-
### License
159+
## License
177160

178-
MIT. Copyright (c) 2016 Jared Reich.
161+
MIT. Copyright (c) Mother Co. 2023

webpack.config.js renamed to config/webpack.build.config.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@ module.exports = {
66
main: './src/index.js'
77
},
88
output: {
9-
path: path.resolve(__dirname, 'dist'),
9+
path: path.resolve(__dirname, '..', 'dist'),
1010
filename: 'index.js',
1111
libraryTarget: 'umd',
1212
// Workaround until https://github.com/webpack/webpack/issues/6525 is adddressed
1313
globalObject: 'this'
1414
},
1515
externals: {
16-
react: 'react'
16+
react: {
17+
commonjs: 'react',
18+
commonjs2: 'react',
19+
amd: 'React',
20+
root: 'React'
21+
},
22+
'react-dom': {
23+
commonjs: 'react-dom',
24+
commonjs2: 'react-dom',
25+
amd: 'ReactDOM',
26+
root: 'ReactDOM'
27+
}
1728
},
1829
module: {
1930
rules: [

webpack.dev.config.js renamed to config/webpack.dev.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
mode: 'development',
66
entry: [
77
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
8-
'./src/demo.js'
8+
'./examples/index.js'
99
],
1010
output: {
1111
path: path.resolve(__dirname, 'dist'),

0 commit comments

Comments
 (0)