| 1 |
import { Table, Caption, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; |
| 2 |
|
| 3 |
interface Repository { |
| 4 |
name: string; |
| 5 |
branches: string | null; |
| 6 |
prs: string | null; |
| 7 |
workspaces: string; |
| 8 |
lastCommit: string; |
| 9 |
} |
| 10 |
|
| 11 |
export const TablePlain: 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: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' }, |
| 15 |
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' }, |
| 16 |
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' } |
| 17 |
]; |
| 18 |
|
| 19 |
const columnNames = { |
| 20 |
name: 'Repositories', |
| 21 |
branches: 'Branches', |
| 22 |
prs: 'Pull requests', |
| 23 |
workspaces: 'Workspaces', |
| 24 |
lastCommit: 'Last commit' |
| 25 |
}; |
| 26 |
|
| 27 |
return ( |
| 28 |
<Table aria-label="Plain table" isPlain={true}> |
| 29 |
<Caption>Simple table with plain styling using composable components</Caption> |
| 30 |
<Thead> |
| 31 |
<Tr> |
| 32 |
<Th>{columnNames.name}</Th> |
| 33 |
<Th>{columnNames.branches}</Th> |
| 34 |
<Th>{columnNames.prs}</Th> |
| 35 |
<Th>{columnNames.workspaces}</Th> |
| 36 |
<Th>{columnNames.lastCommit}</Th> |
| 37 |
</Tr> |
| 38 |
</Thead> |
| 39 |
<Tbody> |
| 40 |
{repositories.map((repo) => ( |
| 41 |
<Tr key={repo.name}> |
| 42 |
<Td dataLabel={columnNames.name}>{repo.name}</Td> |
| 43 |
<Td dataLabel={columnNames.branches}>{repo.branches}</Td> |
| 44 |
<Td dataLabel={columnNames.prs}>{repo.prs}</Td> |
| 45 |
<Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td> |
| 46 |
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td> |
| 47 |
</Tr> |
| 48 |
))} |
| 49 |
</Tbody> |
| 50 |
</Table> |
| 51 |
); |
| 52 |
}; |