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

feat: Table toolbar v10 #2247

Merged
merged 26 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c09a29c
chore: update carbon-components for storybook
vpicone Apr 16, 2019
3b310d8
feat: add initial toolbar updates
vpicone Apr 19, 2019
a16920c
fix: default props
vpicone Apr 19, 2019
601f0a8
test: update snapshots
vpicone Apr 19, 2019
ae6546d
test: update tests
vpicone Apr 19, 2019
cbf99b7
test: fix tests
vpicone Apr 20, 2019
df736be
test: update snapshots
vpicone Apr 20, 2019
31a7d37
Merge branch 'master' of github.com:IBM/carbon-components-react into …
vpicone Apr 21, 2019
646725e
chore: update peer deps
vpicone Apr 21, 2019
e5dd056
feat: add new modifiers, update stories, add knobs
vpicone Apr 22, 2019
2e09e84
test: update snapshots
vpicone Apr 22, 2019
5538a81
test: update snapshots
vpicone Apr 22, 2019
acbea1f
fix: update proptypes and use cx lib
vpicone Apr 22, 2019
58008bb
Merge branch 'master' into table-toolbar-v10
vpicone Apr 22, 2019
94965fb
test: update snapshots
vpicone Apr 22, 2019
0402d03
Merge branch 'master' of github.com:IBM/carbon-components-react into …
vpicone Apr 22, 2019
f0af336
Merge branch 'table-toolbar-v10' of https://github.com/vpicone/carbon…
vpicone Apr 22, 2019
b265526
fix: add sortable prop and update snaps
vpicone Apr 22, 2019
da936e2
chore: refine story responsibilities
vpicone Apr 22, 2019
6d085aa
fix: add a11y updates
vpicone Apr 22, 2019
440f6ec
test: fix tests
vpicone Apr 22, 2019
25e9701
Merge branch 'master' into table-toolbar-v10
vpicone Apr 22, 2019
a1140c1
Update src/components/DataTable/TableToolbar.js
dakahn Apr 23, 2019
5d9f7ae
Merge branch 'master' into table-toolbar-v10
vpicone Apr 23, 2019
5b24766
fix: remove tab index
vpicone Apr 23, 2019
7fc03fa
test: update snapshots
vpicone Apr 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { configure, addDecorator } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import { withOptions } from '@storybook/addon-options';
import { configureActions } from '@storybook/addon-actions';
import { initializeRTL } from 'storybook-addon-rtl';
// import { checkA11y } from 'storybook-addon-a11y';
import Container from './Container';
Expand All @@ -19,6 +20,11 @@ addDecorator(
})
);

configureActions({
depth: 100,
limit: 20,
});

addDecorator(story => <Container story={story} />);
// addDecorator(checkA11y);

