Skip to content

Commit b029265

Browse files
Pass sorting icons to Table through props (#13)
1 parent 99be881 commit b029265

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

demo/generated/demo.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/demo/pages/DemoContainer.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,13 +1619,15 @@ class DemoContainer extends React.Component {
16191619
},
16201620
]}
16211621
sort={{
1622+
ascendingIcon: <Icon icon="arrow_upward" />,
16221623
changeHandler: (column, direction) => {
16231624
this.setState({
16241625
tableSortColumn: column,
16251626
tableSortDirection: direction === 'asc' ? 'desc' : 'asc',
16261627
});
16271628
},
16281629
column: this.state.tableSortColumn,
1630+
descendingIcon: <Icon icon="arrow_downward" />,
16291631
direction: this.state.tableSortDirection,
16301632
}}
16311633
/>

src/lib/components/ui/Table/Table.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class Table extends React.Component {
3232
<div className={styles.sortButton}>
3333
<Button
3434
clickHandler={() => sort.changeHandler(column.name, sortDirection)}
35-
icon={sortDirection === 'asc' ? 'arrow_upward' : 'arrow_downward'}
35+
beforeLabel={
36+
sortDirection === 'asc'
37+
? sort.ascendingIcon
38+
: sort.descendingIcon
39+
}
3640
label={sortDirection}
3741
labelVisibility="none"
3842
priority="flat"
@@ -126,8 +130,10 @@ Table.propTypes = {
126130
]).isRequired,
127131
})).isRequired,
128132
sort: PropTypes.shape({
133+
ascendingIcon: PropTypes.element.isRequired,
129134
changeHandler: PropTypes.func.isRequired,
130135
column: PropTypes.string.isRequired,
136+
descendingIcon: PropTypes.element.isRequired,
131137
direction: PropTypes.oneOf(['asc', 'desc']).isRequired,
132138
}),
133139
};

src/lib/components/ui/Table/__tests__/Table.test.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
shallow,
66
} from 'enzyme';
77
import { shallowToJson } from 'enzyme-to-json';
8+
import Icon from '../../Icon';
89
import Table from '../Table';
910

1011
jest.mock('../../Icon/load-material-design-icons');
@@ -51,8 +52,10 @@ describe('rendering', () => {
5152
id="custom-id"
5253
rows={rowsData}
5354
sort={{
55+
ascendingIcon: <Icon icon="arrow_upward" />,
5456
changeHandler: () => {},
5557
column: 'id',
58+
descendingIcon: <Icon icon="arrow_downward" />,
5659
direction: 'asc',
5760
}}
5861
/>);
@@ -69,8 +72,10 @@ describe('functionality', () => {
6972
columns={columnsData}
7073
rows={rowsData}
7174
sort={{
75+
ascendingIcon: <Icon icon="arrow_upward" />,
7276
changeHandler: spy,
7377
column: 'id',
78+
descendingIcon: <Icon icon="arrow_downward" />,
7479
direction: 'asc',
7580
}}
7681
/>

src/lib/components/ui/Table/__tests__/__snapshots__/Table.test.jsx.snap

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,17 @@ exports[`rendering renders correctly with all props 1`] = `
8282
>
8383
<Button
8484
afterLabel={null}
85-
beforeLabel={null}
85+
beforeLabel={
86+
<Icon
87+
icon="arrow_upward"
88+
size="medium"
89+
/>
90+
}
8691
block={false}
8792
clickHandler={[Function]}
8893
disabled={false}
8994
endCorner={null}
9095
grouped={false}
91-
icon="arrow_upward"
9296
id="custom-id__headerCell__id__sortButton"
9397
label="asc"
9498
labelVisibility="none"
@@ -112,13 +116,17 @@ exports[`rendering renders correctly with all props 1`] = `
112116
>
113117
<Button
114118
afterLabel={null}
115-
beforeLabel={null}
119+
beforeLabel={
120+
<Icon
121+
icon="arrow_upward"
122+
size="medium"
123+
/>
124+
}
116125
block={false}
117126
clickHandler={[Function]}
118127
disabled={false}
119128
endCorner={null}
120129
grouped={false}
121-
icon="arrow_upward"
122130
id="custom-id__headerCell__name__sortButton"
123131
label="asc"
124132
labelVisibility="none"

0 commit comments

Comments
 (0)