Skip to content

Commit

Permalink
Pass sorting icons to Table through props (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bedrich-schindler committed Feb 7, 2020
1 parent 99be881 commit b029265
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/generated/demo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/demo/pages/DemoContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1619,13 +1619,15 @@ class DemoContainer extends React.Component {
},
]}
sort={{
ascendingIcon: <Icon icon="arrow_upward" />,
changeHandler: (column, direction) => {
this.setState({
tableSortColumn: column,
tableSortDirection: direction === 'asc' ? 'desc' : 'asc',
});
},
column: this.state.tableSortColumn,
descendingIcon: <Icon icon="arrow_downward" />,
direction: this.state.tableSortDirection,
}}
/>
Expand Down
8 changes: 7 additions & 1 deletion src/lib/components/ui/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class Table extends React.Component {
<div className={styles.sortButton}>
<Button
clickHandler={() => sort.changeHandler(column.name, sortDirection)}
icon={sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'}
beforeLabel={
sortDirection === 'asc'
? sort.ascendingIcon
: sort.descendingIcon
}
label={sortDirection}
labelVisibility="none"
priority="flat"
Expand Down Expand Up @@ -126,8 +130,10 @@ Table.propTypes = {
]).isRequired,
})).isRequired,
sort: PropTypes.shape({
ascendingIcon: PropTypes.element.isRequired,
changeHandler: PropTypes.func.isRequired,
column: PropTypes.string.isRequired,
descendingIcon: PropTypes.element.isRequired,
direction: PropTypes.oneOf(['asc', 'desc']).isRequired,
}),
};
Expand Down
5 changes: 5 additions & 0 deletions src/lib/components/ui/Table/__tests__/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
shallow,
} from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';
import Icon from '../../Icon';
import Table from '../Table';

jest.mock('../../Icon/load-material-design-icons');
Expand Down Expand Up @@ -51,8 +52,10 @@ describe('rendering', () => {
id="custom-id"
rows={rowsData}
sort={{
ascendingIcon: <Icon icon="arrow_upward" />,
changeHandler: () => {},
column: 'id',
descendingIcon: <Icon icon="arrow_downward" />,
direction: 'asc',
}}
/>);
Expand All @@ -69,8 +72,10 @@ describe('functionality', () => {
columns={columnsData}
rows={rowsData}
sort={{
ascendingIcon: <Icon icon="arrow_upward" />,
changeHandler: spy,
column: 'id',
descendingIcon: <Icon icon="arrow_downward" />,
direction: 'asc',
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ exports[`rendering renders correctly with all props 1`] = `
>
<Button
afterLabel={null}
beforeLabel={null}
beforeLabel={
<Icon
icon="arrow_upward"
size="medium"
/>
}
block={false}
clickHandler={[Function]}
disabled={false}
endCorner={null}
grouped={false}
icon="arrow_upward"
id="custom-id__headerCell__id__sortButton"
label="asc"
labelVisibility="none"
Expand All @@ -112,13 +116,17 @@ exports[`rendering renders correctly with all props 1`] = `
>
<Button
afterLabel={null}
beforeLabel={null}
beforeLabel={
<Icon
icon="arrow_upward"
size="medium"
/>
}
block={false}
clickHandler={[Function]}
disabled={false}
endCorner={null}
grouped={false}
icon="arrow_upward"
id="custom-id__headerCell__name__sortButton"
label="asc"
labelVisibility="none"
Expand Down

0 comments on commit b029265

Please sign in to comment.