| 1 |
import { Fragment } from 'react'; |
| 2 |
import { Table, Caption, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; |
| 3 |
|
| 4 |
interface Repository { |
| 5 |
name: string; |
| 6 |
branches: number; |
| 7 |
description?: string; |
| 8 |
prs: number; |
| 9 |
workspaces: number; |
| 10 |
lastCommit: string; |
| 11 |
} |
| 12 |
|
| 13 |
export const TableStripedMultipleTbody: React.FunctionComponent = () => { |
| 14 |
// In real usage, this data would come from some external source like an API via props. |
| 15 |
const repositories1: Repository[] = [ |
| 16 |
{ |
| 17 |
name: 'tbody 1 - Repository 1', |
| 18 |
description: '(odd rows striped)', |
| 19 |
branches: 10, |
| 20 |
prs: 25, |
| 21 |
workspaces: 5, |
| 22 |
lastCommit: '2 days ago' |
| 23 |
}, |
| 24 |
{ name: 'tbody 1 - Repository 2', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' }, |
| 25 |
{ |
| 26 |
name: 'tbody 1 - Repository 3', |
| 27 |
description: '(odd rows striped)', |
| 28 |
branches: 10, |
| 29 |
prs: 25, |
| 30 |
workspaces: 5, |
| 31 |
lastCommit: '2 days ago' |
| 32 |
} |
| 33 |
]; |
| 34 |
|
| 35 |
const repositories2: Repository[] = [ |
| 36 |
{ name: 'tbody 2 - Repository 4', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' }, |
| 37 |
{ |
| 38 |
name: 'tbody 2 - Repository 5', |
| 39 |
description: '(even rows striped)', |
| 40 |
branches: 10, |
| 41 |
prs: 25, |
| 42 |
workspaces: 5, |
| 43 |
lastCommit: '2 days ago' |
| 44 |
}, |
| 45 |
{ name: 'tbody 2 - Repository 6', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' }, |
| 46 |
{ |
| 47 |
name: 'tbody 2 - Repository 7', |
| 48 |
description: '(even rows striped)', |
| 49 |
branches: 10, |
| 50 |
prs: 25, |
| 51 |
workspaces: 5, |
| 52 |
lastCommit: '2 days ago' |
| 53 |
} |
| 54 |
]; |
| 55 |
|
| 56 |
const columnNames = { |
| 57 |
name: 'Repositories', |
| 58 |
branches: 'Branches', |
| 59 |
prs: 'Pull requests', |
| 60 |
workspaces: 'Workspaces', |
| 61 |
lastCommit: 'Last commit' |
| 62 |
}; |
| 63 |
|
| 64 |
return ( |
| 65 |
<Table aria-label="Simple table"> |
| 66 |
<Caption>Striped table using multiple tbody components</Caption> |
| 67 |
<Thead> |
| 68 |
<Tr> |
| 69 |
<Th>{columnNames.name}</Th> |
| 70 |
<Th>{columnNames.branches}</Th> |
| 71 |
<Th>{columnNames.prs}</Th> |
| 72 |
<Th>{columnNames.workspaces}</Th> |
| 73 |
<Th>{columnNames.lastCommit}</Th> |
| 74 |
</Tr> |
| 75 |
</Thead> |
| 76 |
<Tbody isOddStriped> |
| 77 |
{repositories1.map((repo) => ( |
| 78 |
<Tr key={repo.name}> |
| 79 |
<Td dataLabel={columnNames.name}> |
| 80 |
{repo.description ? ( |
| 81 |
<Fragment> |
| 82 |
{repo.name} |
| 83 |
<br /> |
| 84 |
<small>{repo.description}</small> |
| 85 |
</Fragment> |
| 86 |
) : ( |
| 87 |
repo.name |
| 88 |
)} |
| 89 |
</Td> |
| 90 |
<Td dataLabel={columnNames.branches}>{repo.branches}</Td> |
| 91 |
<Td dataLabel={columnNames.prs}>{repo.prs}</Td> |
| 92 |
<Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td> |
| 93 |
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td> |
| 94 |
</Tr> |
| 95 |
))} |
| 96 |
</Tbody> |
| 97 |
<Tbody isEvenStriped> |
| 98 |
{repositories2.map((repo) => ( |
| 99 |
<Tr key={repo.name}> |
| 100 |
<Td dataLabel={columnNames.name}> |
| 101 |
{repo.description ? ( |
| 102 |
<Fragment> |
| 103 |
{repo.name} |
| 104 |
<br /> |
| 105 |
<small>{repo.description}</small> |
| 106 |
</Fragment> |
| 107 |
) : ( |
| 108 |
repo.name |
| 109 |
)} |
| 110 |
</Td> |
| 111 |
<Td dataLabel={columnNames.branches}>{repo.branches}</Td> |
| 112 |
<Td dataLabel={columnNames.prs}>{repo.prs}</Td> |
| 113 |
<Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td> |
| 114 |
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td> |
| 115 |
</Tr> |
| 116 |
))} |
| 117 |
</Tbody> |
| 118 |
</Table> |
| 119 |
); |
| 120 |
}; |