Skip to content

Commit a4c6aac

Browse files
authored
feat: receive custom headers (#156)
* feat: receive custom headers * chore: update naming
1 parent bf273e4 commit a4c6aac

File tree

6 files changed

+53
-32
lines changed

6 files changed

+53
-32
lines changed

docs/index.mdx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
export { Root } from './root.js'
2-
import { Head } from 'mdx-go'
3-
1+
export { Root } from "./root.js";
2+
import { Head } from "mdx-go";
43

54
# ⌗ react-json-to-csv
5+
66
A react button component to easily generate csv downloads of your json data. ✨
77

88
[![npm package version](https://badge.fury.io/js/react-json-to-csv.svg)](https://www.npmjs.com/package/react-json-to-csv) 
99
[![npm downloads](https://img.shields.io/npm/dm/react-json-to-csv)](https://www.npmjs.com/package/react-json-to-csv) 
1010
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
1111

12-
1312
<Head>
1413
<title>react-json-to-csv</title>
1514
</Head>
1615

1716
## Features
17+
1818
- Create a csv download from json data
1919
- Lightweight
2020
- Easy to use
@@ -23,24 +23,29 @@ A react button component to easily generate csv downloads of your json data. ✨
2323
## Install
2424

2525
Install with npm:
26+
2627
```sh
2728
npm i react-json-to-csv
2829
```
30+
2931
Or load from a CDN:
32+
3033
```html
3134
<script src="https://cdn.jsdelivr.net/npm/react-json-to-csv"></script>
3235
```
3336

34-
3537
## Example Usage
38+
3639
Easy, breezy, just add data.
40+
3741
```.jsx
38-
<CsvDownload data={mockData} />
42+
<CsvDownloadButton data={mockData} />
3943
```
4044

4145
Add a filename or other props.
46+
4247
```.jsx
43-
<CsvDownload
48+
<CsvDownloadButton
4449
data={mockData}
4550
filename="good_data.csv"
4651
style={{ //pass other props, like styles
@@ -59,16 +64,18 @@ Add a filename or other props.
5964
}}
6065
>
6166
Good Data ✨
62-
</CsvDownload>
67+
</CsvDownloadButton>
6368
```
6469

6570
## Props
6671

67-
| Prop | Type | Requirement | Default | Description |
68-
| --------- | --------- | ------------ | ------- | --------------------------------------------------- |
69-
| data | `object` | `required` | `null` | object or array of objects |
70-
| filename| `string` | `optional` | "export.csv" | The complete filename |
72+
| # | Property | Type | Requirement | Default | Description |
73+
| --- | --------- | ---------- | ----------- | ------------------------- | ----------------------------------------------------------------------------- |
74+
| 1 | data | `[]` | `required` | | array of objects |
75+
| 2 | filename | `string` | `optional` | "export.csv" | The filename. The `.csv` extention will be edded if not included in file name |
76+
| 3 | delimiter | `string` | `optional` | ";" | fields separator |
77+
| 4 | headers | `string[]` | `optional` | provided data object keys | List of columns that will be used in the final CSV file. |
7178

7279
## Contributing
7380

74-
Please help provide good data faster! Submit any issues and/or make a pull request!
81+
Please help provide good data faster! Submit any issues and/or make a pull request!

docs/root.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// example Root component
22
import React from 'react'
33
import { StyleProvider } from 'mdx-go'
4-
import CsvDownload from '../src/index'
4+
import CsvDownloadButton from '../src/index'
55
import mockData from './mockData.js'
66

77

88
const components = {
9-
CsvDownload,
9+
CsvDownloadButton,
1010
mockData,
1111
}
1212

@@ -35,6 +35,6 @@ export const Root = props =>(
3535
}}>
3636
{props.children}
3737
</div>
38-
38+
3939
</StyleProvider>
4040
)

readme.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# ⌗ react-json-to-csv
2+
23
A react button component to easily generate csv downloads of your json data. ✨
34

45
[![npm package version](https://badge.fury.io/js/react-json-to-csv.svg)](https://www.npmjs.com/package/react-json-to-csv)&nbsp;
56
[![npm downloads](https://img.shields.io/npm/dm/react-json-to-csv.svg)](https://www.npmjs.com/package/react-json-to-csv)&nbsp;
67
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
78

8-
## Live Demo
9+
## Live Demo
10+
911
[https://react-json-to-csv.coston.io](https://react-json-to-csv.coston.io)
1012

1113
## Features
14+
1215
- Create a csv download from json data
1316
- Lightweight
1417
- Easy to use
@@ -17,31 +20,39 @@ A react button component to easily generate csv downloads of your json data. ✨
1720
## Install
1821

1922
Install with npm:
23+
2024
```sh
2125
npm i react-json-to-csv
2226
```
27+
2328
Or load from a CDN:
29+
2430
```html
2531
<script src="https://cdn.jsdelivr.net/npm/react-json-to-csv" />
2632
```
2733
2834
## Example Usage
35+
2936
```jsx
30-
import CsvDownload from 'react-json-to-csv'
37+
import CsvDownloadButton from 'react-json-to-csv'
3138
...
3239
33-
<CsvDownload data={mockData} />
40+
<CsvDownloadButton data={mockData} />
3441
```
3542
3643
## Props
3744
38-
| Prop | Type | Requirement | Default | Description |
39-
| --------- | --------- | ------------ | ------- | --------------------------------------------------- |
40-
| data | `object` | `required` | `null` | object or array of objects |
41-
| filename| `string` | `optional` | "export.csv" | The complete filename |
45+
| # | Property | Type | Requirement | Default | Description |
46+
| --- | --------- | ---------- | ----------- | ------------------------- | ----------------------------------------------------------------------------- |
47+
| 1 | data | `[]` | `required` | | array of objects |
48+
| 2 | filename | `string` | `optional` | "export.csv" | The filename. The `.csv` extention will be edded if not included in file name |
49+
| 3 | delimiter | `string` | `optional` | ";" | fields separator |
50+
| 4 | headers | `string[]` | `optional` | provided data object keys | List of columns that will be used in the final CSV file. |
51+
52+
## Typescript Support
4253
43-
## Typescript Support
4454
Install types with npm
55+
4556
```sh
4657
npm i --save-dev @types/react-json-to-csv
4758
```

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import React from 'react'
22
import csvDownload from 'json-to-csv-export'
33

4-
const CsvDownload = (props) => {
5-
const { data, filename, delimiter, ...others } = props
4+
const CsvDownloadButton = (props) => {
5+
const { data, filename, delimiter, headers, ...others } = props
66

77
return (
8-
<button onClick={() => csvDownload({ data, filename, delimiter })} {...others}>
8+
<button
9+
onClick={() => csvDownload({ data, filename, delimiter, headers })}
10+
{...others}
11+
>
912
{props.children || 'Download Data'}
1013
</button>
1114
)
1215
}
13-
export default CsvDownload
16+
export default CsvDownloadButton

test/__snapshots__/index.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Render CsvDownload 1`] = `
3+
exports[`Render CsvDownloadButton 1`] = `
44
<button
55
onClick={[Function]}
66
>

test/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
2-
import CsvDownload from '../src/index'
2+
import CsvDownloadButton from '../src/index'
33
import renderer from 'react-test-renderer';
44

5-
test('Render CsvDownload', () => {
5+
test('Render CsvDownloadButton', () => {
66
const wrapper = shallow(
7-
<CsvDownload
7+
<CsvDownloadButton
88
data={mockData}
99
/>
1010
)

0 commit comments

Comments
 (0)