Skip to content

Commit c932735

Browse files
author
nzambello
committed
added component and basic functionalities
1 parent 1bb92f7 commit c932735

File tree

8 files changed

+126
-41
lines changed

8 files changed

+126
-41
lines changed

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
dist
3+
4+
package.json
5+
package-lock.json
6+
yarn.lock

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 120,
3+
"singleQuote": true,
4+
"trailingComma": "none"
5+
}

dist/react-csv-reader.js

Lines changed: 45 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-csv-reader.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"babel-preset-react": "^6.24.1",
1616
"react": "^15.5.4",
1717
"react-dom": "^15.5.4",
18-
"webpack": "^2.5.1"
18+
"webpack": "^2.5.1",
19+
"husky": "^0.14.3",
20+
"lint-staged": "^4.2.3",
21+
"prettier": "1.7.4"
1922
},
2023
"peerDependencies": {
2124
"prop-types": "*",
@@ -24,6 +27,17 @@
2427
},
2528
"scripts": {
2629
"build": "webpack -p",
27-
"watch": "webpack --watch --progress"
30+
"watch": "webpack --watch --progress",
31+
"prettier-all": "prettier --write '**/*.{js,json,css}'",
32+
"precommit": "lint-staged"
33+
},
34+
"dependencies": {
35+
"papaparse": "^4.3.6"
36+
},
37+
"lint-staged": {
38+
"*.{js,json,css}": [
39+
"prettier --write",
40+
"git add"
41+
]
2842
}
2943
}

src/index.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1-
import React from "react"
2-
import { func } from "prop-types"
1+
import React from 'react';
2+
import { string, func } from 'prop-types';
3+
const PapaParse = require('papaparse/papaparse.min.js');
4+
5+
const CSVReader = ({ cssClass, onFileLoaded, onError }) => {
6+
let fileContent = undefined;
7+
8+
const handleChangeFile = e => {
9+
let reader = new FileReader();
10+
11+
reader.onload = event => {
12+
const csvData = PapaParse.parse(event.target.result, {
13+
error: onError
14+
});
15+
onFileLoaded(csvData.data);
16+
};
17+
18+
reader.readAsText(e.target.files[0]);
19+
};
320

4-
const CSVReader = ({ onFileLoaded, onError }) => {
521
return (
6-
<div>
7-
<p>Welcome to CSVReader</p>
8-
</div>
9-
)
10-
}
22+
<input
23+
className={cssClass ? cssClass : ''}
24+
type="file"
25+
id="fileElem"
26+
accept="text/csv"
27+
onChange={e => handleChangeFile(e)}
28+
/>
29+
);
30+
};
1131

1232
CSVReader.propTypes = {
33+
cssClass: string,
1334
onFileLoaded: func,
1435
onError: func
15-
}
36+
};
1637

17-
export default CSVReader
38+
export default CSVReader;

webpack.config.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
var path = require("path")
1+
var path = require('path');
22

33
module.exports = {
4-
devtool: "source-map",
5-
entry: "./src/index.js",
4+
devtool: 'source-map',
5+
entry: './src/index.js',
66
output: {
7-
filename: "react-csv-reader.js",
8-
path: path.resolve(__dirname, "dist"),
9-
library: "CSVReader",
10-
libraryTarget: "commonjs2"
7+
filename: 'react-csv-reader.js',
8+
path: path.resolve(__dirname, 'dist'),
9+
library: 'CSVReader',
10+
libraryTarget: 'commonjs2'
1111
},
1212
module: {
1313
rules: [
1414
{
1515
test: /\.js$/,
1616
exclude: /node_modules/,
17-
loader: "babel-loader"
17+
loader: 'babel-loader'
1818
}
1919
]
2020
},
2121
externals: {
2222
react: {
23-
commonjs: "react",
24-
commonjs2: "react",
25-
amd: "react",
26-
root: "React"
23+
commonjs: 'react',
24+
commonjs2: 'react',
25+
amd: 'react',
26+
root: 'React'
2727
},
28-
"prop-types": {
29-
commonjs: "prop-types",
30-
commonjs2: "prop-types",
31-
amd: "prop-types",
32-
root: "PropTypes"
28+
'prop-types': {
29+
commonjs: 'prop-types',
30+
commonjs2: 'prop-types',
31+
amd: 'prop-types',
32+
root: 'PropTypes'
3333
}
3434
}
35-
}
35+
};

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,10 @@ pako@~1.0.5:
19071907
version "1.0.6"
19081908
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.6.tgz#0101211baa70c4bca4a0f63f2206e97b7dfaf258"
19091909

1910+
papaparse@^4.3.6:
1911+
version "4.3.6"
1912+
resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-4.3.6.tgz#9566eda0ecab13afcb740a62381c699f486cb145"
1913+
19101914
parse-asn1@^5.0.0:
19111915
version "5.1.0"
19121916
resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.0.tgz#37c4f9b7ed3ab65c74817b5f2480937fbf97c712"

0 commit comments

Comments
 (0)