11
11
12
12
# Table of Contents
13
13
14
- * [ Installation] ( #installation )
15
- * [ Usage] ( #usage )
16
- * [ Browser Support] ( #browser-support )
17
- * [ Contribute] ( #contribute )
18
- * [ Credits] ( #credits )
19
- * [ Support] ( #support )
20
- * [ License] ( #license )
21
-
14
+ - [ Installation] ( #installation )
15
+ - [ Usage] ( #usage )
16
+ - [ Browser Support] ( #browser-support )
17
+ - [ Contribute] ( #contribute )
18
+ - [ Credits] ( #credits )
19
+ - [ Support] ( #support )
20
+ - [ License] ( #license )
22
21
23
22
## Installation
24
23
@@ -33,7 +32,7 @@ npm add file-selector
33
32
If you are using a bundler such as [ Vite] ( https://vite.dev/ ) or [ Webpack] ( https://webpack.js.org/ ) you can import the package directly:
34
33
35
34
``` js
36
- import {fromEvent } from ' file-selector' ;
35
+ import { fromEvent } from " file-selector" ;
37
36
```
38
37
39
38
### Browser
@@ -46,7 +45,7 @@ If you want to use a CDN, you can use [Skypack](https://www.skypack.dev/), or an
46
45
47
46
``` html
48
47
<script type =" module" >
49
- import {fromEvent } from ' https://cdn.skypack.dev/file-selector@^1.0.0' ;
48
+ import { fromEvent } from " https://cdn.skypack.dev/file-selector@^1.0.0" ;
50
49
</script >
51
50
```
52
51
@@ -56,7 +55,7 @@ Self hosting is also possible, make sure to copy or link the contents of the NPM
56
55
57
56
``` html
58
57
<script type =" module" >
59
- import {fromEvent } from ' ./path/to/file-selector.js' ;
58
+ import { fromEvent } from " ./path/to/file-selector.js" ;
60
59
</script >
61
60
```
62
61
@@ -66,17 +65,17 @@ To avoid repeating the import path and get an experience similar to a bundler yo
66
65
67
66
``` html
68
67
<script type =" importmap" >
69
- {
70
- " imports" : {
71
- // Using the CDN
72
- " file-selector" : " https://cdn.skypack.dev/file-selector@^1.0.0"
73
- // Or a path to your own self-hosted version.
74
- " file-selector" : " ./path/to/file-selector.js"
75
- }
68
+ {
69
+ " imports" : {
70
+ // Using the CDN
71
+ " file-selector" : " https://cdn.skypack.dev/file-selector@^1.0.0"
72
+ // Or a path to your own self-hosted version.
73
+ " file-selector" : " ./path/to/file-selector.js"
76
74
}
75
+ }
77
76
</script >
78
77
<script type =" module" >
79
- import {fromEvent } from ' file-selector' ;
78
+ import { fromEvent } from " file-selector" ;
80
79
</script >
81
80
```
82
81
@@ -85,64 +84,69 @@ To avoid repeating the import path and get an experience similar to a bundler yo
85
84
Convert a [ DragEvent] ( https://developer.mozilla.org/en-US/docs/Web/API/DragEvent ) to File objects:
86
85
87
86
``` js
88
- import {fromEvent } from ' file-selector' ;
87
+ import { fromEvent } from " file-selector" ;
89
88
90
- document .addEventListener (' drop' , async (event ) => {
91
- const files = await fromEvent (event );
92
- console .log (files);
89
+ document .addEventListener (" drop" , async (event ) => {
90
+ const files = await fromEvent (event );
91
+ console .log (files);
93
92
});
94
93
```
95
94
96
95
Convert a [ change event] ( https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event ) for an input type file to File objects:
97
96
98
97
``` js
99
- import {fromEvent } from ' file-selector' ;
98
+ import { fromEvent } from " file-selector" ;
100
99
101
- const input = document .getElementById (' myInput' );
102
- input .addEventListener (' change' , async (event ) => {
103
- const files = await fromEvent (event );
104
- console .log (files);
100
+ const input = document .getElementById (" myInput" );
101
+ input .addEventListener (" change" , async (event ) => {
102
+ const files = await fromEvent (event );
103
+ console .log (files);
105
104
});
106
105
```
107
106
108
107
Convert [ FileSystemFileHandle] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle ) items to File objects:
109
108
110
109
``` js
111
- import {fromEvent } from ' file-selector' ;
110
+ import { fromEvent } from " file-selector" ;
112
111
113
- const handles = await window .showOpenFilePicker ({multiple: true });
112
+ const handles = await window .showOpenFilePicker ({ multiple: true });
114
113
const files = await fromEvent (handles);
115
114
console .log (files);
116
115
```
117
116
118
- > [ !NOTE]
117
+ > [ !NOTE]
119
118
> The above is experimental and subject to change.
120
119
121
120
## Browser Support
121
+
122
122
Most browser support basic File selection with drag 'n' drop or file input:
123
- * [ File API] ( https://developer.mozilla.org/en-US/docs/Web/API/File#Browser_compatibility )
124
- * [ Drag Event] ( https://developer.mozilla.org/en-US/docs/Web/API/DragEvent#Browser_compatibility )
125
- * [ DataTransfer] ( https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#Browser_compatibility )
126
- * [ ` <input type="file"> ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Browser_compatibility )
123
+
124
+ - [ File API] ( https://developer.mozilla.org/en-US/docs/Web/API/File#Browser_compatibility )
125
+ - [ Drag Event] ( https://developer.mozilla.org/en-US/docs/Web/API/DragEvent#Browser_compatibility )
126
+ - [ DataTransfer] ( https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#Browser_compatibility )
127
+ - [ ` <input type="file"> ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Browser_compatibility )
127
128
128
129
For folder drop we use the [ FileSystem API] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystem ) which has very limited support:
129
- * [ DataTransferItem.getAsFile()] ( https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFile#Browser_compatibility )
130
- * [ DataTransferItem.webkitGetAsEntry()] ( https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#Browser_compatibility )
131
- * [ FileSystemEntry] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry#Browser_compatibility )
132
- * [ FileSystemFileEntry.file()] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file#Browser_compatibility )
133
- * [ FileSystemDirectoryEntry.createReader()] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader#Browser_compatibility )
134
- * [ FileSystemDirectoryReader.readEntries()] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries#Browser_compatibility )
135
130
131
+ - [ DataTransferItem.getAsFile()] ( https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFile#Browser_compatibility )
132
+ - [ DataTransferItem.webkitGetAsEntry()] ( https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#Browser_compatibility )
133
+ - [ FileSystemEntry] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry#Browser_compatibility )
134
+ - [ FileSystemFileEntry.file()] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file#Browser_compatibility )
135
+ - [ FileSystemDirectoryEntry.createReader()] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader#Browser_compatibility )
136
+ - [ FileSystemDirectoryReader.readEntries()] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries#Browser_compatibility )
136
137
137
138
## Contribute
139
+
138
140
Checkout the organization [ CONTRIBUTING.md] ( https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md ) .
139
141
140
142
## Credits
141
- * [ html5-file-selector] ( https://github.com/quarklemotion/html5-file-selector )
143
+
144
+ - [ html5-file-selector] ( https://github.com/quarklemotion/html5-file-selector )
142
145
143
146
## Support
144
147
145
148
### Backers
149
+
146
150
Support us with a monthly donation and help us continue our activities. [[ Become a backer] ( https://opencollective.com/react-dropzone#backer )]
147
151
148
152
<a href =" https://opencollective.com/react-dropzone/backer/0/website " target =" _blank " ><img src =" https://opencollective.com/react-dropzone/backer/0/avatar.svg " ></a >
@@ -158,6 +162,7 @@ Support us with a monthly donation and help us continue our activities. [[Become
158
162
<a href =" https://opencollective.com/react-dropzone/backer/10/website " target =" _blank " ><img src =" https://opencollective.com/react-dropzone/backer/10/avatar.svg " ></a >
159
163
160
164
### Sponsors
165
+
161
166
Become a sponsor and get your logo on our README on Github with a link to your site. [[ Become a sponsor] ( https://opencollective.com/react-dropzone#sponsor )]
162
167
163
168
<a href =" https://opencollective.com/react-dropzone/sponsor/0/website " target =" _blank " ><img src =" https://opencollective.com/react-dropzone/sponsor/0/avatar.svg " ></a >
@@ -173,4 +178,5 @@ Become a sponsor and get your logo on our README on Github with a link to your s
173
178
<a href =" https://opencollective.com/react-dropzone/sponsor/10/website " target =" _blank " ><img src =" https://opencollective.com/react-dropzone/sponsor/10/avatar.svg " ></a >
174
179
175
180
## License
181
+
176
182
MIT
0 commit comments