Skip to content

Commit 8a31003

Browse files
committed
docs(SortableColumn): make the sortable prop to SortableColumn more discoverable
1 parent 25803bc commit 8a31003

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/components/Table/SortableTable.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface SortableColumn<T> extends Omit<HeaderProps, 'children' | 'onSor
1111
header?: React.ReactNode;
1212
key: string;
1313
onSort?: (ascending: boolean) => void;
14+
sortable?: boolean;
1415
width?: string;
1516
}
1617

src/components/Table/SortableTable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class SortableTable extends React.Component {
118118
header: PropTypes.node,
119119
key: PropTypes.string,
120120
onSort: PropTypes.func,
121+
sortable: PropTypes.bool,
121122
width: PropTypes.string,
122123
})
123124
).isRequired,

src/components/Table/SortableTable.stories.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const SortableTableExample = ({ column, ascending, ...args }) => (
111111
key: 'first',
112112
cell: (row) => row.first,
113113
onSort: action('onSort-First'),
114+
sortable: true,
114115
width: '20%',
115116
},
116117
{
@@ -120,6 +121,7 @@ export const SortableTableExample = ({ column, ascending, ...args }) => (
120121
key: 'last',
121122
cell: (row) => row.last,
122123
onSort: action('onSort-Last'),
124+
sortable: true,
123125
width: '30%',
124126
},
125127
{
@@ -129,6 +131,7 @@ export const SortableTableExample = ({ column, ascending, ...args }) => (
129131
key: 'dob',
130132
cell: (row) => fecha.format(row.dob, 'MM/DD/YYYY'),
131133
onSort: action('onSort-DOB'),
134+
sortable: true,
132135
width: '15%',
133136
},
134137
{
@@ -138,6 +141,7 @@ export const SortableTableExample = ({ column, ascending, ...args }) => (
138141
key: 'email',
139142
cell: EmailCell,
140143
onSort: action('onSort-Email'),
144+
sortable: true,
141145
width: '35%',
142146
},
143147
]}

src/components/Table/UncontrolledTable.stories.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const DATA = [
1212
last: 'Jones',
1313
email: 'rufus.xavier.sarsparilla@example.com',
1414
dob: new Date(1968, 6, 15),
15+
estimatedAge: '25-37',
1516
},
1617
{
1718
key: '222',
@@ -20,6 +21,7 @@ const DATA = [
2021
last: 'Thomas',
2122
email: 'albert.andreas.armadillo@example.com',
2223
dob: new Date(1972, 7, 17),
24+
estimatedAge: '29-80',
2325
},
2426
{
2527
key: '333',
@@ -28,6 +30,7 @@ const DATA = [
2830
last: 'Douglas',
2931
email: 'arron.douglas@example.com',
3032
dob: new Date(1982, 4, 1),
33+
estimatedAge: '31-85',
3134
},
3235
{
3336
key: '444',
@@ -36,6 +39,7 @@ const DATA = [
3639
last: 'Rhodes',
3740
email: 'reginald.rhodes@example.com',
3841
dob: new Date(1968, 8, 14),
42+
estimatedAge: '40-69',
3943
},
4044
{
4145
key: '555',
@@ -44,6 +48,7 @@ const DATA = [
4448
last: 'Mendoza',
4549
email: 'jimmy.mendoza@example.com',
4650
dob: new Date(1964, 1, 1),
51+
estimatedAge: '45-91',
4752
},
4853
{
4954
key: '666',
@@ -52,6 +57,7 @@ const DATA = [
5257
last: 'Montgomery',
5358
email: 'georgia.montgomery@example.com',
5459
dob: new Date(1960, 6, 4),
60+
estimatedAge: '50-99',
5561
},
5662
{
5763
key: '777',
@@ -60,6 +66,7 @@ const DATA = [
6066
last: 'Thomas',
6167
email: 'serenity.thomas@example.com',
6268
dob: new Date(1973, 0, 11),
69+
estimatedAge: '1-47',
6370
},
6471
{
6572
key: '888',
@@ -68,6 +75,7 @@ const DATA = [
6875
last: 'Elliott',
6976
email: 'tonya.elliott@example.com',
7077
dob: new Date(1954, 7, 17),
78+
estimatedAge: '2-16',
7179
},
7280
{
7381
key: '999',
@@ -77,6 +85,7 @@ const DATA = [
7785
email: 'maxine.turner@example.com',
7886
dob: new Date(1961, 8, 19),
7987
disabled: true,
88+
estimatedAge: '4-88',
8089
},
8190
{
8291
key: '000',
@@ -86,6 +95,7 @@ const DATA = [
8695
email: 'max.headroom@example.com',
8796
dob: new Date(1984, 6, 1),
8897
disabled: true,
98+
estimatedAge: '70-72',
8999
},
90100
];
91101

@@ -309,3 +319,41 @@ export const CustomExpandColumn = (args) => (
309319
/>
310320
</div>
311321
);
322+
323+
export const UnsortableColumn = (args) => (
324+
<div>
325+
<UncontrolledTable
326+
columns={[
327+
{
328+
header: 'First',
329+
key: 'first',
330+
cell: (row) => row.first,
331+
width: '20%',
332+
},
333+
{
334+
header: 'Last',
335+
key: 'last',
336+
cell: (row) => row.last,
337+
width: '30%',
338+
},
339+
{
340+
header: 'Estimated Age',
341+
key: 'estimatedAge',
342+
cell: (row) => row.estimatedAge,
343+
width: '15%',
344+
sortable: false,
345+
},
346+
{
347+
header: 'Email',
348+
key: 'email',
349+
cell: EmailCell,
350+
width: '35%',
351+
},
352+
]}
353+
rows={DATA}
354+
rowExpanded={FullName}
355+
sort={{ column: 'last', ascending: true }}
356+
{...args}
357+
/>
358+
</div>
359+
);

0 commit comments

Comments
 (0)