| 1 |
import { Table, Caption, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; |
| 2 |
|
| 3 |
interface Repository { |
| 4 |
name: string; |
| 5 |
branches: number; |
| 6 |
prs: number; |
| 7 |
workspaces: number; |
| 8 |
lastCommit: string; |
| 9 |
} |
| 10 |
|
| 11 |
export const TableStriped: React.FunctionComponent = () => { |
| 12 |
// In real usage, this data would come from some external source like an API via props. |
| 13 |
const repositories: Repository[] = [ |
| 14 |
{ name: 'Repository 1', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' }, |
| 15 |
{ name: 'Repository 2', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' }, |
| 16 |
{ name: 'Repository 3', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' }, |
| 17 |
{ name: 'Repository 4', branches: 10, prs: 25, workspaces: 5, lastCommit: '2 days ago' } |
| 18 |
]; |
| 19 |
|
| 20 |
const columnNames = { |
| 21 |
name: 'Repositories', |
| 22 |
branches: 'Branches', |
| 23 |
prs: 'Pull requests', |
| 24 |
workspaces: 'Workspaces', |
| 25 |
lastCommit: 'Last commit' |
| 26 |
}; |
| 27 |
|
| 28 |
return ( |
| 29 |
<Table aria-label="Simple table" isStriped> |
| 30 |
<Caption>Simple striped table using composable components</Caption> |
| 31 |
<Thead> |
| 32 |
<Tr> |
| 33 |
<Th>{columnNames.name}</Th> |
| 34 |
<Th>{columnNames.branches}</Th> |
| 35 |
<Th>{columnNames.prs}</Th> |
| 36 |
<Th>{columnNames.workspaces}</Th> |
| 37 |
<Th>{columnNames.lastCommit}</Th> |
| 38 |
</Tr> |
| 39 |
</Thead> |
| 40 |
<Tbody> |
| 41 |
{repositories.map((repo) => ( |
| 42 |
<Tr key={repo.name}> |
| 43 |
<Td dataLabel={columnNames.name}>{repo.name}</Td> |
| 44 |
<Td dataLabel={columnNames.branches}>{repo.branches}</Td> |
| 45 |
<Td dataLabel={columnNames.prs}>{repo.prs}</Td> |
| 46 |
<Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td> |
| 47 |
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td> |
| 48 |
</Tr> |
| 49 |
))} |
| 50 |
</Tbody> |
| 51 |
</Table> |
| 52 |
); |
| 53 |
}; |