react-dropzone 5.0.0 → 5.1.1

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.
@@ -1,10 +1,13 @@
1
+ /* eslint import/no-extraneous-dependencies: 0 */
1
2
  const path = require('path')
3
+ const { createConfig, babel } = require('webpack-blocks')
2
4
 
3
5
  module.exports = {
4
6
  title: 'react-dropzone',
5
7
  styleguideDir: path.join(__dirname, 'styleguide'),
6
- showCode: true,
7
- showUsage: true,
8
+ webpackConfig: createConfig([babel()]),
9
+ exampleMode: 'expand',
10
+ usageMode: 'expand',
8
11
  showSidebar: false,
9
12
  serverPort: 8080,
10
13
  sections: [
package/testSetup.js CHANGED
@@ -1,8 +1,14 @@
1
1
  /* eslint prefer-template: 0 */
2
+ /* eslint node/no-unpublished-require: 0 */
3
+
4
+ const Enzyme = require('enzyme')
5
+ const Adapter = require('enzyme-adapter-react-16')
2
6
  require('jest-enzyme')
3
7
 
8
+ Enzyme.configure({ adapter: new Adapter() })
9
+
4
10
  global.window.URL = {
5
11
  createObjectURL: function createObjectURL(arg) {
6
- return 'data://' + arg.name
12
+ return `data://${arg.name}`
7
13
  }
8
14
  }
package/tslint.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "jsRules": {
3
+ "class-name": true,
4
+ "comment-format": [
5
+ true,
6
+ "check-space"
7
+ ],
8
+ "indent": [
9
+ true,
10
+ "spaces"
11
+ ],
12
+ "no-duplicate-variable": true,
13
+ "no-eval": true,
14
+ "no-trailing-whitespace": true,
15
+ "no-unsafe-finally": true,
16
+ "one-line": [
17
+ true,
18
+ "check-open-brace",
19
+ "check-whitespace"
20
+ ],
21
+ "quotemark": [
22
+ true,
23
+ "double"
24
+ ],
25
+ "semicolon": [
26
+ true,
27
+ "always"
28
+ ],
29
+ "triple-equals": [
30
+ true,
31
+ "allow-null-check"
32
+ ],
33
+ "variable-name": [
34
+ true,
35
+ "ban-keywords"
36
+ ],
37
+ "whitespace": [
38
+ true,
39
+ "check-branch",
40
+ "check-decl",
41
+ "check-operator",
42
+ "check-separator",
43
+ "check-type"
44
+ ]
45
+ },
46
+ "rules": {
47
+ "class-name": true,
48
+ "comment-format": [
49
+ true,
50
+ "check-space"
51
+ ],
52
+ "indent": [
53
+ true,
54
+ "spaces"
55
+ ],
56
+ "no-eval": true,
57
+ "no-internal-module": true,
58
+ "no-trailing-whitespace": true,
59
+ "no-unsafe-finally": true,
60
+ "no-var-keyword": true,
61
+ "one-line": [
62
+ true,
63
+ "check-open-brace",
64
+ "check-whitespace"
65
+ ],
66
+ "quotemark": [
67
+ true,
68
+ "double"
69
+ ],
70
+ "semicolon": [
71
+ true,
72
+ "always"
73
+ ],
74
+ "triple-equals": [
75
+ true,
76
+ "allow-null-check"
77
+ ],
78
+ "typedef-whitespace": [
79
+ true,
80
+ {
81
+ "call-signature": "nospace",
82
+ "index-signature": "nospace",
83
+ "parameter": "nospace",
84
+ "property-declaration": "nospace",
85
+ "variable-declaration": "nospace"
86
+ }
87
+ ],
88
+ "variable-name": [
89
+ true,
90
+ "ban-keywords"
91
+ ],
92
+ "whitespace": [
93
+ true,
94
+ "check-branch",
95
+ "check-decl",
96
+ "check-operator",
97
+ "check-separator",
98
+ "check-type"
99
+ ]
100
+ }
101
+ }
@@ -0,0 +1,60 @@
1
+ import {
2
+ CSSProperties,
3
+ Component,
4
+ DragEvent,
5
+ InputHTMLAttributes
6
+ } from "react";
7
+
8
+ export interface FileWithPreview extends File {
9
+ preview?: string;
10
+ }
11
+
12
+ export type DropFileEventHandler = (
13
+ acceptedOrRejected: FileWithPreview[],
14
+ event: DragEvent<HTMLDivElement>
15
+ ) => void;
16
+ export type DropFilesEventHandler = (
17
+ accepted: FileWithPreview[],
18
+ rejected: FileWithPreview[],
19
+ event: DragEvent<HTMLDivElement>
20
+ ) => void;
21
+
22
+ type DropzoneRenderArgs = {
23
+ draggedFiles: FileWithPreview[];
24
+ acceptedFiles: FileWithPreview[];
25
+ rejectedFiles: FileWithPreview[];
26
+ isDragActive: boolean;
27
+ isDragAccept: boolean;
28
+ isDragReject: boolean;
29
+ };
30
+
31
+ export type DropzoneRenderFunction = (x: DropzoneRenderArgs) => JSX.Element;
32
+
33
+ type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
34
+
35
+ export type DropzoneProps = Omit<React.HTMLProps<HTMLDivElement>, "onDrop"> & {
36
+ disableClick?: boolean;
37
+ disabled?: boolean;
38
+ disablePreview?: boolean;
39
+ preventDropOnDocument?: boolean;
40
+ inputProps?: InputHTMLAttributes<HTMLInputElement>;
41
+ maxSize?: number;
42
+ minSize?: number;
43
+ activeClassName?: string;
44
+ acceptClassName?: string;
45
+ rejectClassName?: string;
46
+ disabledClassName?: string;
47
+ activeStyle?: CSSProperties;
48
+ acceptStyle?: CSSProperties;
49
+ rejectStyle?: CSSProperties;
50
+ disabledStyle?: CSSProperties;
51
+ onDrop?: DropFilesEventHandler;
52
+ onDropAccepted?: DropFileEventHandler;
53
+ onDropRejected?: DropFileEventHandler;
54
+ onFileDialogCancel?: () => void;
55
+ children: React.ReactNode | DropzoneRenderFunction;
56
+ };
57
+
58
+ export default class Dropzone extends Component<DropzoneProps> {
59
+ open: () => void;
60
+ }
@@ -0,0 +1,76 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ class Accept extends React.Component {
6
+ state = {
7
+ accepted: [],
8
+ rejected: []
9
+ };
10
+
11
+ render() {
12
+ return (
13
+ <section>
14
+ <div className="dropzone">
15
+ <Dropzone
16
+ accept="image/jpeg, image/png"
17
+ onDrop={(accepted, rejected) => {
18
+ this.setState({ accepted, rejected });
19
+ }}
20
+ >
21
+ <p>
22
+ Try dropping some files here, or click to select files to upload.
23
+ </p>
24
+ <p>Only *.jpeg and *.png images will be accepted</p>
25
+ </Dropzone>
26
+ </div>
27
+ <aside>
28
+ <h2>Accepted files</h2>
29
+ <ul>
30
+ {this.state.accepted.map(f => (
31
+ <li key={f.name}>
32
+ {f.name} - {f.size} bytes
33
+ </li>
34
+ ))}
35
+ </ul>
36
+ <h2>Rejected files</h2>
37
+ <ul>
38
+ {this.state.rejected.map(f => (
39
+ <li key={f.name}>
40
+ {f.name} - {f.size} bytes
41
+ </li>
42
+ ))}
43
+ </ul>
44
+ </aside>
45
+ </section>
46
+ );
47
+ }
48
+ }
49
+
50
+ const a = (
51
+ <Dropzone accept=".jpeg,.png">
52
+ {({ isDragActive, isDragReject }) => {
53
+ if (isDragActive) {
54
+ return "All files will be accepted";
55
+ }
56
+ if (isDragReject) {
57
+ return "Some files will be rejected";
58
+ }
59
+ return "Dropping some files here...";
60
+ }}
61
+ </Dropzone>
62
+ );
63
+
64
+ const b = (
65
+ <Dropzone accept="image/jpeg, image/png">
66
+ {({ isDragActive, isDragReject }) => {
67
+ if (isDragActive) {
68
+ return "All files will be accepted";
69
+ }
70
+ if (isDragReject) {
71
+ return "Some files will be rejected";
72
+ }
73
+ return "Dropping some files here...";
74
+ }}
75
+ </Dropzone>
76
+ );
@@ -0,0 +1,58 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ class Test extends React.Component {
6
+ dz: Dropzone;
7
+
8
+ open() {
9
+ this.dz.open();
10
+ }
11
+
12
+ handleFileDialog = () => {};
13
+
14
+ render() {
15
+ return (
16
+ <div>
17
+ <Dropzone
18
+ ref={node => {
19
+ this.dz = node;
20
+ }}
21
+ onClick={event => console.log(event)}
22
+ onDrop={(acceptedFiles, rejectedFiles, event) =>
23
+ console.log(acceptedFiles, rejectedFiles, event)}
24
+ onDragStart={event => console.log(event)}
25
+ onDragEnter={event => console.log(event)}
26
+ onDragOver={event => console.log(event)}
27
+ onDragLeave={event => console.log(event)}
28
+ onDropAccepted={event => console.log(event)}
29
+ onDropRejected={event => console.log(event)}
30
+ onFileDialogCancel={() => console.log("abc")}
31
+ style={{ borderStyle: "dashed" }}
32
+ activeStyle={{ borderStyle: "dotted" }}
33
+ acceptStyle={{ borderStyle: "dotted" }}
34
+ rejectStyle={{ borderStyle: "dotted" }}
35
+ disabledStyle={{ borderStyle: "dotted" }}
36
+ className="regular"
37
+ activeClassName="active"
38
+ acceptClassName="accept"
39
+ rejectClassName="reject"
40
+ disabledClassName="disabled"
41
+ minSize={2000}
42
+ maxSize={Infinity}
43
+ disablePreview
44
+ disableClick
45
+ disabled
46
+ multiple={false}
47
+ accept="*.png"
48
+ name="dropzone"
49
+ inputProps={{ id: "dropzone" }}
50
+ >
51
+ Hi
52
+ </Dropzone>
53
+ </div>
54
+ );
55
+ }
56
+ }
57
+
58
+ export default Test;
@@ -0,0 +1,82 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ class Basic extends React.Component {
6
+ state = { files: [] };
7
+
8
+ onDrop(files) {
9
+ this.setState({
10
+ files
11
+ });
12
+ }
13
+
14
+ render() {
15
+ return (
16
+ <section>
17
+ <div className="dropzone">
18
+ <Dropzone onDrop={this.onDrop.bind(this)}>
19
+ <p>
20
+ Try dropping some files here, or click to select files to upload.
21
+ </p>
22
+ </Dropzone>
23
+ </div>
24
+ <aside>
25
+ <h2>Dropped files</h2>
26
+ <ul>
27
+ {this.state.files.map(f => (
28
+ <li key={f.name}>
29
+ {f.name} - {f.size} bytes
30
+ </li>
31
+ ))}
32
+ </ul>
33
+ </aside>
34
+ </section>
35
+ );
36
+ }
37
+ }
38
+
39
+ class Basic2 extends React.Component {
40
+ state = { disabled: true, files: [] };
41
+
42
+ onDrop(files) {
43
+ this.setState({
44
+ files
45
+ });
46
+ }
47
+
48
+ render() {
49
+ return (
50
+ <section>
51
+ <aside>
52
+ <button
53
+ type="button"
54
+ onClick={() => this.setState({ disabled: !this.state.disabled })}
55
+ >
56
+ Toggle disabled
57
+ </button>
58
+ </aside>
59
+ <div className="dropzone">
60
+ <Dropzone
61
+ onDrop={this.onDrop.bind(this)}
62
+ disabled={this.state.disabled}
63
+ >
64
+ <p>
65
+ Try dropping some files here, or click to select files to upload.
66
+ </p>
67
+ </Dropzone>
68
+ </div>
69
+ <aside>
70
+ <h2>Dropped files</h2>
71
+ <ul>
72
+ {this.state.files.map(f => (
73
+ <li>
74
+ {f.name} - {f.size} bytes
75
+ </li>
76
+ ))}
77
+ </ul>
78
+ </aside>
79
+ </section>
80
+ );
81
+ }
82
+ }
@@ -0,0 +1,26 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ class Events extends React.Component {
6
+ render() {
7
+ return (
8
+ <section>
9
+ <div className="dropzone">
10
+ <Dropzone
11
+ onDrop={(acceptedFiles, rejectedFiles, event) =>
12
+ console.log(acceptedFiles, rejectedFiles, event)}
13
+ onDragStart={event => console.log(event)}
14
+ onDragEnter={event => console.log(event)}
15
+ onDragOver={event => console.log(event)}
16
+ onDragLeave={event => console.log(event)}
17
+ >
18
+ <p>
19
+ Try dropping some files here, or click to select files to upload.
20
+ </p>
21
+ </Dropzone>
22
+ </div>
23
+ </section>
24
+ );
25
+ }
26
+ }
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ let dropzoneRef;
6
+
7
+ const x = (
8
+ <div>
9
+ <Dropzone
10
+ ref={node => {
11
+ dropzoneRef = node;
12
+ }}
13
+ onDrop={(accepted, rejected) => {
14
+ alert(accepted);
15
+ }}
16
+ >
17
+ <p>Drop files here.</p>
18
+ </Dropzone>
19
+ <button
20
+ type="button"
21
+ onClick={() => {
22
+ dropzoneRef.open();
23
+ }}
24
+ >
25
+ Open File Dialog
26
+ </button>
27
+ </div>
28
+ );
@@ -0,0 +1,89 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ class FullScreen extends React.Component {
6
+ state = {
7
+ accept: "",
8
+ files: [],
9
+ dropzoneActive: false
10
+ };
11
+
12
+ onDragEnter() {
13
+ this.setState({
14
+ dropzoneActive: true
15
+ });
16
+ }
17
+
18
+ onDragLeave() {
19
+ this.setState({
20
+ dropzoneActive: false
21
+ });
22
+ }
23
+
24
+ onDrop(files) {
25
+ this.setState({
26
+ files,
27
+ dropzoneActive: false
28
+ });
29
+ }
30
+
31
+ applyMimeTypes(event) {
32
+ this.setState({
33
+ accept: event.target.value
34
+ });
35
+ }
36
+
37
+ render() {
38
+ const { accept, files, dropzoneActive } = this.state;
39
+
40
+ return (
41
+ <Dropzone
42
+ disableClick
43
+ style={{ position: "relative" }}
44
+ accept={accept}
45
+ onDrop={this.onDrop.bind(this)}
46
+ onDragEnter={this.onDragEnter.bind(this)}
47
+ onDragLeave={this.onDragLeave.bind(this)}
48
+ >
49
+ {dropzoneActive && (
50
+ <div
51
+ style={{
52
+ position: "absolute",
53
+ top: 0,
54
+ right: 0,
55
+ bottom: 0,
56
+ left: 0,
57
+ padding: "2.5em 0",
58
+ background: "rgba(0,0,0,0.5)",
59
+ textAlign: "center",
60
+ color: "#fff"
61
+ }}
62
+ >
63
+ Drop files...
64
+ </div>
65
+ )}
66
+ <div>
67
+ <h1>My awesome app</h1>
68
+ <label htmlFor="mimetypes">
69
+ Enter mime types you want to accept:{" "}
70
+ </label>
71
+ <input
72
+ type="text"
73
+ id="mimetypes"
74
+ onChange={this.applyMimeTypes.bind(this)}
75
+ />
76
+
77
+ <h2>Dropped files</h2>
78
+ <ul>
79
+ {files.map(f => (
80
+ <li>
81
+ {f.name} - {f.size} bytes
82
+ </li>
83
+ ))}
84
+ </ul>
85
+ </div>
86
+ </Dropzone>
87
+ );
88
+ }
89
+ }
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+
3
+ import Dropzone from "../../";
4
+
5
+ const x = (
6
+ <Dropzone accept="image/png">
7
+ {({ isDragActive, isDragReject, acceptedFiles, rejectedFiles }) => {
8
+ if (isDragActive) {
9
+ return "This file is authorized";
10
+ }
11
+ if (isDragReject) {
12
+ return "This file is not authorized";
13
+ }
14
+ return acceptedFiles.length || rejectedFiles.length
15
+ ? `Accepted ${acceptedFiles.length}, rejected ${rejectedFiles.length} files`
16
+ : "Try dropping some files.";
17
+ }}
18
+ </Dropzone>
19
+ );
package/wallaby.config.js DELETED
@@ -1,17 +0,0 @@
1
- /* eslint global-require: 0 */
2
- /* eslint import/no-extraneous-dependencies: 0 */
3
- module.exports = wallaby => ({
4
- files: ['package.json', 'src/**/*.js', '!src/**/*.spec.js'],
5
- tests: ['src/**/*.spec.js'],
6
- compilers: {
7
- 'src/**/*.js': wallaby.compilers.babel()
8
- },
9
- env: {
10
- type: 'node',
11
- runner: 'node'
12
- },
13
- testFramework: 'jest',
14
- setup: () => {
15
- wallaby.testFramework.configure(require('./package.json').jest)
16
- }
17
- })
package/webpack.config.js DELETED
@@ -1,43 +0,0 @@
1
- const path = require('path')
2
-
3
- module.exports = env => {
4
- const isProduction = env === 'production'
5
- return {
6
- entry: './src/index.js',
7
- devtool: isProduction ? 'source-map' : 'inline-source-map',
8
- output: {
9
- path: path.resolve(__dirname, 'dist'),
10
- filename: 'index.js',
11
- libraryTarget: 'umd',
12
- library: 'Dropzone'
13
- },
14
- module: {
15
- rules: [
16
- {
17
- include: [path.resolve(__dirname, 'src'), path.resolve(__dirname, 'examples')],
18
- test: /\.js$/,
19
- loader: 'babel-loader',
20
- exclude: /node_modules/
21
- }
22
- ]
23
- },
24
- resolve: {
25
- // Can require('file') instead of require('file.js') etc.
26
- extensions: ['.js', '.json']
27
- },
28
- externals: {
29
- react: {
30
- root: 'React',
31
- commonjs2: 'react',
32
- commonjs: 'react',
33
- amd: 'react'
34
- },
35
- 'prop-types': {
36
- root: 'PropTypes',
37
- commonjs2: 'prop-types',
38
- commonjs: 'prop-types',
39
- amd: 'prop-types'
40
- }
41
- }
42
- }
43
- }