Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.

Commit 01360a6

Browse files
authored
feat: Table toolbar v10 (#2247)
* chore: update carbon-components for storybook * feat: add initial toolbar updates * fix: default props * test: update snapshots * test: update tests * test: fix tests * test: update snapshots * chore: update peer deps * feat: add new modifiers, update stories, add knobs This commit adds all of the new modifiers and removes the unusued ones. All of the datatable stories have been updated to reflect new markup and to expose knobs to adjust shared modifiers. The dynamic content story was updated to use the new menu system. This also adds support for styles that have not been added yet (row size). * test: update snapshots * test: update snapshots * fix: update proptypes and use cx lib * test: update snapshots * fix: add sortable prop and update snaps * chore: refine story responsibilities This updates the stories so that they only use the feature they are showcasing. This will prevent users from bringing in DataTable features that they don't need. A "kitchen sink" data table might be useful as well. * fix: add a11y updates * test: fix tests * Update src/components/DataTable/TableToolbar.js Co-Authored-By: vpicone <vpicone@gmail.com> * fix: remove tab index Received the following linting error when attempting to define tabindex on the section component: `tabIndex` should only be declared on interactive elements.eslint(jsx-a11y/no-noninteractive-tabindex) * test: update snapshots
1 parent 953b870 commit 01360a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1640
-1687
lines changed

.storybook/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { configure, addDecorator } from '@storybook/react';
33
import { withInfo } from '@storybook/addon-info';
44
import { withOptions } from '@storybook/addon-options';
5+
import { configureActions } from '@storybook/addon-actions';
56
import { initializeRTL } from 'storybook-addon-rtl';
67
// import { checkA11y } from 'storybook-addon-a11y';
78
import Container from './Container';
@@ -19,6 +20,11 @@ addDecorator(
1920
})
2021
);
2122

23+
configureActions({
24+
depth: 100,
25+
limit: 20,
26+
});
27+
2228
addDecorator(story => <Container story={story} />);
2329
// addDecorator(checkA11y);
2430

notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use overflow menu for settings
2+
toolbar actions become overflow menu items

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
}
126126
},
127127
"peerDependencies": {
128-
"carbon-components": "^10.0.0",
128+
"carbon-components": "^10.1.0",
129129
"carbon-icons": "^7.0.7",
130130
"react": "^16.8.6",
131131
"react-dom": "^16.8.6"

src/components/DataTable/DataTable-story.js

Lines changed: 69 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
*/
77

88
import { storiesOf } from '@storybook/react';
9-
import { withKnobs, boolean } from '@storybook/addon-knobs';
9+
import { withKnobs, boolean, select } from '@storybook/addon-knobs';
1010
import { withReadme } from 'storybook-readme';
1111
import readme from './README.md';
1212

1313
const readmeURL = 'https://goo.gl/dq6CEK';
1414

1515
const props = () => ({
16-
short: boolean('Short variant (short)', false),
17-
shouldShowBorder: boolean('Table Border variant (shouldShowBorder)', true),
16+
useZebraStyles: boolean('Zebra row styles (useZebraStyles)', false),
17+
size: select(
18+
'Row height (size)',
19+
{ compact: 'compact', short: 'short', tall: 'tall', none: null },
20+
null
21+
),
1822
});
1923

2024
storiesOf('DataTable', module)
@@ -39,118 +43,135 @@ storiesOf('DataTable', module)
3943
)
4044
.add(
4145
'with toolbar',
42-
withReadme(readme, require('./stories/with-toolbar').default),
46+
withReadme(readme, () =>
47+
require('./stories/with-toolbar').default(props())
48+
),
4349
{
4450
info: {
4551
text: `
46-
DataTable with toolbar and filtering.
52+
DataTable with action menu and filtering.
4753
48-
You can find more detailed information surrounding usage of this component
49-
at the following url: ${readmeURL}
50-
`,
54+
You can find more detailed information surrounding usage of this component
55+
at the following url: ${readmeURL}
56+
`,
5157
},
5258
}
5359
)
5460
.add(
5561
'with sorting',
56-
withReadme(readme, require('./stories/with-sorting').default),
62+
withReadme(readme, () =>
63+
require('./stories/with-sorting').default(props())
64+
),
5765
{
5866
info: {
5967
text: `
60-
DataTable with sorting
68+
DataTable with sorting
6169
62-
You can find more detailed information surrounding usage of this component
63-
at the following url: ${readmeURL}
64-
`,
70+
You can find more detailed information surrounding usage of this component
71+
at the following url: ${readmeURL}
72+
`,
6573
},
6674
}
6775
)
6876
.add(
6977
'with selection',
70-
withReadme(readme, require('./stories/with-selection').default),
78+
withReadme(readme, () =>
79+
require('./stories/with-selection').default(props())
80+
),
7181
{
7282
info: {
7383
text: `
74-
DataTable with selection
84+
DataTable with selection
7585
76-
You can find more detailed information surrounding usage of this component
77-
at the following url: ${readmeURL}
78-
`,
86+
You can find more detailed information surrounding usage of this component
87+
at the following url: ${readmeURL}
88+
`,
7989
},
8090
}
8191
)
92+
8293
.add(
8394
'with radio button selection',
84-
withReadme(readme, require('./stories/with-selection--radio').default),
95+
withReadme(readme, () =>
96+
require('./stories/with-selection--radio').default(props())
97+
),
8598
{
8699
info: {
87100
text: `
88-
DataTable with radio button selection
101+
DataTable with radio button selection
89102
90-
You can find more detailed information surrounding usage of this component
91-
at the following url: ${readmeURL}
92-
`,
103+
You can find more detailed information surrounding usage of this component
104+
at the following url: ${readmeURL}
105+
`,
93106
},
94107
}
95108
)
96109
.add(
97110
'with expansion',
98-
withReadme(readme, require('./stories/with-expansion').default),
111+
withReadme(readme, () =>
112+
require('./stories/with-expansion').default(props())
113+
),
99114
{
100115
info: {
101116
text: `
102-
DataTable with expansion
117+
DataTable with expansion
103118
104-
You can find more detailed information surrounding usage of this component
105-
at the following url: ${readmeURL}
106-
`,
119+
You can find more detailed information surrounding usage of this component
120+
at the following url: ${readmeURL}
121+
`,
107122
},
108123
}
109124
)
110125
.add(
111126
'with batch actions',
112-
withReadme(readme, require('./stories/with-batch-actions').default),
127+
withReadme(readme, () =>
128+
require('./stories/with-batch-actions').default(props())
129+
),
113130
{
114131
info: {
115132
text: `
116-
Uses <TableToolbar> alongside <TableBatchActions> and <TableBatchAction>
117-
to create the toolbar and placeholder for where the batch action menu will
118-
be displayed.
133+
Uses <TableToolbar> alongside <TableBatchActions> and <TableBatchAction>
134+
to create the toolbar and placeholder for where the batch action menu will
135+
be displayed.
119136
120-
You can use the \`getBatchActionProps\` prop getter on the
121-
<TableBatchActions> component to have it wire up the ghost menu for you.
137+
You can use the \`getBatchActionProps\` prop getter on the
138+
<TableBatchActions> component to have it wire up the ghost menu for you.
122139
123-
Individual <TableBatchAction> components take in any kind of event handler
124-
prop that you would expect to use, like \`onClick\`. You can use these
125-
alongside the \`selectedRows\` property in your \`render\` prop function
126-
to pass along this info to your batch action handler.
140+
Individual <TableBatchAction> components take in any kind of event handler
141+
prop that you would expect to use, like \`onClick\`. You can use these
142+
alongside the \`selectedRows\` property in your \`render\` prop function
143+
to pass along this info to your batch action handler.
127144
128-
You can find more detailed information surrounding usage of this component
129-
at the following url: ${readmeURL}
130-
`,
145+
You can find more detailed information surrounding usage of this component
146+
at the following url: ${readmeURL}
147+
`,
131148
},
132149
}
133150
)
134151
.add(
135152
'with dynamic content',
136-
withReadme(readme, require('./stories/with-dynamic-content').default),
153+
withReadme(readme, () =>
154+
require('./stories/with-dynamic-content').default(props())
155+
),
137156
{
138157
info: {
139158
text: `
140-
Showcases DataTable behavior when rows are added to the component,
141-
and when cell data changes dynamically.
142-
`,
159+
Showcases DataTable behavior when rows are added to the component,
160+
and when cell data changes dynamically.
161+
`,
143162
},
144163
}
145164
)
146165
.add(
147166
'with boolean column',
148-
withReadme(readme, require('./stories/with-boolean-column').default),
167+
withReadme(readme, () =>
168+
require('./stories/with-boolean-column').default(props())
169+
),
149170
{
150171
info: {
151172
text: `
152-
DataTable with toolbar and filtering with column has boolean value.
153-
`,
173+
DataTable with toolbar and filtering with column has boolean value.
174+
`,
154175
},
155176
}
156177
);

src/components/DataTable/DataTable.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,6 @@ export default class DataTable extends React.Component {
9898
*/
9999
translateWithId: PropTypes.func,
100100

101-
/**
102-
* Optional boolean to create a short data table.
103-
*/
104-
short: PropTypes.bool,
105-
106-
/**
107-
* Optional boolean to remove borders from data table.
108-
*/
109-
shouldShowBorder: PropTypes.bool,
110-
111101
/**
112102
* Specify whether the control should be a radio button or inline checkbox
113103
*/
@@ -119,8 +109,6 @@ export default class DataTable extends React.Component {
119109
filterRows: defaultFilterRows,
120110
locale: 'en',
121111
translateWithId,
122-
short: false,
123-
shouldShowBorder: true,
124112
};
125113

126114
static translationKeys = Object.values(translationKeys);
@@ -163,7 +151,12 @@ export default class DataTable extends React.Component {
163151
* @param {Function} config.onClick a custom click handler for the header
164152
* @returns {Object}
165153
*/
166-
getHeaderProps = ({ header, onClick, isSortable = true, ...rest }) => {
154+
getHeaderProps = ({
155+
header,
156+
onClick,
157+
isSortable = this.props.isSortable,
158+
...rest
159+
}) => {
167160
const { sortDirection, sortHeaderKey } = this.state;
168161
return {
169162
...rest,
@@ -287,9 +280,18 @@ export default class DataTable extends React.Component {
287280
* Helper utility to get the Table Props.
288281
*/
289282
getTableProps = () => {
290-
const { short, shouldShowBorder } = this.props;
283+
const {
284+
useZebraStyles,
285+
size,
286+
isSortable,
287+
useStaticWidth,
288+
shouldShowBorder,
289+
} = this.props;
291290
return {
292-
short,
291+
useZebraStyles,
292+
size,
293+
isSortable,
294+
useStaticWidth,
293295
shouldShowBorder,
294296
};
295297
};
@@ -453,7 +455,9 @@ export default class DataTable extends React.Component {
453455
* @param {Event} event
454456
*/
455457
handleOnInputValueChange = event => {
456-
this.setState({ filterInputValue: event.target.value });
458+
if (event.currentTarget) {
459+
this.setState({ filterInputValue: event.currentTarget.value });
460+
}
457461
};
458462

459463
render() {

src/components/DataTable/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ In practice, the combination of these components looks like the following:
393393
<DataTable
394394
rows={initialRows}
395395
headers={headers}
396-
render={({ rows, headers, getHeaderProps, getRowProps }) => (
396+
render={({ rows, headers, getHeaderProps, getRowProps, getTableProps }) => (
397397
<TableContainer title="DataTable with expansion">
398-
<Table>
398+
<Table {...getTableProps()}>
399399
<TableHead>
400400
<TableRow>
401401
{/* add the expand header before all other headers */}

src/components/DataTable/Table.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ import { settings } from 'carbon-components';
1313
const { prefix } = settings;
1414

1515
export const Table = ({
16-
zebra,
1716
className,
1817
children,
19-
short,
20-
shouldShowBorder,
18+
useZebraStyles,
19+
size,
2120
isSortable,
21+
useStaticWidth,
22+
shouldShowBorder,
2223
...other
2324
}) => {
2425
const componentClass = cx(`${prefix}--data-table`, className, {
25-
[`${prefix}--data-table--zebra`]: zebra,
26-
[`${prefix}--data-table--short`]: short,
26+
[`${prefix}--data-table--compact`]: size === 'compact',
27+
[`${prefix}--data-table--short`]: size === 'short',
28+
[`${prefix}--data-table--tall`]: size === 'tall',
2729
[`${prefix}--data-table--sort`]: isSortable,
30+
[`${prefix}--data-table--zebra`]: useZebraStyles,
31+
[`${prefix}--data-table--static`]: useStaticWidth,
2832
[`${prefix}--data-table--no-border`]: !shouldShowBorder,
2933
});
3034
return (
@@ -35,36 +39,36 @@ export const Table = ({
3539
};
3640

3741
Table.propTypes = {
38-
/**
39-
* The CSS class names.
40-
*/
4142
className: PropTypes.string,
4243

4344
/**
44-
* `true` to add zebra striping.
45+
* `true` to add useZebraStyles striping.
4546
*/
46-
zebra: PropTypes.bool,
47+
useZebraStyles: PropTypes.bool,
4748

4849
/**
49-
* `true` for short data table.
50+
* `normal` Change the row height of table
5051
*/
51-
short: PropTypes.bool,
52+
size: PropTypes.oneOf(['compact', 'small', 'normal', 'tall']),
5253

5354
/**
54-
* `false` Applies styles for data tables with sorting functionality.
55+
* `false` If true, will use a width of 'auto' instead of 100%
5556
*/
56-
isSortable: PropTypes.bool,
57+
useStaticWidth: PropTypes.bool,
5758

5859
/**
59-
* `true` for data table without borders.
60+
* `false` If true, will remove the table border
6061
*/
6162
shouldShowBorder: PropTypes.bool,
63+
64+
/**
65+
* `false` If true, will apply sorting styles
66+
*/
67+
isSortable: PropTypes.bool,
6268
};
6369

6470
Table.defaultProps = {
65-
zebra: true,
66-
short: false,
67-
shouldShowBorder: true,
71+
isSortable: false,
6872
};
6973

7074
export default Table;

0 commit comments

Comments
 (0)