Skip to content

Commit

Permalink
Merge pull request #131 from heetch/table-initial-state
Browse files Browse the repository at this point in the history
Allow initial state to be passed to Table
  • Loading branch information
tamarasaurus authored Apr 16, 2020
2 parents 9b07740 + 1166370 commit 2bfc42c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 19 additions & 1 deletion packages/react/src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import RowCell from '../TableRowCell';

const Table = React.forwardRef(
(
{ className, columns, data, isSortable, manualSorting, onChangeSort },
{
className,
columns,
data,
isSortable,
manualSorting,
onChangeSort,
initialState,
},
ref,
) => {
const {
Expand All @@ -23,6 +31,7 @@ const Table = React.forwardRef(
columns,
data,
manualSorting,
initialState,
},
useSortBy,
);
Expand Down Expand Up @@ -99,6 +108,14 @@ Table.propTypes = {
isSortable: PropTypes.bool,
manualSorting: PropTypes.bool,
onChangeSort: PropTypes.func,
initialState: PropTypes.shape({
sortBy: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
desc: PropTypes.bool,
}),
),
}),
};

Table.defaultProps = {
Expand All @@ -108,6 +125,7 @@ Table.defaultProps = {
isSortable: false,
onChangeSort: () => {},
manualSorting: false,
initialState: undefined,
};

Table.HeaderGroup = HeaderGroup;
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/components/Table/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ stories.add('Playground', () => (
},
]}
data={data}
isSortable={boolean('Is sortable', false)}
isSortable={boolean('Table 1 sortable', false)}
/>

<Heading>Table with manual sorting</Heading>
Expand All @@ -59,9 +59,10 @@ stories.add('Playground', () => (
},
]}
data={data}
isSortable={boolean('Is sortable', false)}
isSortable={boolean('Table 2 sortable', true)}
manualSorting
onChangeSort={action('onChangeSort')}
initialState={{ sortBy: [{ id: 'number', desc: true }] }}
/>
</>
));

1 comment on commit 2bfc42c

@vercel
Copy link

@vercel vercel bot commented on 2bfc42c Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.