Skip to content

Commit 4af4058

Browse files
authored
documenation pass 7 (#892)
1 parent 1adf531 commit 4af4058

27 files changed

+1098
-822
lines changed

.storybook/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const parameters = {
66
options: {
77
storySort: {
88
method: 'alphabetical',
9-
order: ['Getting Started', ['Introduction', 'Installation', 'Basic Examples', 'Kitchen Sink', 'Code of Conduct', 'Features & Issues', '*'], 'API', ['Columns', 'Properties'], 'Columns', 'Sorting', 'Selectable', 'Expandable', 'Pagination', 'Headers', 'Loading', '*', 'Performance', ['Optimization', '*'], 'Contributing'],
9+
order: ['Getting Started', ['Introduction', 'Installation', 'Basic Examples', 'Kitchen Sink', 'Code of Conduct', 'Features & Issues', '*'], 'API Reference', ['Columns', 'Properties'], 'Columns', 'Sorting', 'Selectable', 'Expandable', 'Pagination', 'Headers', 'Loading', '*', 'Performance', ['Optimization', '*'], 'Contributing'],
1010
},
1111
},
1212
a11y: {

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
[![Netlify Status](https://api.netlify.com/api/v1/badges/26e0d16d-a986-46b1-9097-1a76c10d7cad/deploy-status)](https://app.netlify.com/sites/react-data-table-component/deploys) [![npm version](https://badge.fury.io/js/react-data-table-component.svg)](https://badge.fury.io/js/react-data-table-component) [![codecov](https://codecov.io/gh/jbetancur/react-data-table-component/branch/master/graph/badge.svg)](https://codecov.io/gh/jbetancur/react-data-table-component)
2-
1+
[![Netlify Status](https://api.netlify.com/api/v1/badges/26e0d16d-a986-46b1-9097-1a76c10d7cad/deploy-status)](https://app.netlify.com/sites/react-data-table-component/deploys) [![npm version](https://badge.fury.io/js/react-data-table-component.svg)](https://badge.fury.io/js/react-data-table-component) [![codecov](https://codecov.io/gh/jbetancur/react-data-table-component/branch/master/graph/badge.svg)](https://codecov.io/gh/jbetancur/react-data-table-component) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
32

43
# React Data Table Component
54

package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-data-table-component",
3-
"version": "7.0.0-rc7",
4-
"description": "A declarative react based data table",
3+
"version": "7.0.0",
4+
"description": "A simple to use declarative react based data table",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.es.js",
77
"browser": "dist/index.cjs.js",
@@ -42,24 +42,24 @@
4242
"devDependencies": {
4343
"@material-ui/core": "^4.12.3",
4444
"@material-ui/icons": "^4.11.2",
45-
"@storybook/addon-a11y": "^6.3.7",
46-
"@storybook/addon-essentials": "^6.3.7",
47-
"@storybook/addon-storysource": "^6.3.7",
48-
"@storybook/addons": "^6.3.7",
49-
"@storybook/react": "^6.3.7",
50-
"@storybook/theming": "^6.3.7",
45+
"@storybook/addon-a11y": "^6.3.8",
46+
"@storybook/addon-essentials": "^6.3.8",
47+
"@storybook/addon-storysource": "^6.3.8",
48+
"@storybook/addons": "^6.3.8",
49+
"@storybook/react": "^6.3.8",
50+
"@storybook/theming": "^6.3.8",
5151
"@testing-library/react": "^12.0.0",
5252
"@types/faker": "^5.5.8",
5353
"@types/jest": "^27.0.1",
5454
"@types/lodash-es": "^4.17.4",
5555
"@types/lodash.orderby": "^4.6.6",
56-
"@types/node": "^16.7.2",
57-
"@types/react": "^17.0.19",
56+
"@types/node": "^16.7.10",
57+
"@types/react": "^17.0.20",
5858
"@types/react-dom": "^17.0.9",
59-
"@types/styled-components": "^5.1.13",
60-
"@typescript-eslint/eslint-plugin": "^4.29.3",
61-
"@typescript-eslint/parser": "^4.29.3",
62-
"axios": "^0.21.1",
59+
"@types/styled-components": "^5.1.14",
60+
"@typescript-eslint/eslint-plugin": "^4.30.0",
61+
"@typescript-eslint/parser": "^4.30.0",
62+
"axios": "^0.21.3",
6363
"babel-eslint": "^10.1.0",
6464
"codecov": "^3.8.3",
6565
"eslint": "^7.32.0",
@@ -68,12 +68,12 @@
6868
"eslint-plugin-import": "^2.24.2",
6969
"eslint-plugin-jest": "^24.4.0",
7070
"eslint-plugin-jsx-a11y": "^6.4.1",
71-
"eslint-plugin-prettier": "^3.4.1",
72-
"eslint-plugin-react": "^7.24.0",
71+
"eslint-plugin-prettier": "^4.0.0",
72+
"eslint-plugin-react": "^7.25.1",
7373
"eslint-plugin-react-hooks": "^4.2.0",
7474
"faker": "^5.5.3",
7575
"gh-pages": "^3.2.3",
76-
"jest": "^27.0.6",
76+
"jest": "^27.1.0",
7777
"jest-styled-components": "^7.0.5",
7878
"jest-watch-typeahead": "^0.6.4",
7979
"lodash-es": "^4.17.21",
@@ -96,14 +96,14 @@
9696
"stylelint-config-styled-components": "^0.1.1",
9797
"stylelint-processor-styled-components": "^1.10.0",
9898
"ts-jest": "^27.0.5",
99-
"typescript": "^4.3.5"
99+
"typescript": "^4.4.2"
100100
},
101101
"dependencies": {
102102
"deepmerge": "^4.2.2",
103103
"lodash.orderby": "^4.6.0"
104104
},
105105
"peerDependencies": {
106-
"react": "^17.0.2",
107-
"styled-components": "^5.3.1"
106+
"react": ">= 16.8.3",
107+
"styled-components": ">= 4"
108108
}
109109
}

src/DataTable/TableColCheckbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function TableColCheckbox<T>({
4040
const indeterminate = selectedRows.length > 0 && !allSelected;
4141
const rows = selectableRowDisabled ? rowData.filter((row: T) => !selectableRowDisabled(row)) : rowData;
4242
const isDisabled = rows.length === 0;
43-
// The row count should subtrtact rows that are disabled
43+
// The row count should subtract rows that are disabled
4444
const rowCount = Math.min(rowData.length, rows.length);
4545

4646
const handleSelectAll = () => {

stories/DataTable/ThemeDark.stories.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ const Template = args => <BuiltinStory {...args} />;
3939
export const Builtin = Template.bind({});
4040

4141
Builtin.args = {
42-
theme: 'light',
42+
theme: 'default',
4343
};
4444

4545
export default {
4646
title: 'Theming/Builtin',
4747
component: Builtin,
4848
argTypes: {
4949
theme: {
50-
options: ['light', 'dark'],
50+
options: ['default', 'dark'],
5151
control: { type: 'radio' },
5252
description: 'toggle between light and dark themes',
5353
table: {
5454
type: { summary: 'string' },
55-
defaultValue: { summary: 'Hello' },
55+
defaultValue: { summary: 'default' },
5656
},
5757
},
5858
},
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Story, Canvas } from '@storybook/addon-docs';
2+
3+
# Pagination
4+
5+
Adding client side pagination functionality is easy:
6+
7+
```js
8+
function MyComponent() {
9+
return (
10+
<DataTable
11+
columns={columns}
12+
data={data}
13+
pagination
14+
/>
15+
);
16+
};
17+
```
18+
19+
<Canvas>
20+
<Story id="pagination-basic--basic" />
21+
</Canvas>
22+

stories/DataTable/Pagination.stories.js renamed to stories/DataTable/pagination/basic.stories.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import data from '../constants/sampleMovieData';
3-
import DataTable from '../../src/index';
2+
import doc from './basic.mdx';
3+
import data from '../../constants/sampleMovieData';
4+
import DataTable from '../../../src/index';
45

56
const columns = [
67
{
@@ -25,4 +26,9 @@ export const Basic = () => <DataTable title="Movie List" columns={columns} data=
2526
export default {
2627
title: 'Pagination/Basic',
2728
component: Basic,
29+
parameters: {
30+
docs: {
31+
page: doc,
32+
},
33+
},
2834
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Story, Canvas } from '@storybook/addon-docs';
2+
3+
# Pagination Component Options
4+
5+
`paginationComponentOptions`allow you to provide options to the built-in in Pagination component.
6+
7+
| Property | Type | Description |
8+
| --------------------- | ------- | ----------------------------------------------------- |
9+
| noRowsPerPage | boolean | hide the rows per page dropdown |
10+
| rowsPerPageText | string | chan ge the page per fors text |
11+
| rangeSeparatorText | string | change the seperator text e.g. 1 - 10 'of' 100 rows |
12+
| selectAllRowsItem | boolean | show 'All' as an option in the rows per page dropdown |
13+
| selectAllRowsItemText | string | change the rows per page text |
14+
15+
```js
16+
const paginationComponentOptions = {
17+
rowsPerPageText: 'Filas por página',
18+
rangeSeparatorText: 'de',
19+
selectAllRowsItem: true,
20+
selectAllRowsItemText: 'Todos',
21+
};
22+
23+
function MyComponent() {
24+
return <DataTable columns={columns} data={data} pagination paginationComponentOptions={paginationComponentOptions} />;
25+
}
26+
```
27+
28+
## Custom Pagination Component `paginationComponentOptions`
29+
30+
When using `paginationComponent` the `paginationComponentOptions` above become irrelevent. Instead, `paginationComponentOptions` can be used to pass whatever options you need to your custom Pagination component
31+
32+
<Canvas>
33+
<Story id="pagination-options--options" />
34+
</Canvas>

stories/DataTable/PaginationOptions.stories.js renamed to stories/DataTable/pagination/options.stories.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import data from '../constants/sampleMovieData';
3-
import DataTable from '../../src/index';
2+
import doc from './options.mdx';
3+
import data from '../../constants/sampleMovieData';
4+
import DataTable from '../../../src/index';
45

56
const columns = [
67
{
@@ -20,7 +21,7 @@ const columns = [
2021
},
2122
];
2223

23-
const paginationOptions = {
24+
const paginationComponentOptions = {
2425
rowsPerPageText: 'Filas por página',
2526
rangeSeparatorText: 'de',
2627
selectAllRowsItem: true,
@@ -33,11 +34,16 @@ export const Options = () => (
3334
columns={columns}
3435
data={data}
3536
pagination
36-
paginationComponentOptions={paginationOptions}
37+
paginationComponentOptions={paginationComponentOptions}
3738
/>
3839
);
3940

4041
export default {
4142
title: 'Pagination/Options',
4243
component: Options,
44+
parameters: {
45+
docs: {
46+
page: doc,
47+
},
48+
},
4349
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Story, Canvas } from '@storybook/addon-docs';
2+
3+
# Remote Pagination
4+
5+
To enable remote/manual pagination you'll need to add the `paginationServer` property and ensure the remote API you are using supports pagination metadata.
6+
7+
You'll also need to implement the `onChangeRowsPerPage`, and `onChangePage` callbacks.
8+
9+
Finally, you'll need to keep track of your total rows using `paginationTotalRows`. This should be obtained from the remote API you are calling from to get the pagnination records.
10+
11+
The following example covers a working example of remote pagniation:
12+
13+
<Canvas>
14+
<Story id="pagination-remote--remote" />
15+
</Canvas>

stories/DataTable/PaginationRemote.stories.js renamed to stories/DataTable/pagination/remote.stories.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
2+
import doc from './remote.mdx';
23
import axios from 'axios';
3-
import DataTable from '../../src/index';
4+
import DataTable from '../../../src/index';
45

56
const columns = [
67
{
@@ -20,7 +21,7 @@ const columns = [
2021
},
2122
];
2223

23-
export const Remote = () => {
24+
export function Remote() {
2425
const [data, setData] = useState([]);
2526
const [loading, setLoading] = useState(false);
2627
const [totalRows, setTotalRows] = useState(0);
@@ -51,7 +52,7 @@ export const Remote = () => {
5152
};
5253

5354
useEffect(() => {
54-
fetchUsers(1);
55+
fetchUsers(1); // fetch page 1 of users
5556
// eslint-disable-next-line react-hooks/exhaustive-deps
5657
}, []);
5758

@@ -64,14 +65,18 @@ export const Remote = () => {
6465
pagination
6566
paginationServer
6667
paginationTotalRows={totalRows}
67-
selectableRows
6868
onChangeRowsPerPage={handlePerRowsChange}
6969
onChangePage={handlePageChange}
7070
/>
7171
);
72-
};
72+
}
7373

7474
export default {
7575
title: 'Pagination/Remote',
7676
component: Remote,
77+
parameters: {
78+
docs: {
79+
page: doc,
80+
},
81+
},
7782
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Story, Canvas } from '@storybook/addon-docs';
2+
3+
# Custom Sorting Individual Columns - sortFunction
4+
5+
If you only need to override the sorting behavior for a specific column(s). In this case, the custom sorting function takes only provides you access to two arguments, rowA and rowB.
6+
7+
```js
8+
const customColumnSort = (rowA, rowB) => {
9+
if (rowA.columnName > rowB.columnName) {
10+
return 1;
11+
} else if (rowB.columnName > rowA.columnName) {
12+
return -1;
13+
}
14+
return 0;
15+
};
16+
17+
const columns = [
18+
{
19+
name: 'Quantity',
20+
selector: 'quantity',
21+
sortable: true,
22+
sortFunction: customColumnSort
23+
}
24+
];
25+
26+
...
27+
<DataTable ... columns={columns} />
28+
```
29+
30+
<Canvas>
31+
<Story id="sorting-custom-column-sort--custom-column-sort" />
32+
</Canvas>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import doc from './sortFunctionCol.mdx';
3+
import data from '../../constants/sampleMovieData';
4+
import DataTable from '../../../src/index';
5+
6+
const caseInsensitiveSort = (rowA, rowB) => {
7+
const a = rowA.title.toLowerCase();
8+
const b = rowB.title.toLowerCase();
9+
10+
if (a > b) {
11+
return 1;
12+
} else if (b > a) {
13+
return -1;
14+
}
15+
return 0;
16+
};
17+
18+
const columns = [
19+
{
20+
name: 'Title',
21+
selector: row => row.title,
22+
sortable: true,
23+
sortFunction: caseInsensitiveSort,
24+
},
25+
{
26+
name: 'Director',
27+
selector: row => row.director,
28+
sortable: true,
29+
},
30+
{
31+
name: 'Year',
32+
selector: row => row.year,
33+
sortable: true,
34+
},
35+
];
36+
37+
export const CustomColumnSort = () => {
38+
return <DataTable title="Movie List" columns={columns} data={data} pagination />;
39+
};
40+
41+
export default {
42+
title: 'Sorting/Custom Column Sort',
43+
component: CustomColumnSort,
44+
parameters: {
45+
docs: {
46+
page: doc,
47+
},
48+
},
49+
};

stories/columns.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Meta } from '@storybook/addon-docs';
22

3-
<Meta title="API/Columns" id="api-columns" />
3+
<Meta title="API Reference/Columns" id="api-columns" />
44

55
# Column Definitions API
66

0 commit comments

Comments
 (0)