| 1 |
import { Table, TableHeader, TableBody, TableProps } from '@patternfly/react-table/deprecated'; |
| 2 |
import { classNames, cellWidth, Visibility } from '@patternfly/react-table'; |
| 3 |
|
| 4 |
interface Repository { |
| 5 |
name: string; |
| 6 |
branches: string; |
| 7 |
prs: string; |
| 8 |
workspaces: string; |
| 9 |
lastCommit: string; |
| 10 |
} |
| 11 |
|
| 12 |
export const LegacyTableCellWidth: React.FunctionComponent = () => { |
| 13 |
// In real usage, this data would come from some external source like an API via props. |
| 14 |
const repositories: Repository[] = [ |
| 15 |
{ |
| 16 |
name: 'one - 1', |
| 17 |
branches: 'two - 1 (visible only on md)', |
| 18 |
prs: 'three - 1 (hidden only on md)', |
| 19 |
workspaces: 'four - 1 (hidden on xs)', |
| 20 |
lastCommit: 'five - 1' |
| 21 |
}, |
| 22 |
{ |
| 23 |
name: 'one - 2', |
| 24 |
branches: 'two - 2 (visible only on md)', |
| 25 |
prs: 'three - 2 (hidden only on md)', |
| 26 |
workspaces: 'four - 2 (hidden on xs)', |
| 27 |
lastCommit: 'five - 2' |
| 28 |
} |
| 29 |
]; |
| 30 |
|
| 31 |
const columns: TableProps['cells'] = [ |
| 32 |
{ title: 'Header cell', transforms: [cellWidth(10)] }, |
| 33 |
{ |
| 34 |
title: 'Branches (visible only on md and 2Xl)', |
| 35 |
columnTransforms: [ |
| 36 |
classNames(Visibility.hidden, Visibility.visibleOnMd, Visibility.hiddenOnLg, Visibility.visibleOn2Xl) |
| 37 |
] |
| 38 |
}, |
| 39 |
{ |
| 40 |
title: 'Pull requests (hidden only on md)', |
| 41 |
columnTransforms: [classNames(Visibility.hiddenOnMd, Visibility.visibleOnLg)] |
| 42 |
}, |
| 43 |
{ |
| 44 |
title: 'Workspaces (hidden on xs)', |
| 45 |
columnTransforms: [classNames(Visibility.hidden, Visibility.visibleOnSm)] |
| 46 |
}, |
| 47 |
{ |
| 48 |
title: 'Last commit', |
| 49 |
transforms: [cellWidth(30)] |
| 50 |
} |
| 51 |
]; |
| 52 |
const rows: TableProps['rows'] = repositories.map((repo) => [ |
| 53 |
repo.name, |
| 54 |
repo.branches, |
| 55 |
repo.prs, |
| 56 |
repo.workspaces, |
| 57 |
repo.lastCommit |
| 58 |
]); |
| 59 |
|
| 60 |
return ( |
| 61 |
<Table aria-label="Table with width and breakpoint visibility modifiers" cells={columns} rows={rows}> |
| 62 |
<TableHeader /> |
| 63 |
<TableBody /> |
| 64 |
</Table> |
| 65 |
); |
| 66 |
}; |