Debian Codegraph @

node/@patternfly/react-table/src/deprecated/components/Table/examples/LegacyTableBasic.tsx

raw
1 import { Fragment, useState } from 'react';
2 import { Table, TableHeader, TableBody, TableProps } from '@patternfly/react-table/deprecated';
3 import { ToggleGroup, ToggleGroupItem, ToggleGroupItemProps } from '@patternfly/react-core';
4 interface Repository {
5 name: string;
6 branches: string;
7 prs: string;
8 workspaces: string;
9 lastCommit: string;
10 }
11
12 type ExampleType = 'default' | 'compact' | 'compactBorderless';
13
14 export const LegacyTableBasic: React.FunctionComponent = () => {
15 // In real usage, this data would come from some external source like an API via props.
16 const repositories: Repository[] = [
17 {
18 name: 'Repository one',
19 branches: 'Branch one',
20 prs: 'PR one',
21 workspaces: 'Workspace one',
22 lastCommit: 'Commit one'
23 },
24 {
25 name: 'Repository two',
26 branches: 'Branch two',
27 prs: 'PR two',
28 workspaces: 'Workspace two',
29 lastCommit: 'Commit two'
30 },
31 {
32 name: 'Repository three',
33 branches: 'Branch three',
34 prs: 'PR three',
35 workspaces: 'Workspace three',
36 lastCommit: 'Commit three'
37 }
38 ];
39
40 // This state is just for the ToggleGroup in this example and isn't necessary for table usage.
41 const [exampleChoice, setExampleChoice] = useState<ExampleType>('default');
42 const onExampleTypeChange: ToggleGroupItemProps['onChange'] = (event, _isSelected) => {
43 const id = event.currentTarget.id;
44 setExampleChoice(id as ExampleType);
45 };
46
47 const columns: TableProps['cells'] = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
48 const rows: TableProps['rows'] = repositories.map((repo) => [
49 repo.name,
50 repo.branches,
51 repo.prs,
52 repo.workspaces,
53 repo.lastCommit
54 ]);
55
56 return (
57 <Fragment>
58 <ToggleGroup aria-label="Default with single selectable">
59 <ToggleGroupItem
60 text="Default"
61 buttonId="default"
62 isSelected={exampleChoice === 'default'}
63 onChange={onExampleTypeChange}
64 />
65 <ToggleGroupItem
66 text="Compact"
67 buttonId="compact"
68 isSelected={exampleChoice === 'compact'}
69 onChange={onExampleTypeChange}
70 />
71 <ToggleGroupItem
72 text="Compact borderless"
73 buttonId="compactBorderless"
74 isSelected={exampleChoice === 'compactBorderless'}
75 onChange={onExampleTypeChange}
76 />
77 </ToggleGroup>
78 <Table
79 aria-label="Simple Table"
80 variant={exampleChoice !== 'default' ? 'compact' : undefined}
81 borders={exampleChoice !== 'compactBorderless'}
82 cells={columns}
83 rows={rows}
84 >
85 <TableHeader />
86 <TableBody />
87 </Table>
88 </Fragment>
89 );
90 };