Debian Codegraph @

node/@patternfly/react-table/src/demos/examples/TableStickyHeader.tsx

raw
1 import { Label, PageSection } from '@patternfly/react-core';
2 import { Table, Thead, Tr, Th, Tbody, Td, TableText } from '@patternfly/react-table';
3 import { DashboardWrapper } from '@patternfly/react-table/dist/esm/demos/DashboardWrapper';
4 import { rows, columns } from '@patternfly/react-table/dist/esm/demos/sampleData';
5
6 export const TableStickyHeader: React.FunctionComponent = () => {
7 const renderLabel = (labelText: string) => {
8 switch (labelText) {
9 case 'Running':
10 return <Label color="green">{labelText}</Label>;
11 case 'Stopped':
12 return <Label color="orange">{labelText}</Label>;
13 case 'Needs Maintenance':
14 return <Label color="blue">{labelText}</Label>;
15 case 'Down':
16 return <Label color="red">{labelText}</Label>;
17 }
18 };
19
20 return (
21 <DashboardWrapper hasPageTemplateTitle>
22 <PageSection padding={{ default: 'noPadding', xl: 'padding' }} aria-label="Sticky header table data">
23 <Table aria-label="Sticky Header Table Demo" isStickyHeader>
24 <Thead>
25 <Tr>
26 <Th width={15}>{columns[0]}</Th>
27 <Th width={10}>{columns[1]}</Th>
28 <Th width={10}>{columns[2]}</Th>
29 <Th width={10}>{columns[3]}</Th>
30 <Th width={10}>{columns[4]}</Th>
31 <Th width={15}>{columns[5]}</Th>
32 <Th width={15}>{columns[6]}</Th>
33 <Th width={10}>{columns[7]}</Th>
34 </Tr>
35 </Thead>
36 <Tbody>
37 {rows.map((row) => (
38 <Tr key={row.name}>
39 <Td dataLabel={columns[0]}>{row.name}</Td>
40 <Td dataLabel={columns[1]}>{row.threads}</Td>
41 <Td dataLabel={columns[2]}>{row.applications}</Td>
42 <Td dataLabel={columns[3]}>{row.workspaces}</Td>
43 <Td dataLabel={columns[4]}>{renderLabel(row.status)}</Td>
44 <Td dataLabel={columns[5]}>{row.location}</Td>
45 <Td dataLabel={columns[6]}>{row.lastModified}</Td>
46 <Td dataLabel={columns[7]}>
47 <a href="#">
48 <TableText wrapModifier="truncate">{row.url} </TableText>
49 </a>
50 </Td>
51 </Tr>
52 ))}
53 </Tbody>
54 </Table>
55 </PageSection>
56 </DashboardWrapper>
57 );
58 };