Skip to content

Commit

Permalink
updated README and added default inputId
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Mar 14, 2020
1 parent 186a423 commit 0454b99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ It handles file input and returns its content as a matrix.

You can try it out in a [demo on Codesandbox](https://codesandbox.io/s/react-csv-reader-vtull).


## Installation

Install the package with either yarn or npm.
Expand Down Expand Up @@ -88,22 +87,21 @@ ReactDOM.render(<App />, document.getElementById('root'))

### Parameters

| Name | Type | Default | Description |
| ------------- | --------------- | ------------------ | -------------------------------------------------------------------------------- |
| cssClass | string | `csv-reader-input` | A CSS class to be applied to the wrapper element. |
| cssInputClass | string | `csv-input` | A CSS class to be applied to the `<input>` element. |
| label | string, element | | If present, it will be rendered in a `<label>` to describe input aim. |
| onFileLoaded | function | | (**_required_**) The function to be called passing loaded results. |
| onError | function | | Error handling function. |
| parserOptions | object | `{}` | [PapaParse configuration](https://www.papaparse.com/docs#config) object override |
| inputId | string | | An id to be applied to the `<input>` element. |
| inputStyle | object | `{}` | Some style to be applied to the `<input>` element. |
| fileEncoding | string | `UTF-8` | Encoding type of the input file |

| Name | Type | Default | Description |
| ------------- | --------------- | ------------------------ | -------------------------------------------------------------------------------- |
| accept | striing | `.csv, text/csv` | File type accepted by file input |
| cssClass | string | `csv-reader-input` | A CSS class to be applied to the wrapper element. |
| cssInputClass | string | `csv-input` | A CSS class to be applied to the `<input>` element. |
| label | string, element | | If present, it will be rendered in a `<label>` to describe input aim. |
| onFileLoaded | function | | (**_required_**) The function to be called passing loaded results. |
| onError | function | | Error handling function. |
| parserOptions | object | `{}` | [PapaParse configuration](https://www.papaparse.com/docs#config) object override |
| inputId | string | `react-csv-reader-input` | An id to be applied to the `<input>` element. |
| inputStyle | object | `{}` | Some style to be applied to the `<input>` element. |
| fileEncoding | string | `UTF-8` | Encoding type of the input file |

### Results

When the file has been loaded, it will be parsed with [PapaParse](https://github.com/mholt/PapaParse) from a CSV formatted text to a matrix of strings or a list of objects (using `header` option).
That matrix is returned to the parent component with `onFileLoaded` function (it will be passed as an argument).
The second argument to `onFileLoaded` will be the filename provided

2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const CSVReader = ({
cssClass = 'csv-reader-input',
cssInputClass = 'csv-input',
fileEncoding = 'UTF-8',
inputId = null,
inputId = 'react-csv-reader-input',
inputStyle = {},
label,
onError,
Expand Down

0 comments on commit 0454b99

Please sign in to comment.