1111
1212# Table of Contents
1313
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 )
2221
2322## Installation
2423
@@ -33,7 +32,7 @@ npm add file-selector
3332If you are using a bundler such as [ Vite] ( https://vite.dev/ ) or [ Webpack] ( https://webpack.js.org/ ) you can import the package directly:
3433
3534``` js
36- import {fromEvent } from ' file-selector' ;
35+ import { fromEvent } from " file-selector" ;
3736```
3837
3938### Browser
@@ -46,7 +45,7 @@ If you want to use a CDN, you can use [Skypack](https://www.skypack.dev/), or an
4645
4746``` html
4847<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" ;
5049 </script >
5150```
5251
@@ -56,7 +55,7 @@ Self hosting is also possible, make sure to copy or link the contents of the NPM
5655
5756``` html
5857<script type =" module" >
59- import {fromEvent } from ' ./path/to/file-selector.js' ;
58+ import { fromEvent } from " ./path/to/file-selector.js" ;
6059 </script >
6160```
6261
@@ -66,17 +65,17 @@ To avoid repeating the import path and get an experience similar to a bundler yo
6665
6766``` html
6867<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"
7674 }
75+ }
7776 </script >
7877<script type =" module" >
79- import {fromEvent } from ' file-selector' ;
78+ import { fromEvent } from " file-selector" ;
8079 </script >
8180```
8281
@@ -85,64 +84,69 @@ To avoid repeating the import path and get an experience similar to a bundler yo
8584Convert a [ DragEvent] ( https://developer.mozilla.org/en-US/docs/Web/API/DragEvent ) to File objects:
8685
8786``` js
88- import {fromEvent } from ' file-selector' ;
87+ import { fromEvent } from " file-selector" ;
8988
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);
9392});
9493```
9594
9695Convert a [ change event] ( https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event ) for an input type file to File objects:
9796
9897``` js
99- import {fromEvent } from ' file-selector' ;
98+ import { fromEvent } from " file-selector" ;
10099
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);
105104});
106105```
107106
108107Convert [ FileSystemFileHandle] ( https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle ) items to File objects:
109108
110109``` js
111- import {fromEvent } from ' file-selector' ;
110+ import { fromEvent } from " file-selector" ;
112111
113- const handles = await window .showOpenFilePicker ({multiple: true });
112+ const handles = await window .showOpenFilePicker ({ multiple: true });
114113const files = await fromEvent (handles);
115114console .log (files);
116115```
117116
118- > [ !NOTE]
117+ > [ !NOTE]
119118> The above is experimental and subject to change.
120119
121120## Browser Support
121+
122122Most 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 )
127128
128129For 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 )
135130
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 )
136137
137138## Contribute
139+
138140Checkout the organization [ CONTRIBUTING.md] ( https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md ) .
139141
140142## Credits
141- * [ html5-file-selector] ( https://github.com/quarklemotion/html5-file-selector )
143+
144+ - [ html5-file-selector] ( https://github.com/quarklemotion/html5-file-selector )
142145
143146## Support
144147
145148### Backers
149+
146150Support us with a monthly donation and help us continue our activities. [[ Become a backer] ( https://opencollective.com/react-dropzone#backer )]
147151
148152<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
158162<a href =" https://opencollective.com/react-dropzone/backer/10/website " target =" _blank " ><img src =" https://opencollective.com/react-dropzone/backer/10/avatar.svg " ></a >
159163
160164### Sponsors
165+
161166Become 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 )]
162167
163168<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
173178<a href =" https://opencollective.com/react-dropzone/sponsor/10/website " target =" _blank " ><img src =" https://opencollective.com/react-dropzone/sponsor/10/avatar.svg " ></a >
174179
175180## License
181+
176182MIT
0 commit comments