Skip to content

Commit 24e30a7

Browse files
authored
Merge pull request #31 from Bunlong/v3.4.0
Upgrade Papaparse to Latest Version
2 parents b5aaa2c + f6c535b commit 24e30a7

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<p align="center">
2+
⭐️ Please support react-papaparse by giving a star! ⭐️
3+
</p>
4+
15
# react-papaparse
26

37
The fastest in-browser CSV (or delimited text) parser for React.
@@ -209,6 +213,7 @@ export default class CSVReader extends Component {
209213
onDrop={this.handleOnDrop}
210214
onError={this.handleOnError}
211215
addRemoveButton
216+
removeButtonColor='#659cef'
212217
onRemoveFile={this.handleOnRemoveFile}
213218
>
214219
<span>Drop CSV file here or click to upload.</span>

docs/src/components/screens/Demo.js

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export default class Demo extends Component {
292292
onDrop={this.handleOnDrop}
293293
onError={this.handleOnError}
294294
addRemoveButton
295+
removeButtonColor='#659cef'
295296
onRemoveFile={this.handleOnRemoveFile}
296297
>
297298
<span>Drop CSV file here or click to upload.</span>

docs/src/components/screens/docs/CSVToJSON.js

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const CSVToJSON = () => {
111111
<li><code>progressBarColor</code> is a property to be used to set the color of progress bar (for example, <code>progressBarColor='#659cef'</code>).</li>
112112
<li><code>style</code> is some styles to be applied to the <code>{'<input>'}</code> element.</li>
113113
<li><code>addRemoveButton</code> If true, this will add a button to remove or cancel (if already uploading) the file.</li>
114+
<li><code>removeButtonColor</code> is a property to be used to set the color of remove button (for example, <code>removeButtonColor='#659cef'</code>).</li>
114115
<li><code>config</code> is a <a href='#config'>config object</a> which contains a callback.</li>
115116
<li>Doesn't return anything. Results are provided asynchronously to a callback function.</li>
116117
</ul>
@@ -149,6 +150,7 @@ const CSVToJSON = () => {
149150
<li><code>progressBarColor</code> is a property to be used to set the color of progress bar (for example, <code>progressBarColor='#659cef'</code>).</li>
150151
<li><code>style</code> is some styles to be applied to the <code>{'<input>'}</code> element.</li>
151152
<li><code>addRemoveButton</code> If true, this will add a button to remove or cancel (if already uploading) the file.</li>
153+
<li><code>removeButtonColor</code> is a property to be used to set the color of remove button (for example, <code>removeButtonColor='#659cef'</code>).</li>
152154
<li><code>config</code> is a <a href='#config'>config object</a> which contains a callback.</li>
153155
<li>Doesn't return anything. Results are provided asynchronously to a callback function.</li>
154156
</ul>
@@ -187,6 +189,7 @@ const CSVToJSON = () => {
187189
<li><code>progressBarColor</code> is a property to be used to set the color of progress bar (for example, <code>progressBarColor='#659cef'</code>).</li>
188190
<li><code>style</code> is some styles to be applied to the <code>{'<input>'}</code> element.</li>
189191
<li><code>addRemoveButton</code> If true, this will add a button to remove or cancel (if already uploading) the file.</li>
192+
<li><code>removeButtonColor</code> is a property to be used to set the color of remove button (for example, <code>removeButtonColor='#659cef'</code>).</li>
190193
<li><code>config</code> is a <a href='#config'>config object</a> which contains a callback.</li>
191194
<li>Doesn't return anything. Results are provided asynchronously to a callback function.</li>
192195
</ul>

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-papaparse",
3-
"version": "3.3.0",
3+
"version": "3.4.0",
44
"description": "Fast and powerful React CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.",
55
"author": "Bunlong <bunlong.van@gmail.com>",
66
"license": "MIT",
@@ -94,7 +94,7 @@
9494
"dist"
9595
],
9696
"dependencies": {
97-
"@types/papaparse": "^5.0.3",
98-
"papaparse": "^5.1.1"
97+
"@types/papaparse": "^5.0.4",
98+
"papaparse": "^5.2.0"
9999
}
100100
}

src/CSVReader.tsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React, { CSSProperties } from 'react';
22
import PapaParse from 'papaparse';
3-
import getSize from './util';
3+
import getSize, { lightenDarkenColor } from './util';
44
import RemoveIcon from './RemoveIcon';
55
import ProgressBar from './ProgressBar';
66

77
const GREY = '#CCC';
88
const GREY_LIGHT = 'rgba(255, 255, 255, 0.4)';
9-
const RED = '#A01919';
10-
const RED_LIGHT = '#DD2222';
119

1210
const styles = {
1311
dropArea: {
@@ -90,6 +88,7 @@ interface Props {
9088
addRemoveButton?: boolean;
9189
onRemoveFile?: (data: any) => void;
9290
noProgressBar?: boolean;
91+
removeButtonColor?: string;
9392
}
9493

9594
interface State {
@@ -110,14 +109,17 @@ export default class CSVReader extends React.Component<Props, State> {
110109
fileSizeInfoRef: any = React.createRef<HTMLDivElement>();
111110
fileNameInfoRef: any = React.createRef<HTMLDivElement>();
112111

112+
REMOVE_ICON_COLOR = this.props.removeButtonColor || '#A01919';
113+
REMOVE_ICON_COLOR_LIGHT = lightenDarkenColor(this.REMOVE_ICON_COLOR, 40);
114+
113115
state = {
114116
dropAreaStyle: styles.dropArea,
115117
progressBar: 0,
116118
displayProgressBarStatus: 'none',
117119
file: null,
118120
timeout: null,
119121
files: null,
120-
removeIconColor: RED,
122+
removeIconColor: this.REMOVE_ICON_COLOR,
121123
isCanceled: false,
122124
} as State;
123125

@@ -372,8 +374,10 @@ export default class CSVReader extends React.Component<Props, State> {
372374
<div
373375
style={styles.dropFileRemoveButton}
374376
onClick={(e) => this.removeFile(e)}
375-
onMouseOver={() => this.changeRemoveIconColor(RED_LIGHT)}
376-
onMouseOut={() => this.changeRemoveIconColor(RED)}
377+
onMouseOver={() =>
378+
this.changeRemoveIconColor(this.REMOVE_ICON_COLOR_LIGHT)
379+
}
380+
onMouseOut={() => this.changeRemoveIconColor(this.REMOVE_ICON_COLOR)}
377381
>
378382
<RemoveIcon color={removeIconColor} />
379383
</div>
@@ -383,12 +387,12 @@ export default class CSVReader extends React.Component<Props, State> {
383387
if (addRemoveButton) {
384388
return (
385389
<div style={styles.dropFileRemoveButton}>
386-
<RemoveIcon color={RED} />
390+
<RemoveIcon color={this.REMOVE_ICON_COLOR} />
387391
</div>
388392
);
389393
}
390394

391-
return <></>;
395+
return null;
392396
};
393397

394398
render() {

src/util.ts

+31
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,34 @@ export default function getSize(size: number) {
1818

1919
return '';
2020
}
21+
22+
export function lightenDarkenColor(col: string, amt: number) {
23+
let usePound = false;
24+
if (col[0] == '#') {
25+
col = col.slice(1);
26+
usePound = true;
27+
}
28+
29+
const num = parseInt(col, 16);
30+
let r = (num >> 16) + amt;
31+
if (r > 255) {
32+
r = 255;
33+
} else if (r < 0) {
34+
r = 0;
35+
}
36+
37+
let b = ((num >> 8) & 0x00ff) + amt;
38+
if (b > 255) {
39+
b = 255;
40+
} else if (b < 0) {
41+
b = 0;
42+
}
43+
44+
let g = (num & 0x0000ff) + amt;
45+
if (g > 255) {
46+
g = 255;
47+
} else if (g < 0) {
48+
g = 0;
49+
}
50+
return (usePound ? '#' : '') + (g | (b << 8) | (r << 16)).toString(16);
51+
}

0 commit comments

Comments
 (0)