Skip to content

Commit f9a18cb

Browse files
committed
update changelog and readme
1 parent 48d9b51 commit f9a18cb

File tree

2 files changed

+98
-14
lines changed

2 files changed

+98
-14
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# react-file-trap changelog
2+
3+
## v1.0.1
4+
5+
- [Added default values for props. This was cause errors when allowedExtensions prop is not provided](https://github.com/rasimandiran/react-file-trap/commit/7b0b3bf1db94faa6ba05047d21e3ca86e0ebcd64)
6+
- [onClick event handler checked before bind. This was cause errors when browseOnClick prop is false but manual triggering element inside of the trap](https://github.com/rasimandiran/react-file-trap/commit/2017715a48ca41123b45e14f1463303a0813bcd7)
7+
- [Added a new funtion to remove specific files from file list](https://github.com/rasimandiran/react-file-trap/commit/d6fd3cc9e6f868a27810ae099e6167656698538e)
8+
- [Page title of the example application is updated](https://github.com/rasimandiran/react-file-trap/commit/48d9b5153c3c534450a2bcd602d92cc46c2be446)
9+
10+
## v1.0.0
11+
12+
- Initial release

README.md

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,92 @@ npm install react-file-trap
4040

4141
## Props
4242

43-
| Parameter | Type | Description |
44-
| :-------- | :------- | :------------------------- |
45-
| `ref` | `ref` | Suggest to use to reset and/or trigger browse outside of child component |
46-
| `allowedExtensions` | `array` | Allowed file extensions |
47-
| `handleChange` | `function` | Runs when selected and/or dropped a valid file |
48-
| `handleDrag` | `function` | Runs for every drag event. Possible values: `dragover` `dragleave` |
49-
| `handleDrop` | `function` | Runs when dropped a file |
50-
| `onValidationError` | `function` | Runs everytime if dropped or selected file invalid |
51-
| `fileCount` | `number` | Allowed file count |
52-
| `maxFileSize` | `number` | Allowed upper limit for file size in MB |
53-
| `minFileSize` | `number` | Allowed lower limit for file size in MB |
54-
| `browseOnClick` | `boolean` | Trigger browse window on click to child component |
55-
56-
For more details about usage, please check example project in the root directory.
43+
| Parameter | Type | Description | Default Value | Notes |
44+
| :-------- | :------- | :------------------------- |:----------------- |:--------- |
45+
| `ref` | `ref` | Suggest to use to reset and/or trigger browse outside of child component | `undefined` | Should be defined to trigger some [functions](https://github.com/rasimandiran/react-file-trap#functions)|
46+
| `allowedExtensions` | `array` | Allowed file extensions | `undefined` | Don't provide to allow all file types |
47+
| `handleChange` | `function` | Runs when selected and/or dropped a valid file | | Mandatory prop to handle files. See [events](https://github.com/rasimandiran/react-file-trap#events) |
48+
| `handleDrag` | `function` | Runs for every drag event. Possible values: `dragover` `dragleave` | `undefined` | See [events](https://github.com/rasimandiran/test/tree/main#events) |
49+
| `handleDrop` | `function` | Runs when dropped a file | `undefined` | See [events](https://github.com/rasimandiran/react-file-trap#events) |
50+
| `onValidationError` | `function` | Runs everytime if dropped or selected file invalid | `undefined` | See [events](https://github.com/rasimandiran/react-file-trap#events) |
51+
| `fileCount` | `number` | Allowed file count | `Number.MAX_VALUE` | |
52+
| `maxFileSize` | `number` | Allowed upper limit for file size in MB | `Number.MAX_VALUE` | |
53+
| `minFileSize` | `number` | Allowed lower limit for file size in MB | `0` | |
54+
| `browseOnClick` | `boolean` | Trigger browse window on click to child component | `true` | |
55+
56+
## Events
57+
58+
### handleChange
59+
60+
Runs on every change on the valid files. `fileList` parameter includes all valid files.
61+
62+
```javascript
63+
const handleChange = (fileList) => {
64+
setFiles(filesList);
65+
setTotalSize(byteFormatter(newFiles.reduce((acc, file) => acc + file.size, 0)));
66+
};
67+
```
68+
69+
### handleDrag
70+
71+
Runs on drag event, eventName parametet can be: `dragover` or `dragleave`
72+
73+
```javascript
74+
const handleDrag = (eventName) => {
75+
setCurrentEvent(eventName);
76+
};
77+
```
78+
79+
### handleDrop
80+
81+
Runs after a dropped files.
82+
83+
```javascript
84+
const handleDrop = () => {
85+
setCurrentEvent('dropped');
86+
};
87+
```
88+
89+
### onValidationError
90+
91+
Runs after selected/dropped files.
92+
93+
```javascript
94+
const onValidationError = (invalidFileList, errorMsg) => {
95+
setInvalidFiles([...invalidFiles, ...invalidFileList]);
96+
setLastError(errorMsg);
97+
}
98+
```
99+
100+
## Functions
101+
102+
### browseFiles
103+
104+
Trigger browse window manually. `ref` prop is needed.
105+
106+
```javascript
107+
wrapperRef.current.browseFiles();
108+
```
109+
110+
### resetWrapper
111+
112+
To reset selected files. `ref` prop is needed.
113+
114+
```javascript
115+
wrapperRef.current.resetWrapper();
116+
```
117+
118+
### removeFile
119+
120+
To remove specific file. `file` should be provided as parameter. `ref` prop is also needed.
121+
122+
```javascript
123+
wrapperRef.current.removeFile(file);
124+
```
125+
126+
## Notes
127+
128+
For more details about usage, please check `example` project in the root directory.
57129

58130
## License
59131

0 commit comments

Comments
 (0)