@patternfly/react-table 4.83.2 → 4.83.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "4.83.2",
3
+ "version": "4.83.5",
4
4
  "description": "This library provides a set of React table components for use with the PatternFly 4",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,10 +31,10 @@
31
31
  "clean": "rimraf dist"
32
32
  },
33
33
  "dependencies": {
34
- "@patternfly/react-core": "^4.214.2",
35
- "@patternfly/react-icons": "^4.65.2",
36
- "@patternfly/react-styles": "^4.64.2",
37
- "@patternfly/react-tokens": "^4.66.2",
34
+ "@patternfly/react-core": "^4.214.5",
35
+ "@patternfly/react-icons": "^4.65.5",
36
+ "@patternfly/react-styles": "^4.64.5",
37
+ "@patternfly/react-tokens": "^4.66.5",
38
38
  "lodash": "^4.17.19",
39
39
  "tslib": "^2.0.0"
40
40
  },
@@ -46,5 +46,5 @@
46
46
  "react": "^16.8.0 || ^17.0.0",
47
47
  "react-dom": "^16.8.0 || ^17.0.0"
48
48
  },
49
- "gitHead": "ed7902dfb21796ef07d5f938c3937d55d7dda0b9"
49
+ "gitHead": "f5ee87ffe8b88ade3018d145fba33f0579c85c61"
50
50
  }
@@ -4,6 +4,7 @@ section: components
4
4
  ---
5
5
 
6
6
  import { Checkbox, PageSection, ToolbarExpandIconWrapper, ToolbarContent } from '@patternfly/react-core';
7
+ import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
7
8
  import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
8
9
  import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
9
10
  import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