Expand Down
2 changes: 2 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use overflow menu for settings
toolbar actions become overflow menu items
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
}
},
"peerDependencies": {
"carbon-components": "^10.0.0",
"carbon-components": "^10.1.0",
"carbon-icons": "^7.0.7",
"react": "^16.8.6",
"react-dom": "^16.8.6"
Expand Down
117 changes: 69 additions & 48 deletions src/components/DataTable/DataTable-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
*/

import { storiesOf } from '@storybook/react';
import { withKnobs, boolean } from '@storybook/addon-knobs';
import { withKnobs, boolean, select } from '@storybook/addon-knobs';
import { withReadme } from 'storybook-readme';
import readme from './README.md';

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

const props = () => ({
short: boolean('Short variant (short)', false),
shouldShowBorder: boolean('Table Border variant (shouldShowBorder)', true),
useZebraStyles: boolean('Zebra row styles (useZebraStyles)', false),
size: select(
'Row height (size)',
{ compact: 'compact', short: 'short', tall: 'tall', none: null },
null
),
});

storiesOf('DataTable', module)
Expand All @@ -39,118 +43,135 @@ storiesOf('DataTable', module)
)
.add(
'with toolbar',
withReadme(readme, require('./stories/with-toolbar').default),
withReadme(readme, () =>
require('./stories/with-toolbar').default(props())
),
{
info: {
text: `
DataTable with toolbar and filtering.
DataTable with action menu and filtering.

You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
},
}
)
.add(
'with sorting',
withReadme(readme, require('./stories/with-sorting').default),
withReadme(readme, () =>
require('./stories/with-sorting').default(props())
),
{
info: {
text: `
DataTable with sorting
DataTable with sorting

You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
},
}
)
.add(
'with selection',
withReadme(readme, require('./stories/with-selection').default),
withReadme(readme, () =>
require('./stories/with-selection').default(props())
),
{
info: {
text: `
DataTable with selection
DataTable with selection

You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
},
}
)

.add(
'with radio button selection',
withReadme(readme, require('./stories/with-selection--radio').default),
withReadme(readme, () =>
require('./stories/with-selection--radio').default(props())
),
{
info: {
text: `
DataTable with radio button selection
DataTable with radio button selection

You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
},
}
)
.add(
'with expansion',
withReadme(readme, require('./stories/with-expansion').default),
withReadme(readme, () =>
require('./stories/with-expansion').default(props())
),
{
info: {
text: `
DataTable with expansion
DataTable with expansion

You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
},
}
)
.add(
'with batch actions',
withReadme(readme, require('./stories/with-batch-actions').default),
withReadme(readme, () =>
require('./stories/with-batch-actions').default(props())
),
{
info: {
text: `
Uses <TableToolbar> alongside <TableBatchActions> and <TableBatchAction>
to create the toolbar and placeholder for where the batch action menu will
be displayed.
Uses <TableToolbar> alongside <TableBatchActions> and <TableBatchAction>
to create the toolbar and placeholder for where the batch action menu will
be displayed.

You can use the \`getBatchActionProps\` prop getter on the
<TableBatchActions> component to have it wire up the ghost menu for you.
You can use the \`getBatchActionProps\` prop getter on the
<TableBatchActions> component to have it wire up the ghost menu for you.

Individual <TableBatchAction> components take in any kind of event handler
prop that you would expect to use, like \`onClick\`. You can use these
alongside the \`selectedRows\` property in your \`render\` prop function
to pass along this info to your batch action handler.
Individual <TableBatchAction> components take in any kind of event handler
prop that you would expect to use, like \`onClick\`. You can use these
alongside the \`selectedRows\` property in your \`render\` prop function
to pass along this info to your batch action handler.

You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
You can find more detailed information surrounding usage of this component
at the following url: ${readmeURL}
`,
},
}
)
.add(
'with dynamic content',
withReadme(readme, require('./stories/with-dynamic-content').default),
withReadme(readme, () =>
require('./stories/with-dynamic-content').default(props())
),
{
info: {
text: `
Showcases DataTable behavior when rows are added to the component,
and when cell data changes dynamically.
`,
Showcases DataTable behavior when rows are added to the component,
and when cell data changes dynamically.
`,
},
}
)
.add(
'with boolean column',
withReadme(readme, require('./stories/with-boolean-column').default),
withReadme(readme, () =>
require('./stories/with-boolean-column').default(props())
),
{
info: {
text: `
DataTable with toolbar and filtering with column has boolean value.
`,
DataTable with toolbar and filtering with column has boolean value.
`,
},
}
);
36 changes: 20 additions & 16 deletions src/components/DataTable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ export default class DataTable extends React.Component {
*/
translateWithId: PropTypes.func,

/**
* Optional boolean to create a short data table.
*/
short: PropTypes.bool,

/**
* Optional boolean to remove borders from data table.
*/
shouldShowBorder: PropTypes.bool,

/**
* Specify whether the control should be a radio button or inline checkbox
*/
Expand All @@ -119,8 +109,6 @@ export default class DataTable extends React.Component {
filterRows: defaultFilterRows,
locale: 'en',
translateWithId,
short: false,
shouldShowBorder: true,
};

static translationKeys = Object.values(translationKeys);
Expand Down Expand Up @@ -163,7 +151,12 @@ export default class DataTable extends React.Component {
* @param {Function} config.onClick a custom click handler for the header
* @returns {Object}
*/
getHeaderProps = ({ header, onClick, isSortable = true, ...rest }) => {
getHeaderProps = ({
header,
onClick,
isSortable = this.props.isSortable,
...rest
}) => {
const { sortDirection, sortHeaderKey } = this.state;
return {
...rest,
Expand Down Expand Up @@ -287,9 +280,18 @@ export default class DataTable extends React.Component {
* Helper utility to get the Table Props.
*/
getTableProps = () => {
const { short, shouldShowBorder } = this.props;
const {
useZebraStyles,
size,
isSortable,
useStaticWidth,
shouldShowBorder,
} = this.props;
return {
short,
useZebraStyles,
size,
isSortable,
useStaticWidth,
shouldShowBorder,
};
};
Expand Down Expand Up @@ -453,7 +455,9 @@ export default class DataTable extends React.Component {
* @param {Event} event
*/
handleOnInputValueChange = event => {
this.setState({ filterInputValue: event.target.value });
if (event.currentTarget) {
this.setState({ filterInputValue: event.currentTarget.value });
}
};

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/DataTable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ In practice, the combination of these components looks like the following:
<DataTable
rows={initialRows}
headers={headers}
render={({ rows, headers, getHeaderProps, getRowProps }) => (
render={({ rows, headers, getHeaderProps, getRowProps, getTableProps }) => (
<TableContainer title="DataTable with expansion">
<Table>
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{/* add the expand header before all other headers */}
Expand Down
40 changes: 22 additions & 18 deletions src/components/DataTable/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ import { settings } from 'carbon-components';
const { prefix } = settings;

export const Table = ({
zebra,
className,
children,
short,
shouldShowBorder,
useZebraStyles,
size,
isSortable,
useStaticWidth,
shouldShowBorder,
...other
}) => {
const componentClass = cx(`${prefix}--data-table`, className, {
[`${prefix}--data-table--zebra`]: zebra,
[`${prefix}--data-table--short`]: short,
[`${prefix}--data-table--compact`]: size === 'compact',
[`${prefix}--data-table--short`]: size === 'short',
[`${prefix}--data-table--tall`]: size === 'tall',
[`${prefix}--data-table--sort`]: isSortable,
[`${prefix}--data-table--zebra`]: useZebraStyles,
[`${prefix}--data-table--static`]: useStaticWidth,
[`${prefix}--data-table--no-border`]: !shouldShowBorder,
});
return (
Expand All @@ -35,36 +39,36 @@ export const Table = ({
};

Table.propTypes = {
/**
* The CSS class names.
*/
className: PropTypes.string,

/**
* `true` to add zebra striping.
* `true` to add useZebraStyles striping.
*/
zebra: PropTypes.bool,
useZebraStyles: PropTypes.bool,

/**
* `true` for short data table.
* `normal` Change the row height of table
*/
short: PropTypes.bool,
size: PropTypes.oneOf(['compact', 'small', 'normal', 'tall']),

/**
* `false` Applies styles for data tables with sorting functionality.
* `false` If true, will use a width of 'auto' instead of 100%
*/
isSortable: PropTypes.bool,
useStaticWidth: PropTypes.bool,

/**
* `true` for data table without borders.
* `false` If true, will remove the table border
*/
shouldShowBorder: PropTypes.bool,

/**
* `false` If true, will apply sorting styles
*/
isSortable: PropTypes.bool,
};

Table.defaultProps = {
zebra: true,
short: false,
shouldShowBorder: true,
isSortable: false,
};

export default Table;
Loading