@patternfly/react-table 4.103.0 → 4.103.1
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/CHANGELOG.md +8 -0
- package/dist/umd/react-table.min.css +1041 -1041
- package/package.json +6 -6
- package/src/{demos → docs/demos}/Table.md +1 -1
- package/src/{demos → docs/demos}/table-demos/Compact.jsx +0 -0
- package/src/{demos → docs/demos}/table-demos/CompoundExpansion.jsx +0 -0
- package/src/docs/demos/table-demos/ExpandCollapseAll.jsx +219 -0
- package/src/{demos → docs/demos}/table-demos/StickyFirstColumn.jsx +0 -0
- package/src/{demos → docs}/examples/ComposableTableStickyToolbar.tsx +0 -0
- package/src/docs/examples/Data.jsx +768 -0
- package/src/demos/table-demos/ExpandCollapseAll.jsx +0 -152
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Card, PageSection, Table, TableHeader, TableBody, expandable } from '@patternfly/react-table';
|
|
3
|
-
import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
class ExpandCollapseAllTableDemo extends React.Component {
|
|
7
|
-
constructor(props) {
|
|
8
|
-
super(props);
|
|
9
|
-
this.state = {
|
|
10
|
-
isChecked: false,
|
|
11
|
-
selectedRows: 0,
|
|
12
|
-
expandedRows: 0,
|
|
13
|
-
expandCollapseToggle: 'expand',
|
|
14
|
-
collapseAllAriaLabel: 'Expand all',
|
|
15
|
-
columns: [
|
|
16
|
-
{
|
|
17
|
-
title: 'Repositories',
|
|
18
|
-
cellFormatters: [expandable]
|
|
19
|
-
},
|
|
20
|
-
'Branches',
|
|
21
|
-
'Pull requests',
|
|
22
|
-
'Workspaces',
|
|
23
|
-
'Last Commit'
|
|
24
|
-
],
|
|
25
|
-
rows: [
|
|
26
|
-
{
|
|
27
|
-
cells: ['one', 'two', 'three', 'four', 'five']
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
isOpen: false,
|
|
31
|
-
cells: ['parent - 1', 'two', 'three', 'four', 'five']
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
parent: 1,
|
|
35
|
-
cells: ['child - 1']
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
isOpen: false,
|
|
39
|
-
cells: ['parent - 2', 'two', 'three', 'four', 'five']
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
parent: 3,
|
|
43
|
-
cells: ['child - 2']
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
isOpen: false,
|
|
47
|
-
cells: ['parent - 3', 'two', 'three', 'four', 'five']
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
parent: 5,
|
|
51
|
-
cells: ['child - 3']
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
};
|
|
55
|
-
this.onCollapse = this.onCollapse.bind(this);
|
|
56
|
-
this.onSelect = this.onSelect.bind(this);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
onCollapse(event, rowIndex, isOpen) {
|
|
60
|
-
const { rows, expandedRows, expandCollapseToggle } = this.state;
|
|
61
|
-
const expandableRowLength = this.state.rows.filter(row => row.isOpen !== undefined).length;
|
|
62
|
-
/**
|
|
63
|
-
* Please do not use rowKey as row index for more complex tables.
|
|
64
|
-
* Rather use some kind of identifier like ID passed with each row.
|
|
65
|
-
*/
|
|
66
|
-
const collapseAll = rowIndex === undefined;
|
|
67
|
-
let newRows = Array.from(rows);
|
|
68
|
-
let newExpandedRows = expandedRows;
|
|
69
|
-
if (collapseAll) {
|
|
70
|
-
newRows = newRows.map(r => (r.isOpen === undefined ? r : { ...r, isOpen }));
|
|
71
|
-
newExpandedRows = isOpen ? expandableRowLength : 0;
|
|
72
|
-
} else {
|
|
73
|
-
newRows[rowIndex] = { ...newRows[rowIndex], isOpen };
|
|
74
|
-
newExpandedRows = isOpen ? newExpandedRows + 1 : newExpandedRows - 1;
|
|
75
|
-
}
|
|
76
|
-
let toggle = expandCollapseToggle;
|
|
77
|
-
if (newExpandedRows === expandableRowLength) {
|
|
78
|
-
toggle = 'collapse';
|
|
79
|
-
} else if (newExpandedRows === 0) {
|
|
80
|
-
toggle = 'expand';
|
|
81
|
-
}
|
|
82
|
-
this.setState({
|
|
83
|
-
rows: newRows,
|
|
84
|
-
expandedRows: newExpandedRows,
|
|
85
|
-
expandCollapseToggle: toggle,
|
|
86
|
-
collapseAllAriaLabel: toggle === 'expand' ? 'Expand All' : 'Collapse All'
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
onSelect(event, isSelected, rowId) {
|
|
91
|
-
let isChecked = null;
|
|
92
|
-
let selectedRows = this.state.selectedRows;
|
|
93
|
-
const selectableRowLength = this.state.rows.filter(row => row.parent === undefined).length;
|
|
94
|
-
let rows;
|
|
95
|
-
if (rowId === -1) {
|
|
96
|
-
rows = this.state.rows.map(row => {
|
|
97
|
-
row.selected = isSelected;
|
|
98
|
-
return row;
|
|
99
|
-
});
|
|
100
|
-
isChecked = isSelected;
|
|
101
|
-
selectedRows = isSelected ? selectableRowLength : 0;
|
|
102
|
-
} else {
|
|
103
|
-
rows = [...this.state.rows];
|
|
104
|
-
rows[rowId] = { ...rows[rowId], selected: isSelected };
|
|
105
|
-
selectedRows = isSelected ? selectedRows + 1 : selectedRows - 1;
|
|
106
|
-
if (selectedRows === 0) {
|
|
107
|
-
isChecked = false;
|
|
108
|
-
} else if (selectedRows === selectableRowLength) {
|
|
109
|
-
isChecked = true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
this.setState({
|
|
113
|
-
rows,
|
|
114
|
-
isChecked,
|
|
115
|
-
selectedRows
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
render() {
|
|
120
|
-
const { columns, rows, collapseAllAriaLabel } = this.state;
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<React.Fragment>
|
|
124
|
-
<DashboardWrapper hasPageTemplateTitle>
|
|
125
|
-
<PageSection
|
|
126
|
-
padding={{
|
|
127
|
-
default: 'noPadding',
|
|
128
|
-
xl: 'padding'
|
|
129
|
-
}}
|
|
130
|
-
>
|
|
131
|
-
<Card component="div">
|
|
132
|
-
<Table
|
|
133
|
-
aria-label="Collapsible table"
|
|
134
|
-
onSelect={this.onSelect}
|
|
135
|
-
onCollapse={this.onCollapse}
|
|
136
|
-
rows={rows}
|
|
137
|
-
cells={columns}
|
|
138
|
-
canSelectAll={false}
|
|
139
|
-
canCollapseAll={true}
|
|
140
|
-
collapseAllAriaLabel={collapseAllAriaLabel}
|
|
141
|
-
expandId="expand-collapse-all-demo"
|
|
142
|
-
>
|
|
143
|
-
<TableHeader />
|
|
144
|
-
<TableBody />
|
|
145
|
-
</Table>
|
|
146
|
-
</Card>
|
|
147
|
-
</PageSection>
|
|
148
|
-
</DashboardWrapper>
|
|
149
|
-
</React.Fragment>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|