@patternfly/react-table 4.56.1 → 4.58.0
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 +38 -0
- package/dist/esm/components/Table/ActionsColumn.d.ts.map +1 -1
- package/dist/esm/components/Table/ActionsColumn.js +4 -5
- package/dist/esm/components/Table/ActionsColumn.js.map +1 -1
- package/dist/esm/components/Table/Body.d.ts.map +1 -1
- package/dist/esm/components/Table/Body.js +12 -7
- package/dist/esm/components/Table/Body.js.map +1 -1
- package/dist/esm/components/Table/TableTypes.d.ts +36 -11
- package/dist/esm/components/Table/TableTypes.d.ts.map +1 -1
- package/dist/js/components/Table/ActionsColumn.d.ts.map +1 -1
- package/dist/js/components/Table/ActionsColumn.js +4 -5
- package/dist/js/components/Table/ActionsColumn.js.map +1 -1
- package/dist/js/components/Table/Body.d.ts.map +1 -1
- package/dist/js/components/Table/Body.js +12 -7
- package/dist/js/components/Table/Body.js.map +1 -1
- package/dist/js/components/Table/TableTypes.d.ts +36 -11
- package/dist/js/components/Table/TableTypes.d.ts.map +1 -1
- package/dist/umd/react-table.js +16 -12
- package/dist/umd/react-table.min.js +1 -1
- package/package.json +6 -6
- package/src/components/Table/ActionsColumn.tsx +34 -23
- package/src/components/Table/Body.tsx +13 -7
- package/src/components/Table/TableTypes.tsx +43 -11
- package/src/components/TableComposable/examples/ComposableTable.md +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-table",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.58.0",
|
|
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.
|
|
35
|
-
"@patternfly/react-icons": "^4.
|
|
36
|
-
"@patternfly/react-styles": "^4.
|
|
37
|
-
"@patternfly/react-tokens": "^4.
|
|
34
|
+
"@patternfly/react-core": "^4.189.0",
|
|
35
|
+
"@patternfly/react-icons": "^4.40.0",
|
|
36
|
+
"@patternfly/react-styles": "^4.39.0",
|
|
37
|
+
"@patternfly/react-tokens": "^4.41.0",
|
|
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": "
|
|
49
|
+
"gitHead": "232be76ce3bb9ee8af7b86f3b0ae3629eb65a761"
|
|
50
50
|
}
|
|
@@ -10,7 +10,14 @@ import {
|
|
|
10
10
|
DropdownPosition
|
|
11
11
|
} from '@patternfly/react-core/dist/esm/components/Dropdown/dropdownConstants';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
IAction,
|
|
15
|
+
IActionDropdownItem,
|
|
16
|
+
IActionOutsideItemButton,
|
|
17
|
+
IActionOutsideItemCustom,
|
|
18
|
+
IExtraData,
|
|
19
|
+
IRowData
|
|
20
|
+
} from './TableTypes';
|
|
14
21
|
|
|
15
22
|
export interface CustomActionsToggleProps {
|
|
16
23
|
onToggle: (isOpen: boolean) => void;
|
|
@@ -82,10 +89,16 @@ export class ActionsColumn extends React.Component<ActionsColumnProps, ActionsCo
|
|
|
82
89
|
<KebabToggle isDisabled={isDisabled} onToggle={this.onToggle} />
|
|
83
90
|
);
|
|
84
91
|
|
|
92
|
+
const outsideDropdownItems = items.filter(a => a.isOutsideDropdown) as (
|
|
93
|
+
| IActionOutsideItemButton
|
|
94
|
+
| IActionOutsideItemCustom
|
|
95
|
+
)[];
|
|
96
|
+
|
|
97
|
+
const dropdownItems = items.filter(a => !a.isOutsideDropdown) as IActionDropdownItem[];
|
|
98
|
+
|
|
85
99
|
return (
|
|
86
100
|
<React.Fragment>
|
|
87
|
-
{
|
|
88
|
-
.filter(item => item.isOutsideDropdown)
|
|
101
|
+
{outsideDropdownItems
|
|
89
102
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
103
|
.map(({ title, itemKey, onClick, isOutsideDropdown, ...props }, key) =>
|
|
91
104
|
typeof title === 'string' ? (
|
|
@@ -107,26 +120,24 @@ export class ActionsColumn extends React.Component<ActionsColumnProps, ActionsCo
|
|
|
107
120
|
position={dropdownPosition}
|
|
108
121
|
direction={dropdownDirection}
|
|
109
122
|
isOpen={isOpen}
|
|
110
|
-
dropdownItems={
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
)
|
|
129
|
-
)}
|
|
123
|
+
dropdownItems={dropdownItems.map(({ title, itemKey, onClick, isSeparator, ...props }, key) =>
|
|
124
|
+
isSeparator ? (
|
|
125
|
+
<DropdownSeparator {...props} key={itemKey || key} data-key={itemKey || key} />
|
|
126
|
+
) : (
|
|
127
|
+
<DropdownItem
|
|
128
|
+
component="button"
|
|
129
|
+
onClick={event => {
|
|
130
|
+
this.onClick(event, onClick);
|
|
131
|
+
this.onToggle(!isOpen);
|
|
132
|
+
}}
|
|
133
|
+
{...props}
|
|
134
|
+
key={itemKey || key}
|
|
135
|
+
data-key={itemKey || key}
|
|
136
|
+
>
|
|
137
|
+
{title}
|
|
138
|
+
</DropdownItem>
|
|
139
|
+
)
|
|
140
|
+
)}
|
|
130
141
|
isPlain
|
|
131
142
|
{...(rowData && rowData.actionProps)}
|
|
132
143
|
/>
|
|
@@ -57,21 +57,27 @@ class ContextBody extends React.Component<TableBodyProps, {}> {
|
|
|
57
57
|
row,
|
|
58
58
|
rowProps: extendedRowProps,
|
|
59
59
|
onClick: (event: React.MouseEvent) => {
|
|
60
|
+
const tagName = (event.target as HTMLElement).tagName;
|
|
60
61
|
const computedData = {
|
|
61
|
-
isInput:
|
|
62
|
-
isButton:
|
|
62
|
+
isInput: tagName === 'INPUT',
|
|
63
|
+
isButton: tagName === 'BUTTON'
|
|
63
64
|
};
|
|
64
65
|
|
|
65
66
|
onRowClick(event, row, rowProps, computedData);
|
|
66
67
|
},
|
|
67
68
|
onKeyDown: (event: React.KeyboardEvent) => {
|
|
69
|
+
const targetElement = event.target as HTMLElement;
|
|
70
|
+
const tagName = targetElement.tagName;
|
|
71
|
+
const computedData = {
|
|
72
|
+
isInput: tagName === 'INPUT',
|
|
73
|
+
isButton: tagName === 'BUTTON'
|
|
74
|
+
};
|
|
68
75
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
69
|
-
const computedData = {
|
|
70
|
-
isInput: (event.target as HTMLElement).tagName === 'INPUT',
|
|
71
|
-
isButton: (event.target as HTMLElement).tagName === 'BUTTON'
|
|
72
|
-
};
|
|
73
76
|
onRowClick(event, row, rowProps, computedData);
|
|
74
|
-
|
|
77
|
+
|
|
78
|
+
// prevent event default if space is typed while focusing on a hoverable row
|
|
79
|
+
// so that the page does not scroll when trying to use spacebar to select a row
|
|
80
|
+
if (event.key === ' ' && !!targetElement.closest('.pf-m-hoverable')) {
|
|
75
81
|
event.preventDefault();
|
|
76
82
|
}
|
|
77
83
|
}
|
|
@@ -146,22 +146,54 @@ export interface ISortBy {
|
|
|
146
146
|
defaultDirection?: 'asc' | 'desc';
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
export interface
|
|
149
|
+
export interface ISeparator {
|
|
150
150
|
/** Flag indicating an item on actions menu is a separator, rather than an action */
|
|
151
|
-
isSeparator
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
isSeparator: true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface IActionSeparator extends ISeparator {
|
|
155
|
+
isOutsideDropdown?: false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface IActionClickable {
|
|
156
159
|
/** Click handler for the actions menu item */
|
|
157
160
|
onClick?: (event: React.MouseEvent, rowIndex: number, rowData: IRowData, extraData: IExtraData) => void;
|
|
158
|
-
/** Flag indicating this action should be placed outside the actions menu, beside the toggle */
|
|
159
|
-
isOutsideDropdown?: boolean;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
export
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
export type IActionOutsideItemBase = IActionClickable & {
|
|
164
|
+
/** Flag indicating this action should be placed outside the actions menu, beside the toggle */
|
|
165
|
+
isOutsideDropdown: true;
|
|
166
|
+
/** Flag indicating an item on actions menu is not a separator, added to make it easy to distinguish */
|
|
167
|
+
isSeparator?: false;
|
|
168
|
+
/** Key of actions menu item */
|
|
169
|
+
itemKey?: undefined;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type IActionOutsideItemButton = IActionOutsideItemBase &
|
|
173
|
+
Omit<ButtonProps, 'onClick'> & {
|
|
174
|
+
title: string;
|
|
175
|
+
/** Key of actions menu item */
|
|
176
|
+
itemKey?: string;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export type IActionOutsideItemCustom = IActionOutsideItemBase & {
|
|
180
|
+
title: Exclude<React.ReactNode, string>;
|
|
181
|
+
[key: string]: any;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export type IActionDropdownItem = Omit<DropdownItemProps, 'title' | 'onClick'> &
|
|
185
|
+
IActionClickable & {
|
|
186
|
+
/** Flag indicating an item on actions menu is not a separator, added to make it easy to distinguish */
|
|
187
|
+
isSeparator?: false;
|
|
188
|
+
/** Flag indicating this action should be placed outside the actions menu, beside the toggle */
|
|
189
|
+
isOutsideDropdown?: false;
|
|
190
|
+
/** Key of actions menu item */
|
|
191
|
+
itemKey?: string;
|
|
192
|
+
/** Content to display in the actions menu item */
|
|
193
|
+
title: React.ReactNode;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export type IAction = IActionSeparator | IActionDropdownItem | IActionOutsideItemButton | IActionOutsideItemCustom;
|
|
165
197
|
|
|
166
198
|
export type IActions = (IAction | ISeparator)[];
|
|
167
199
|
export type IActionsResolver = (rowData: IRowData, extraData: IExtraData) => (IAction | ISeparator)[];
|
|
@@ -163,6 +163,9 @@ This example demonstrates adding actions as the last column. The header's last c
|
|
|
163
163
|
|
|
164
164
|
To make a cell an action cell, render an `ActionsColumn` component inside a row's last `Td` and pass an array of `IAction` objects via the `items` prop of `ActionsColumn`.
|
|
165
165
|
|
|
166
|
+
Look [here](https://github.com/patternfly/patternfly-react/blob/main/packages/react-table/src/components/Table/TableTypes.tsx)
|
|
167
|
+
for the `IAction` type to see what it looks like.
|
|
168
|
+
|
|
166
169
|
```ts file="ComposableTableActions.tsx"
|
|
167
170
|
```
|
|
168
171
|
|