@@ -277,6 +278,16 @@ class BulkSelectTableDemo extends React.Component {
277
278
  ```js isFullscreen file="table-demos/ExpandCollapseAll.jsx"
278
279
  ```
279
280
 
281
+ ### Compact
282
+
283
+ ```js isFullscreen file="table-demos/Compact.jsx"
284
+ ```
285
+
286
+ ### Compound expansion
287
+
288
+ ```js isFullscreen file="table-demos/CompoundExpansion.jsx"
289
+ ```
290
+
280
291
  ### Column management
281
292
 
282
293
  ```js
@@ -0,0 +1,135 @@
1
+ import React from 'react';
2
+ import {
3
+ Button,
4
+ Card,
5
+ Toolbar,
6
+ ToolbarContent,
7
+ ToolbarGroup,
8
+ ToolbarItem,
9
+ Pagination,
10
+ Select,
11
+ SelectVariant,
12
+ SelectOption,
13
+ PageSection
14
+ } from '@patternfly/react-core';
15
+ import { TableComposable, Thead, Tr, Th, Tbody, Td, ActionsColumn } from '@patternfly/react-table';
16
+
17
+ import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
18
+ import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
19
+ import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
20
+
21
+ export const ComposableTable = () => {
22
+ const [isSelectOpen, setIsSelectOpen] = React.useState(false);
23
+
24
+ const columns = ['Contributor', 'Position', 'Location', 'Last seen', 'Numbers', 'Icons'];
25
+ const rows = [
26
+ ['Sam Jones', 'CSS guru', 'Not too sure', 'May 9, 2018', '0556'],
27
+ ['Amy Miller', 'Visual design', 'Raleigh', 'May 9, 2018', '9492'],
28
+ ['Steve Wilson', 'Visual design lead', 'Westford', 'May 9, 2018', '9929'],
29
+ ['Emma Jackson', 'Interaction design', 'Westford', 'May 9, 2018', '2217']
30
+ ];
31
+
32
+ const defaultActions = () => [
33
+ {
34
+ title: 'Settings',
35
+ // eslint-disable-next-line no-console
36
+ onClick: () => console.log(`clicked on Settings`)
37
+ },
38
+ {
39
+ title: 'Help',
40
+ // eslint-disable-next-line no-console
41
+ onClick: () => console.log(`clicked on Help`)
42
+ }
43
+ ];
44
+ const renderPagination = (variant, isCompact) => (
45
+ <Pagination
46
+ isCompact={isCompact}
47
+ itemCount={36}
48
+ page={1}
49
+ perPage={10}
50
+ variant={variant}
51
+ titles={{
52
+ paginationTitle: `${variant} pagination`
53
+ }}
54
+ />
55
+ );
56
+
57
+ const tableToolbar = (
58
+ <Toolbar usePageInsets id="compact-toolbar">
59
+ <ToolbarContent>
60
+ <ToolbarItem>
61
+ <Select
62
+ id="select-example"
63
+ variant={SelectVariant.single}
64
+ aria-label="Select Input"
65
+ placeholderText={
66
+ <>
67
+ <FilterIcon /> Status
68
+ </>
69
+ }
70
+ isOpen={isSelectOpen}
71
+ onToggle={() => setIsSelectOpen(!isSelectOpen)}
72
+ onSelect={() => setIsSelectOpen(!isSelectOpen)}
73
+ >
74
+ {[
75
+ <SelectOption key={0} value="Debug" />,
76
+ <SelectOption key={1} value="Info" />,
77
+ <SelectOption key={2} value="Warn" />,
78
+ <SelectOption key={3} value="Error" />
79
+ ]}
80
+ </Select>
81
+ </ToolbarItem>
82
+ <ToolbarGroup>
83
+ <ToolbarItem>
84
+ <Button variant="primary">Action</Button>
85
+ </ToolbarItem>
86
+ </ToolbarGroup>
87
+ <ToolbarItem variant="pagination">{renderPagination('top', true)}</ToolbarItem>
88
+ </ToolbarContent>
89
+ </Toolbar>
90
+ );
91
+
92
+ return (
93
+ <React.Fragment>
94
+ <DashboardWrapper hasPageTemplateTitle>
95
+ <PageSection isFilled>
96
+ <Card>
97
+ {tableToolbar}
98
+ <TableComposable variant="compact" aria-label="Sortable Table">
99
+ <Thead>
100
+ <Tr>
101
+ {columns.map((column, columnIndex) => (
102
+ <Th key={columnIndex}>{column}</Th>
103
+ ))}
104
+ </Tr>
105
+ </Thead>
106
+ <Tbody>
107
+ {rows.map((row, rowIndex) => (
108
+ <Tr key={rowIndex}>
109
+ <>
110
+ <Td dataLabel={columns[0]}>{row[0]}</Td>
111
+ <Td dataLabel={columns[1]}>{row[1]}</Td>
112
+ <Td dataLabel={columns[2]}>{row[2]}</Td>
113
+ <Td dataLabel={columns[3]}>{row[3]}</Td>
114
+ <Td dataLabel={columns[4]}>{row[4]}</Td>
115
+ <Td dataLabel={columns[5]}>
116
+ <CheckIcon key="icon" />
117
+ </Td>
118
+ <Td dataLabel={'Action'}>
119
+ <a href="#">Action link</a>
120
+ </Td>
121
+ <Td isActionCell>
122
+ <ActionsColumn items={defaultActions()} />
123
+ </Td>
124
+ </>
125
+ </Tr>
126
+ ))}
127
+ </Tbody>
128
+ </TableComposable>
129
+ {renderPagination('bottom', false)}
130
+ </Card>
131
+ </PageSection>
132
+ </DashboardWrapper>
133
+ </React.Fragment>
134
+ );
135
+ };
@@ -0,0 +1,260 @@
1
+ import React from 'react';
2
+ import {
3
+ ActionsColumn,
4
+ TableComposable,
5
+ Thead,
6
+ Tr,
7
+ Th,
8
+ Tbody,
9
+ Td,
10
+ ExpandableRowContent
11
+ } from '@patternfly/react-table';
12
+ import {
13
+ Button,
14
+ Card,
15
+ Flex,
16
+ FlexItem,
17
+ Toolbar,
18
+ ToolbarContent,
19
+ ToolbarGroup,
20
+ ToolbarItem,
21
+ Pagination,
22
+ Select,
23
+ SelectVariant,
24
+ SelectOption,
25
+ PageSection
26
+ } from '@patternfly/react-core';
27
+ import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
28
+ import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
29
+ import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
30
+ import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
31
+ import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
32
+
33
+ export const CompoundExpandable = () => {
34
+ // In real usage, this data would come from some external source like an API via props.
35
+ const [isSelectOpen, setIsSelectOpen] = React.useState(false);
36
+
37
+ const NestedItemsTable = () => {
38
+ // In real usage, this data would come from some external source like an API via props.
39
+ const items = [
40
+ { description: 'Item 1', date: 'May 9, 2018', status: 'Active' },
41
+ { description: 'Item 2', date: 'May 9, 2018', status: 'Warning' },
42
+ { description: 'Item 3', date: 'May 9, 2018', status: 'Active' },
43
+ { description: 'Item 4', date: 'May 9, 2018', status: 'Active' },
44
+ { description: 'Item 5', date: 'May 9, 2018', status: 'Active' }
45
+ ];
46
+
47
+ const columnNames = {
48
+ description: 'Description',
49
+ date: 'Date',
50
+ status: 'Status'
51
+ };
52
+
53
+ return (
54
+ <TableComposable borders={false} aria-label="Nested table" variant="compact">
55
+ <Thead>
56
+ <Tr>
57
+ <Th>{columnNames.description}</Th>
58
+ <Th>{columnNames.date}</Th>
59
+ <Th>{columnNames.status}</Th>
60
+ <Th />
61
+ </Tr>
62
+ </Thead>
63
+ <Tbody>
64
+ {items.map(item => (
65
+ <Tr key={item.name}>
66
+ <Td dataLabel={columnNames.description}>{item.description}</Td>
67
+ <Td dataLabel={columnNames.date}>{item.date}</Td>
68
+ <Td dataLabel={columnNames.status}>{item.status}</Td>
69
+ <Td isActionCell>
70
+ <ActionsColumn items={defaultActions()} />
71
+ </Td>
72
+ </Tr>
73
+ ))}
74
+ </Tbody>
75
+ </TableComposable>
76
+ );
77
+ };
78
+
79
+ const renderPagination = (variant, isCompact) => (
80
+ <Pagination
81
+ isCompact={isCompact}
82
+ itemCount={36}
83
+ page={1}
84
+ perPage={10}
85
+ variant={variant}
86
+ titles={{
87
+ paginationTitle: `${variant} pagination`
88
+ }}
89
+ />
90
+ );
91
+
92
+ const tableToolbar = (
93
+ <Toolbar id="compact-toolbar" usePageInsets>
94
+ <ToolbarContent>
95
+ <ToolbarItem>
96
+ <Select
97
+ id="select-example"
98
+ variant={SelectVariant.single}
99
+ aria-label="Select Input"
100
+ placeholderText={
101
+ <>
102
+ <FilterIcon /> Status
103
+ </>
104
+ }
105
+ isOpen={isSelectOpen}
106
+ onToggle={() => setIsSelectOpen(!isSelectOpen)}
107
+ onSelect={() => setIsSelectOpen(!isSelectOpen)}
108
+ >
109
+ {[
110
+ <SelectOption key={0} value="Debug" />,
111
+ <SelectOption key={1} value="Info" />,
112
+ <SelectOption key={2} value="Warn" />,
113
+ <SelectOption key={3} value="Error" />
114
+ ]}
115
+ </Select>
116
+ </ToolbarItem>
117
+ <ToolbarGroup>
118
+ <ToolbarItem>
119
+ <Button variant="primary">Action</Button>
120
+ </ToolbarItem>
121
+ </ToolbarGroup>
122
+ <ToolbarItem variant="pagination">{renderPagination('top', true)}</ToolbarItem>
123
+ </ToolbarContent>
124
+ </Toolbar>
125
+ );
126
+
127
+ const defaultActions = () => [
128
+ {
129
+ title: 'Settings',
130
+ // eslint-disable-next-line no-console
131
+ onClick: () => console.log(`clicked on Settings`)
132
+ },
133
+ {
134
+ title: 'Help',
135
+ // eslint-disable-next-line no-console
136
+ onClick: () => console.log(`clicked on Help`)
137
+ }
138
+ ];
139
+
140
+ const repositories = [
141
+ {
142
+ name: 'siemur/test-space',
143
+ branches: 10,
144
+ prs: 4,
145
+ workspaces: 4,
146
+ lastCommit: '20 minutes'
147
+ },
148
+ { name: 'siemur/test-space-2', branches: 3, prs: 4, workspaces: 4, lastCommit: '20 minutes' }
149
+ ];
150
+
151
+ const columnNames = {
152
+ name: 'Repositories',
153
+ branches: 'Branches',
154
+ prs: 'Pull requests',
155
+ workspaces: 'Workspaces',
156
+ lastCommit: 'Last commit'
157
+ };
158
+
159
+ // In this example, expanded cells are tracked by the repo and property names from each row. This could be any pair of unique identifiers.
160
+ // This is to prevent state from being based on row and column order index in case we later add sorting and rearranging columns.
161
+ // Note that this behavior is very similar to selection state.
162
+ const [expandedCells, setExpandedCells] = React.useState({
163
+ 'siemur/test-space': 'branches' // Default to the first cell of the first row being expanded
164
+ });
165
+ const setCellExpanded = (repo, columnKey, isExpanding = true) => {
166
+ const newExpandedCells = { ...expandedCells };
167
+ if (isExpanding) {
168
+ newExpandedCells[repo.name] = columnKey;
169
+ } else {
170
+ delete newExpandedCells[repo.name];
171
+ }
172
+ setExpandedCells(newExpandedCells);
173
+ };
174
+ const compoundExpandParams = (repo, columnKey) => ({
175
+ isExpanded: expandedCells[repo.name] === columnKey,
176
+ onToggle: () => setCellExpanded(repo, columnKey, expandedCells[repo.name] !== columnKey)
177
+ });
178
+
179
+ return (
180
+ <DashboardWrapper hasPageTemplateTitle>
181
+ <PageSection padding={{ default: 'noPadding', xl: 'padding' }}>
182
+ <Card>
183
+ {tableToolbar}
184
+ <TableComposable aria-label="Compound expandable table">
185
+ <Thead>
186
+ <Tr>
187
+ <Th>{columnNames.name}</Th>
188
+ <Th>{columnNames.branches}</Th>
189
+ <Th>{columnNames.prs}</Th>
190
+ <Th>{columnNames.workspaces}</Th>
191
+ <Th>{columnNames.lastCommit}</Th>
192
+ <Th />
193
+ </Tr>
194
+ </Thead>
195
+ {repositories.map(repo => {
196
+ const expandedCellKey = expandedCells[repo.name];
197
+ const isRowExpanded = !!expandedCellKey;
198
+ return (
199
+ <Tbody key={repo.name} isExpanded={isRowExpanded}>
200
+ <Tr>
201
+ <Td dataLabel={columnNames.name} component="th">
202
+ <a href="#">{repo.name}</a>
203
+ </Td>
204
+ <Td dataLabel={columnNames.branches} compoundExpand={compoundExpandParams(repo, 'branches')}>
205
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
206
+ <FlexItem>
207
+ <CodeBranchIcon key="icon" />
208
+ </FlexItem>
209
+ <FlexItem>{repo.branches}</FlexItem>
210
+ </Flex>
211
+ </Td>
212
+ <Td dataLabel={columnNames.prs} compoundExpand={compoundExpandParams(repo, 'prs')}>
213
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
214
+ <FlexItem>
215
+ <CodeIcon key="icon" />
216
+ </FlexItem>
217
+ <FlexItem>{repo.prs}</FlexItem>
218
+ </Flex>{' '}
219
+ </Td>
220
+ <Td dataLabel={columnNames.workspaces} compoundExpand={compoundExpandParams(repo, 'workspaces')}>
221
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
222
+ <FlexItem>
223
+ <CubeIcon key="icon" />
224
+ </FlexItem>
225
+ <FlexItem>{repo.workspaces}</FlexItem>
226
+ </Flex>
227
+ </Td>
228
+ <Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
229
+ <Td>
230
+ <a href="#">Open in GitHub</a>
231
+ </Td>
232
+ <Td isActionCell>
233
+ <ActionsColumn items={defaultActions()} />
234
+ </Td>
235
+ </Tr>
236
+ {isRowExpanded ? (
237
+ <Tr isExpanded={isRowExpanded}>
238
+ <Td dataLabel={columnNames[expandedCellKey]} noPadding colSpan={7}>
239
+ {expandedCellKey === 'branches' && repo.name === 'siemur/test-space' ? (
240
+ <NestedItemsTable />
241
+ ) : (
242
+ <ExpandableRowContent>
243
+ <div className="pf-u-m-md">
244
+ Expanded content for {repo.name}: {expandedCellKey} goes here!
245
+ </div>
246
+ </ExpandableRowContent>
247
+ )}
248
+ </Td>
249
+ </Tr>
250
+ ) : null}
251
+ </Tbody>
252
+ );
253
+ })}
254
+ </TableComposable>
255
+ {renderPagination('bottom', false)}
256
+ </Card>
257
+ </PageSection>
258
+ </DashboardWrapper>
259
+ );
260
+ };