forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompact.jsx
More file actions
135 lines (129 loc) · 4.21 KB
/
Copy pathCompact.jsx
File metadata and controls
135 lines (129 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from 'react';
import {
Button,
Card,
Toolbar,
ToolbarContent,
ToolbarGroup,
ToolbarItem,
Pagination,
Select,
SelectVariant,
SelectOption,
PageSection
} from '@patternfly/react-core';
import { TableComposable, Thead, Tr, Th, Tbody, Td, ActionsColumn } from '@patternfly/react-table';
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
export const ComposableTable = () => {
const [isSelectOpen, setIsSelectOpen] = React.useState(false);
const columns = ['Contributor', 'Position', 'Location', 'Last seen', 'Numbers', 'Icons'];
const rows = [
['Sam Jones', 'CSS guru', 'Not too sure', 'May 9, 2018', '0556'],
['Amy Miller', 'Visual design', 'Raleigh', 'May 9, 2018', '9492'],
['Steve Wilson', 'Visual design lead', 'Westford', 'May 9, 2018', '9929'],
['Emma Jackson', 'Interaction design', 'Westford', 'May 9, 2018', '2217']
];
const defaultActions = () => [
{
title: 'Settings',
// eslint-disable-next-line no-console
onClick: () => console.log(`clicked on Settings`)
},
{
title: 'Help',
// eslint-disable-next-line no-console
onClick: () => console.log(`clicked on Help`)
}
];
const renderPagination = (variant, isCompact) => (
<Pagination
isCompact={isCompact}
itemCount={36}
page={1}
perPage={10}
variant={variant}
titles={{
paginationTitle: `${variant} pagination`
}}
/>
);
const tableToolbar = (
<Toolbar usePageInsets id="compact-toolbar">
<ToolbarContent>
<ToolbarItem>
<Select
id="select-example"
variant={SelectVariant.single}
aria-label="Select Input"
placeholderText={
<>
<FilterIcon /> Status
</>
}
isOpen={isSelectOpen}
onToggle={() => setIsSelectOpen(!isSelectOpen)}
onSelect={() => setIsSelectOpen(!isSelectOpen)}
>
{[
<SelectOption key={0} value="Debug" />,
<SelectOption key={1} value="Info" />,
<SelectOption key={2} value="Warn" />,
<SelectOption key={3} value="Error" />
]}
</Select>
</ToolbarItem>
<ToolbarGroup>
<ToolbarItem>
<Button variant="primary">Action</Button>
</ToolbarItem>
</ToolbarGroup>
<ToolbarItem variant="pagination">{renderPagination('top', true)}</ToolbarItem>
</ToolbarContent>
</Toolbar>
);
return (
<React.Fragment>
<DashboardWrapper hasPageTemplateTitle>
<PageSection isFilled>
<Card>
{tableToolbar}
<TableComposable variant="compact" aria-label="Sortable Table">
<Thead>
<Tr>
{columns.map((column, columnIndex) => (
<Th key={columnIndex}>{column}</Th>
))}
</Tr>
</Thead>
<Tbody>
{rows.map((row, rowIndex) => (
<Tr key={rowIndex}>
<>
<Td dataLabel={columns[0]}>{row[0]}</Td>
<Td dataLabel={columns[1]}>{row[1]}</Td>
<Td dataLabel={columns[2]}>{row[2]}</Td>
<Td dataLabel={columns[3]}>{row[3]}</Td>
<Td dataLabel={columns[4]}>{row[4]}</Td>
<Td dataLabel={columns[5]}>
<CheckIcon key="icon" />
</Td>
<Td dataLabel={'Action'}>
<a href="#">Action link</a>
</Td>
<Td isActionCell>
<ActionsColumn items={defaultActions()} />
</Td>
</>
</Tr>
))}
</Tbody>
</TableComposable>
{renderPagination('bottom', false)}
</Card>
</PageSection>
</DashboardWrapper>
</React.Fragment>
);
};