@carbon/react 1.33.2 → 1.34.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/es/components/Button/Button.d.ts +1 -1
- package/es/components/ComposedModal/ComposedModal.js +13 -14
- package/es/components/DataTable/DataTable.d.ts +541 -0
- package/es/components/DataTable/DataTable.js +35 -14
- package/es/components/DataTable/index.d.ts +2 -2
- package/es/components/DataTable/state/sortStates.d.ts +13 -0
- package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +17 -16
- package/es/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
- package/es/components/ExpandableSearch/ExpandableSearch.js +16 -8
- package/es/components/InlineCheckbox/InlineCheckbox.js +3 -2
- package/es/components/OverflowMenu/OverflowMenu.js +2 -2
- package/es/components/Search/Search.d.ts +2 -2
- package/es/components/Search/Search.js +25 -4
- package/es/components/Tabs/Tabs.js +2 -0
- package/es/components/Tag/Tag.js +9 -2
- package/es/components/TextArea/TextArea.js +1 -0
- package/es/components/Toggle/Toggle.d.ts +8 -8
- package/es/components/UIShell/HeaderMenuButton.d.ts +57 -0
- package/es/components/UIShell/HeaderMenuButton.js +4 -0
- package/es/components/UIShell/HeaderNavigation.d.ts +56 -0
- package/es/prop-types/isRequiredOneOf.js +2 -2
- package/lib/components/Button/Button.d.ts +1 -1
- package/lib/components/ComposedModal/ComposedModal.js +13 -14
- package/lib/components/DataTable/DataTable.d.ts +541 -0
- package/lib/components/DataTable/DataTable.js +39 -18
- package/lib/components/DataTable/index.d.ts +2 -2
- package/lib/components/DataTable/state/sortStates.d.ts +13 -0
- package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +17 -16
- package/lib/components/ExpandableSearch/ExpandableSearch.d.ts +1 -1
- package/lib/components/ExpandableSearch/ExpandableSearch.js +16 -8
- package/lib/components/InlineCheckbox/InlineCheckbox.js +3 -2
- package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
- package/lib/components/Search/Search.d.ts +2 -2
- package/lib/components/Search/Search.js +24 -3
- package/lib/components/Tabs/Tabs.js +2 -0
- package/lib/components/Tag/Tag.js +9 -2
- package/lib/components/TextArea/TextArea.js +1 -0
- package/lib/components/Toggle/Toggle.d.ts +8 -8
- package/lib/components/UIShell/HeaderMenuButton.d.ts +57 -0
- package/lib/components/UIShell/HeaderMenuButton.js +4 -0
- package/lib/components/UIShell/HeaderNavigation.d.ts +56 -0
- package/lib/prop-types/isRequiredOneOf.js +2 -2
- package/package.json +6 -6
|
@@ -33,7 +33,7 @@ interface ButtonBaseProps extends React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
|
33
33
|
*/
|
|
34
34
|
iconDescription?: string;
|
|
35
35
|
/**
|
|
36
|
-
* Specify whether the Button is expressive, or not
|
|
36
|
+
* Specify whether the Button is expressive, or not. Only applies to the large/default button size.
|
|
37
37
|
*/
|
|
38
38
|
isExpressive?: boolean;
|
|
39
39
|
/**
|
|
@@ -177,25 +177,24 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
177
177
|
}
|
|
178
178
|
});
|
|
179
179
|
useEffect(() => {
|
|
180
|
+
const initialFocus = focusContainerElement => {
|
|
181
|
+
const containerElement = focusContainerElement || innerModal.current;
|
|
182
|
+
const primaryFocusElement = containerElement ? containerElement.querySelector(selectorPrimaryFocus) : null;
|
|
183
|
+
if (primaryFocusElement) {
|
|
184
|
+
return primaryFocusElement;
|
|
185
|
+
}
|
|
186
|
+
return button && button.current;
|
|
187
|
+
};
|
|
180
188
|
const focusButton = focusContainerElement => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
primaryFocusElement.focus();
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (button.current) {
|
|
188
|
-
button.current.focus();
|
|
189
|
-
}
|
|
189
|
+
const target = initialFocus(focusContainerElement);
|
|
190
|
+
if (target) {
|
|
191
|
+
target.focus();
|
|
190
192
|
}
|
|
191
193
|
};
|
|
192
|
-
if (
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (innerModal.current) {
|
|
194
|
+
if (open && isOpen) {
|
|
196
195
|
focusButton(innerModal.current);
|
|
197
196
|
}
|
|
198
|
-
}, [open, selectorPrimaryFocus]);
|
|
197
|
+
}, [open, selectorPrimaryFocus, isOpen]);
|
|
199
198
|
return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
|
|
200
199
|
role: "presentation",
|
|
201
200
|
ref: ref,
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import type { DataTableSortState } from './state/sortStates';
|
|
10
|
+
import Table from './Table';
|
|
11
|
+
import TableActionList from './TableActionList';
|
|
12
|
+
import TableBatchAction from './TableBatchAction';
|
|
13
|
+
import TableBatchActions from './TableBatchActions';
|
|
14
|
+
import TableBody from './TableBody';
|
|
15
|
+
import TableCell from './TableCell';
|
|
16
|
+
import TableContainer from './TableContainer';
|
|
17
|
+
import TableExpandHeader from './TableExpandHeader';
|
|
18
|
+
import TableExpandRow from './TableExpandRow';
|
|
19
|
+
import TableExpandedRow from './TableExpandedRow';
|
|
20
|
+
import TableHead from './TableHead';
|
|
21
|
+
import TableHeader from './TableHeader';
|
|
22
|
+
import TableRow from './TableRow';
|
|
23
|
+
import TableSelectAll from './TableSelectAll';
|
|
24
|
+
import TableSelectRow from './TableSelectRow';
|
|
25
|
+
import TableToolbar from './TableToolbar';
|
|
26
|
+
import TableToolbarAction from './TableToolbarAction';
|
|
27
|
+
import TableToolbarContent from './TableToolbarContent';
|
|
28
|
+
import TableToolbarSearch from './TableToolbarSearch';
|
|
29
|
+
import TableToolbarMenu from './TableToolbarMenu';
|
|
30
|
+
declare const dataTableDefaultProps: {
|
|
31
|
+
filterRows: ({ rowIds, headers, cellsById, inputValue, getCellId, }: {
|
|
32
|
+
rowIds: string[];
|
|
33
|
+
headers: any[];
|
|
34
|
+
cellsById: any;
|
|
35
|
+
inputValue: string;
|
|
36
|
+
getCellId: Function;
|
|
37
|
+
}) => string[];
|
|
38
|
+
locale: string;
|
|
39
|
+
overflowMenuOnHover: boolean;
|
|
40
|
+
size: string;
|
|
41
|
+
sortRow: (cellA: any, cellB: any, { sortDirection, sortStates, locale }: {
|
|
42
|
+
sortDirection: any;
|
|
43
|
+
sortStates: any;
|
|
44
|
+
locale: any;
|
|
45
|
+
}) => number;
|
|
46
|
+
translateWithId: (id: any) => string;
|
|
47
|
+
};
|
|
48
|
+
export type DataTableSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
49
|
+
export interface DataTableCell {
|
|
50
|
+
id: string;
|
|
51
|
+
value: unknown;
|
|
52
|
+
isEditable: boolean;
|
|
53
|
+
isEditing: boolean;
|
|
54
|
+
isValid: boolean;
|
|
55
|
+
errors: null | Array<Error>;
|
|
56
|
+
info: {
|
|
57
|
+
header: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface DataTableRow {
|
|
61
|
+
id: string;
|
|
62
|
+
cells: Array<DataTableCell>;
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
isExpanded?: boolean;
|
|
65
|
+
isSelected?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface DataTableHeader {
|
|
68
|
+
key: string;
|
|
69
|
+
header: React.ReactNode;
|
|
70
|
+
}
|
|
71
|
+
export interface DataTableRenderProps {
|
|
72
|
+
headers: Array<DataTableHeader>;
|
|
73
|
+
rows: Array<DataTableRow>;
|
|
74
|
+
selectedRows: Array<DataTableRow>;
|
|
75
|
+
getHeaderProps: (getHeaderPropsArgs: {
|
|
76
|
+
header: DataTableHeader;
|
|
77
|
+
isSortable?: boolean;
|
|
78
|
+
onClick?: (e: MouseEvent, sortState: {
|
|
79
|
+
sortHeaderKey: string;
|
|
80
|
+
sortDirection: DataTableSortState;
|
|
81
|
+
}) => void;
|
|
82
|
+
[key: string]: unknown;
|
|
83
|
+
}) => {
|
|
84
|
+
isSortable: boolean | undefined;
|
|
85
|
+
isSortHeader: boolean;
|
|
86
|
+
key: string;
|
|
87
|
+
onClick: (e: MouseEvent) => void;
|
|
88
|
+
sortDirection: DataTableSortState;
|
|
89
|
+
[key: string]: unknown;
|
|
90
|
+
};
|
|
91
|
+
getExpandHeaderProps: (getExpandHeaderPropsArgs?: {
|
|
92
|
+
onClick?: (e: MouseEvent, expandState: {
|
|
93
|
+
isExpanded?: boolean;
|
|
94
|
+
}) => void;
|
|
95
|
+
onExpand?: (e: MouseEvent) => void;
|
|
96
|
+
[key: string]: unknown;
|
|
97
|
+
}) => {
|
|
98
|
+
ariaLabel: string;
|
|
99
|
+
isExpanded: boolean;
|
|
100
|
+
onExpand: (e: MouseEvent) => void;
|
|
101
|
+
[key: string]: unknown;
|
|
102
|
+
};
|
|
103
|
+
getRowProps: (getRowPropsArgs: {
|
|
104
|
+
onClick?: (e: MouseEvent) => void;
|
|
105
|
+
row: DataTableRow;
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
}) => {
|
|
108
|
+
ariaLabel: string;
|
|
109
|
+
disabled: boolean | undefined;
|
|
110
|
+
isExpanded?: boolean;
|
|
111
|
+
isSelected?: boolean;
|
|
112
|
+
key: string;
|
|
113
|
+
onExpand: (e: MouseEvent) => void;
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
};
|
|
116
|
+
getSelectionProps: (getSelectionPropsArgs: {
|
|
117
|
+
onClick?: (e: MouseEvent) => void;
|
|
118
|
+
row: DataTableRow;
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
}) => {
|
|
121
|
+
ariaLabel: string;
|
|
122
|
+
checked: boolean | undefined;
|
|
123
|
+
disabled?: boolean | undefined;
|
|
124
|
+
id: string;
|
|
125
|
+
indeterminate?: boolean;
|
|
126
|
+
name: string;
|
|
127
|
+
onSelect: (e: MouseEvent) => void;
|
|
128
|
+
radio?: boolean | null;
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
};
|
|
131
|
+
getToolbarProps: (getToolbarPropsArgs?: {
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}) => {
|
|
134
|
+
size: 'sm' | undefined;
|
|
135
|
+
[key: string]: unknown;
|
|
136
|
+
};
|
|
137
|
+
getBatchActionProps: (getBatchActionPropsArgs?: {
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
}) => {
|
|
140
|
+
onCancel: () => void;
|
|
141
|
+
shouldShowBatchActions: boolean;
|
|
142
|
+
totalSelected: number;
|
|
143
|
+
[key: string]: unknown;
|
|
144
|
+
};
|
|
145
|
+
getTableProps: () => {
|
|
146
|
+
experimentalAutoAlign?: boolean;
|
|
147
|
+
isSortable?: boolean;
|
|
148
|
+
overflowMenuOnHover: boolean;
|
|
149
|
+
size: DataTableSize;
|
|
150
|
+
stickyHeader?: boolean;
|
|
151
|
+
useStaticWidth?: boolean;
|
|
152
|
+
useZebraStyles?: boolean;
|
|
153
|
+
};
|
|
154
|
+
getTableContainerProps: () => {
|
|
155
|
+
stickyHeader?: boolean;
|
|
156
|
+
useStaticWidth?: boolean;
|
|
157
|
+
};
|
|
158
|
+
onInputChange: (e: Event, defaultValue?: string) => void;
|
|
159
|
+
sortBy: (headerKey: string) => void;
|
|
160
|
+
selectAll: () => void;
|
|
161
|
+
selectRow: (rowId: string) => void;
|
|
162
|
+
expandRow: (rowId: string) => void;
|
|
163
|
+
expandAll: () => void;
|
|
164
|
+
radio: boolean | undefined;
|
|
165
|
+
}
|
|
166
|
+
export interface DataTableProps {
|
|
167
|
+
children?: (renderProps: DataTableRenderProps) => React.ReactElement;
|
|
168
|
+
experimentalAutoAlign?: boolean;
|
|
169
|
+
filterRows?: (filterRowsArgs: {
|
|
170
|
+
cellsById: Record<string, DataTableCell>;
|
|
171
|
+
getCellId: (rowId: string, header: string) => string;
|
|
172
|
+
headers: Array<DataTableHeader>;
|
|
173
|
+
inputValue: string;
|
|
174
|
+
rowIds: Array<string>;
|
|
175
|
+
}) => Array<string>;
|
|
176
|
+
headers: Array<DataTableHeader>;
|
|
177
|
+
isSortable?: boolean;
|
|
178
|
+
locale?: string;
|
|
179
|
+
overflowMenuOnHover?: boolean;
|
|
180
|
+
radio?: boolean;
|
|
181
|
+
render?: (renderProps: DataTableRenderProps) => React.ReactElement;
|
|
182
|
+
rows: Array<Omit<DataTableRow, 'cells'>>;
|
|
183
|
+
size?: DataTableSize;
|
|
184
|
+
sortRow?: (cellA: DataTableCell, cellB: DataTableCell, sortRowOptions: {
|
|
185
|
+
sortDirection: DataTableSortState;
|
|
186
|
+
sortStates: Record<DataTableSortState, DataTableSortState>;
|
|
187
|
+
locale: string;
|
|
188
|
+
}) => number;
|
|
189
|
+
stickyHeader?: boolean;
|
|
190
|
+
translateWithId?: (id: string) => string;
|
|
191
|
+
useStaticWidth?: boolean;
|
|
192
|
+
useZebraStyles?: boolean;
|
|
193
|
+
}
|
|
194
|
+
interface DataTableState {
|
|
195
|
+
cellsById: Record<string, DataTableCell>;
|
|
196
|
+
filterInputValue: string | null;
|
|
197
|
+
initialRowOrder: Array<string>;
|
|
198
|
+
isExpandedAll: boolean;
|
|
199
|
+
rowIds: Array<string>;
|
|
200
|
+
rowsById: Record<string, DataTableRow>;
|
|
201
|
+
shouldShowBatchActions: boolean;
|
|
202
|
+
sortDirection: DataTableSortState;
|
|
203
|
+
sortHeaderKey: string | null;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Data Tables are used to represent a collection of resources, displaying a
|
|
207
|
+
* subset of their fields in columns, or headers. We prioritize direct updates
|
|
208
|
+
* to the state of what we're rendering, so internally we end up normalizing the
|
|
209
|
+
* given data and then denormalizing it when rendering.
|
|
210
|
+
*
|
|
211
|
+
* As a result, each part of the DataTable is accessible through look-up by id,
|
|
212
|
+
* and updating the state of the single entity will cascade updates to the
|
|
213
|
+
* consumer.
|
|
214
|
+
*/
|
|
215
|
+
declare class DataTable extends React.Component<DataTableProps & typeof dataTableDefaultProps, DataTableState> {
|
|
216
|
+
instanceId: number;
|
|
217
|
+
static defaultProps: {
|
|
218
|
+
filterRows: ({ rowIds, headers, cellsById, inputValue, getCellId, }: {
|
|
219
|
+
rowIds: string[];
|
|
220
|
+
headers: any[];
|
|
221
|
+
cellsById: any;
|
|
222
|
+
inputValue: string;
|
|
223
|
+
getCellId: Function;
|
|
224
|
+
}) => string[];
|
|
225
|
+
locale: string;
|
|
226
|
+
overflowMenuOnHover: boolean;
|
|
227
|
+
size: string;
|
|
228
|
+
sortRow: (cellA: any, cellB: any, { sortDirection, sortStates, locale }: {
|
|
229
|
+
sortDirection: any;
|
|
230
|
+
sortStates: any;
|
|
231
|
+
locale: any;
|
|
232
|
+
}) => number;
|
|
233
|
+
translateWithId: (id: any) => string;
|
|
234
|
+
};
|
|
235
|
+
static propTypes: {
|
|
236
|
+
/**
|
|
237
|
+
* Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
|
|
238
|
+
*/
|
|
239
|
+
experimentalAutoAlign: PropTypes.Requireable<boolean>;
|
|
240
|
+
/**
|
|
241
|
+
* Optional hook to manually control filtering of the rows from the
|
|
242
|
+
* TableToolbarSearch component
|
|
243
|
+
*/
|
|
244
|
+
filterRows: PropTypes.Requireable<(...args: any[]) => any>;
|
|
245
|
+
/**
|
|
246
|
+
* The `headers` prop represents the order in which the headers should
|
|
247
|
+
* appear in the table. We expect an array of objects to be passed in, where
|
|
248
|
+
* `key` is the name of the key in a row object, and `header` is the name of
|
|
249
|
+
* the header.
|
|
250
|
+
*/
|
|
251
|
+
headers: PropTypes.Validator<(PropTypes.InferProps<{
|
|
252
|
+
key: PropTypes.Validator<string>;
|
|
253
|
+
header: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
|
|
254
|
+
}> | null | undefined)[]>;
|
|
255
|
+
/**
|
|
256
|
+
* Specify whether the table should be able to be sorted by its headers
|
|
257
|
+
*/
|
|
258
|
+
isSortable: PropTypes.Requireable<boolean>;
|
|
259
|
+
/**
|
|
260
|
+
* Provide a string for the current locale
|
|
261
|
+
*/
|
|
262
|
+
locale: PropTypes.Requireable<string>;
|
|
263
|
+
/**
|
|
264
|
+
* Specify whether the overflow menu (if it exists) should be shown always, or only on hover
|
|
265
|
+
*/
|
|
266
|
+
overflowMenuOnHover: PropTypes.Requireable<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* Specify whether the control should be a radio button or inline checkbox
|
|
269
|
+
*/
|
|
270
|
+
radio: PropTypes.Requireable<boolean>;
|
|
271
|
+
/**
|
|
272
|
+
* The `rows` prop is where you provide us with a list of all the rows that
|
|
273
|
+
* you want to render in the table. The only hard requirement is that this
|
|
274
|
+
* is an array of objects, and that each object has a unique `id` field
|
|
275
|
+
* available on it.
|
|
276
|
+
*/
|
|
277
|
+
rows: PropTypes.Validator<(PropTypes.InferProps<{
|
|
278
|
+
id: PropTypes.Validator<string>;
|
|
279
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
280
|
+
isSelected: PropTypes.Requireable<boolean>;
|
|
281
|
+
isExpanded: PropTypes.Requireable<boolean>;
|
|
282
|
+
}> | null | undefined)[]>;
|
|
283
|
+
/**
|
|
284
|
+
* Change the row height of table. Currently supports `xs`, `sm`, `md`, `lg`, and `xl`.
|
|
285
|
+
*/
|
|
286
|
+
size: PropTypes.Requireable<string>;
|
|
287
|
+
/**
|
|
288
|
+
* Optional hook to manually control sorting of the rows.
|
|
289
|
+
*/
|
|
290
|
+
sortRow: PropTypes.Requireable<(...args: any[]) => any>;
|
|
291
|
+
/**
|
|
292
|
+
* Specify whether the header should be sticky.
|
|
293
|
+
* Still experimental: may not work with every combination of table props
|
|
294
|
+
*/
|
|
295
|
+
stickyHeader: PropTypes.Requireable<boolean>;
|
|
296
|
+
/**
|
|
297
|
+
* Optional method that takes in a message id and returns an
|
|
298
|
+
* internationalized string. See `DataTable.translationKeys` for all
|
|
299
|
+
* available message ids.
|
|
300
|
+
*/
|
|
301
|
+
translateWithId: PropTypes.Requireable<(...args: any[]) => any>;
|
|
302
|
+
/**
|
|
303
|
+
* `false` If true, will use a width of 'auto' instead of 100%
|
|
304
|
+
*/
|
|
305
|
+
useStaticWidth: PropTypes.Requireable<boolean>;
|
|
306
|
+
/**
|
|
307
|
+
* `true` to add useZebraStyles striping.
|
|
308
|
+
*/
|
|
309
|
+
useZebraStyles: PropTypes.Requireable<boolean>;
|
|
310
|
+
};
|
|
311
|
+
static translationKeys: string[];
|
|
312
|
+
static Table: typeof Table;
|
|
313
|
+
static TableActionList: typeof TableActionList;
|
|
314
|
+
static TableBatchAction: typeof TableBatchAction;
|
|
315
|
+
static TableBatchActions: typeof TableBatchActions;
|
|
316
|
+
static TableBody: typeof TableBody;
|
|
317
|
+
static TableCell: typeof TableCell;
|
|
318
|
+
static TableContainer: typeof TableContainer;
|
|
319
|
+
static TableExpandHeader: typeof TableExpandHeader;
|
|
320
|
+
static TableExpandRow: typeof TableExpandRow;
|
|
321
|
+
static TableExpandedRow: typeof TableExpandedRow;
|
|
322
|
+
static TableHead: typeof TableHead;
|
|
323
|
+
static TableHeader: typeof TableHeader;
|
|
324
|
+
static TableRow: typeof TableRow;
|
|
325
|
+
static TableSelectAll: typeof TableSelectAll;
|
|
326
|
+
static TableSelectRow: typeof TableSelectRow;
|
|
327
|
+
static TableToolbar: typeof TableToolbar;
|
|
328
|
+
static TableToolbarAction: typeof TableToolbarAction;
|
|
329
|
+
static TableToolbarContent: typeof TableToolbarContent;
|
|
330
|
+
static TableToolbarSearch: typeof TableToolbarSearch;
|
|
331
|
+
static TableToolbarMenu: typeof TableToolbarMenu;
|
|
332
|
+
constructor(props: any);
|
|
333
|
+
shouldComponentUpdate(nextProps: any): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Get the props associated with the given header. Mostly used for adding in
|
|
336
|
+
* sorting behavior.
|
|
337
|
+
*
|
|
338
|
+
* @param {object} config
|
|
339
|
+
* @param {string} config.header the header we want the props for
|
|
340
|
+
* @param {Function} config.onClick a custom click handler for the header
|
|
341
|
+
* @param {boolean} config.isSortable
|
|
342
|
+
* @returns {object}
|
|
343
|
+
*/
|
|
344
|
+
getHeaderProps: ({ header, onClick, isSortable, ...rest }: {
|
|
345
|
+
[key: string]: unknown;
|
|
346
|
+
header: DataTableHeader;
|
|
347
|
+
onClick?: ((e: MouseEvent, sortState: {
|
|
348
|
+
sortHeaderKey: string;
|
|
349
|
+
sortDirection: DataTableSortState;
|
|
350
|
+
}) => void) | undefined;
|
|
351
|
+
isSortable?: boolean | undefined;
|
|
352
|
+
}) => {
|
|
353
|
+
key: string;
|
|
354
|
+
sortDirection: DataTableSortState;
|
|
355
|
+
isSortable: boolean | undefined;
|
|
356
|
+
isSortHeader: boolean;
|
|
357
|
+
onClick: (event: any) => void;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Get the props associated with the given expand header.
|
|
361
|
+
*
|
|
362
|
+
* @param {object} config
|
|
363
|
+
* @param {Function} config.onClick a custom click handler for the expand header
|
|
364
|
+
* @param {Function} config.onExpand a custom click handler called when header is expanded
|
|
365
|
+
* @returns {object}
|
|
366
|
+
*/
|
|
367
|
+
getExpandHeaderProps: ({ onClick, onExpand, ...rest }?: {
|
|
368
|
+
[key: string]: unknown;
|
|
369
|
+
onClick?: ((e: MouseEvent, expandState: {
|
|
370
|
+
isExpanded: boolean;
|
|
371
|
+
}) => void) | undefined;
|
|
372
|
+
onExpand?: ((e: MouseEvent) => void) | undefined;
|
|
373
|
+
}) => {
|
|
374
|
+
ariaLabel: string;
|
|
375
|
+
isExpanded: boolean;
|
|
376
|
+
onExpand: any;
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Decorate consumer's `onClick` event handler with sort parameters
|
|
380
|
+
*
|
|
381
|
+
* @param {Function} onClick
|
|
382
|
+
* @param {object} sortParams
|
|
383
|
+
* @returns {Function}
|
|
384
|
+
*/
|
|
385
|
+
handleOnHeaderClick: (onClick: any, sortParams: any) => (e: any) => any;
|
|
386
|
+
/**
|
|
387
|
+
* Decorate consumer's `onClick` event handler with sort parameters
|
|
388
|
+
*
|
|
389
|
+
* @param {Function} onClick
|
|
390
|
+
* @param {object} expandParams
|
|
391
|
+
* @returns {Function}
|
|
392
|
+
*/
|
|
393
|
+
handleOnExpandHeaderClick: (onClick: any, expandParams: any) => (e: any) => any;
|
|
394
|
+
/**
|
|
395
|
+
* Get the props associated with the given row. Mostly used for expansion.
|
|
396
|
+
*
|
|
397
|
+
* @param {object} config
|
|
398
|
+
* @param {object} config.row the row we want the props for
|
|
399
|
+
* @param {Function} config.onClick a custom click handler for the header
|
|
400
|
+
* @returns {object}
|
|
401
|
+
*/
|
|
402
|
+
getRowProps: ({ row, onClick, ...rest }: {
|
|
403
|
+
[key: string]: unknown;
|
|
404
|
+
onClick?: ((e: MouseEvent) => void) | undefined;
|
|
405
|
+
row: DataTableRow;
|
|
406
|
+
}) => {
|
|
407
|
+
key: string;
|
|
408
|
+
onExpand: any;
|
|
409
|
+
isExpanded: boolean | undefined;
|
|
410
|
+
ariaLabel: string;
|
|
411
|
+
isSelected: boolean | undefined;
|
|
412
|
+
disabled: boolean | undefined;
|
|
413
|
+
};
|
|
414
|
+
/**
|
|
415
|
+
* Gets the props associated with selection for a header or a row, where
|
|
416
|
+
* applicable. Most often used to indicate selection status of the table or
|
|
417
|
+
* for a specific row.
|
|
418
|
+
*
|
|
419
|
+
* @param {object} [row] an optional row that we want to access the props for
|
|
420
|
+
* @param {Function} row.onClick
|
|
421
|
+
* @param {object} row.row
|
|
422
|
+
* @returns {object}
|
|
423
|
+
*/
|
|
424
|
+
getSelectionProps: ({ onClick, row, ...rest }?: {
|
|
425
|
+
[key: string]: unknown;
|
|
426
|
+
onClick?: ((e: MouseEvent) => void) | undefined;
|
|
427
|
+
row: DataTableRow;
|
|
428
|
+
}) => {
|
|
429
|
+
checked: boolean | undefined;
|
|
430
|
+
onSelect: any;
|
|
431
|
+
id: string;
|
|
432
|
+
name: string;
|
|
433
|
+
ariaLabel: string;
|
|
434
|
+
disabled: boolean | undefined;
|
|
435
|
+
radio: true | null;
|
|
436
|
+
} | {
|
|
437
|
+
ariaLabel: string;
|
|
438
|
+
checked: boolean;
|
|
439
|
+
id: string;
|
|
440
|
+
indeterminate: boolean;
|
|
441
|
+
name: string;
|
|
442
|
+
onSelect: any;
|
|
443
|
+
};
|
|
444
|
+
getToolbarProps: (props?: {}) => {
|
|
445
|
+
[key: string]: unknown;
|
|
446
|
+
size: 'sm' | undefined;
|
|
447
|
+
};
|
|
448
|
+
getBatchActionProps: (props?: {}) => {
|
|
449
|
+
shouldShowBatchActions: boolean;
|
|
450
|
+
totalSelected: number;
|
|
451
|
+
onCancel: () => void;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Helper utility to get the Table Props.
|
|
455
|
+
*/
|
|
456
|
+
getTableProps: () => {
|
|
457
|
+
useZebraStyles: boolean | undefined;
|
|
458
|
+
size: "sm" | "md" | "lg" | "xl" | "xs";
|
|
459
|
+
isSortable: boolean | undefined;
|
|
460
|
+
useStaticWidth: boolean | undefined;
|
|
461
|
+
stickyHeader: boolean | undefined;
|
|
462
|
+
overflowMenuOnHover: boolean;
|
|
463
|
+
experimentalAutoAlign: boolean | undefined;
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Helper utility to get the TableContainer Props.
|
|
467
|
+
*/
|
|
468
|
+
getTableContainerProps: () => {
|
|
469
|
+
stickyHeader: boolean | undefined;
|
|
470
|
+
useStaticWidth: boolean | undefined;
|
|
471
|
+
};
|
|
472
|
+
/**
|
|
473
|
+
* Helper utility to get all the currently selected rows
|
|
474
|
+
* @returns {Array<string>} the array of rowIds that are currently selected
|
|
475
|
+
*/
|
|
476
|
+
getSelectedRows: () => string[];
|
|
477
|
+
/**
|
|
478
|
+
* Helper utility to get all of the available rows after applying the filter
|
|
479
|
+
* @returns {Array<string>} the array of rowIds that are currently included through the filter
|
|
480
|
+
* */
|
|
481
|
+
getFilteredRowIds: () => string[];
|
|
482
|
+
/**
|
|
483
|
+
* Helper for getting the table prefix for elements that require an
|
|
484
|
+
* `id` attribute that is unique.
|
|
485
|
+
*
|
|
486
|
+
* @returns {string}
|
|
487
|
+
*/
|
|
488
|
+
getTablePrefix: () => string;
|
|
489
|
+
/**
|
|
490
|
+
* Helper for toggling all selected items in a state. Does not call
|
|
491
|
+
* setState, so use it when setting state.
|
|
492
|
+
* @param {object} initialState
|
|
493
|
+
* @returns {object} object to put into this.setState (use spread operator)
|
|
494
|
+
*/
|
|
495
|
+
setAllSelectedState: (initialState: any, isSelected: any, filteredRowIds: any) => {
|
|
496
|
+
rowsById: any;
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Handler for the `onCancel` event to hide the batch action bar and
|
|
500
|
+
* deselect all selected rows
|
|
501
|
+
*/
|
|
502
|
+
handleOnCancel: () => void;
|
|
503
|
+
/**
|
|
504
|
+
* Handler for toggling the selection state of all rows in the database
|
|
505
|
+
*/
|
|
506
|
+
handleSelectAll: () => void;
|
|
507
|
+
/**
|
|
508
|
+
* Handler for toggling the selection state of a given row.
|
|
509
|
+
*
|
|
510
|
+
* @param {string} rowId
|
|
511
|
+
* @returns {Function}
|
|
512
|
+
*/
|
|
513
|
+
handleOnSelectRow: (rowId: any) => () => void;
|
|
514
|
+
/**
|
|
515
|
+
* Handler for toggling the expansion state of a given row.
|
|
516
|
+
*
|
|
517
|
+
* @param {string} rowId
|
|
518
|
+
* @returns {Function}
|
|
519
|
+
*/
|
|
520
|
+
handleOnExpandRow: (rowId: any) => () => void;
|
|
521
|
+
/**
|
|
522
|
+
* Handler for changing the expansion state of all rows.
|
|
523
|
+
*/
|
|
524
|
+
handleOnExpandAll: () => void;
|
|
525
|
+
/**
|
|
526
|
+
* Handler for transitioning to the next sort state of the table
|
|
527
|
+
*
|
|
528
|
+
* @param {string} headerKey the field for the header that we are sorting by
|
|
529
|
+
* @returns {Function}
|
|
530
|
+
*/
|
|
531
|
+
handleSortBy: (headerKey: any) => () => void;
|
|
532
|
+
/**
|
|
533
|
+
* Event handler for transitioning input value state changes for the table
|
|
534
|
+
* filter component.
|
|
535
|
+
*
|
|
536
|
+
* @param {Event} event
|
|
537
|
+
*/
|
|
538
|
+
handleOnInputValueChange: (event: any, defaultValue: any) => void;
|
|
539
|
+
render(): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
|
|
540
|
+
}
|
|
541
|
+
export default DataTable;
|
|
@@ -60,7 +60,14 @@ const defaultTranslations = {
|
|
|
60
60
|
[translationKeys.unselectRow]: 'Unselect row'
|
|
61
61
|
};
|
|
62
62
|
const translateWithId = id => defaultTranslations[id];
|
|
63
|
-
|
|
63
|
+
const dataTableDefaultProps = {
|
|
64
|
+
filterRows: defaultFilterRows,
|
|
65
|
+
locale: 'en',
|
|
66
|
+
overflowMenuOnHover: true,
|
|
67
|
+
size: 'lg',
|
|
68
|
+
sortRow: defaultSortRow,
|
|
69
|
+
translateWithId
|
|
70
|
+
};
|
|
64
71
|
/**
|
|
65
72
|
* Data Tables are used to represent a collection of resources, displaying a
|
|
66
73
|
* subset of their fields in columns, or headers. We prioritize direct updates
|
|
@@ -76,6 +83,7 @@ class DataTable extends React__default.Component {
|
|
|
76
83
|
var _this;
|
|
77
84
|
super(_props);
|
|
78
85
|
_this = this;
|
|
86
|
+
_defineProperty(this, "instanceId", void 0);
|
|
79
87
|
/**
|
|
80
88
|
* Get the props associated with the given header. Mostly used for adding in
|
|
81
89
|
* sorting behavior.
|
|
@@ -146,9 +154,9 @@ class DataTable extends React__default.Component {
|
|
|
146
154
|
isExpanded,
|
|
147
155
|
// Compose the event handlers so we don't overwrite a consumer's `onClick`
|
|
148
156
|
// handler
|
|
149
|
-
onExpand: composeEventHandlers([_this.handleOnExpandAll, onExpand, onClick
|
|
157
|
+
onExpand: composeEventHandlers([_this.handleOnExpandAll, onExpand, onClick && _this.handleOnExpandHeaderClick(onClick, {
|
|
150
158
|
isExpanded
|
|
151
|
-
})
|
|
159
|
+
})])
|
|
152
160
|
};
|
|
153
161
|
});
|
|
154
162
|
/**
|
|
@@ -258,7 +266,7 @@ class DataTable extends React__default.Component {
|
|
|
258
266
|
const {
|
|
259
267
|
size
|
|
260
268
|
} = _this.props;
|
|
261
|
-
|
|
269
|
+
const isSmall = size === 'xs' || size === 'sm';
|
|
262
270
|
return {
|
|
263
271
|
...props,
|
|
264
272
|
size: isSmall ? 'sm' : undefined
|
|
@@ -602,6 +610,7 @@ class DataTable extends React__default.Component {
|
|
|
602
610
|
return null;
|
|
603
611
|
}
|
|
604
612
|
}
|
|
613
|
+
_defineProperty(DataTable, "defaultProps", dataTableDefaultProps);
|
|
605
614
|
_defineProperty(DataTable, "propTypes", {
|
|
606
615
|
/**
|
|
607
616
|
* Experimental property. Allows table to align cell contents to the top if there is text wrapping in the content. Might have performance issues, intended for smaller tables
|
|
@@ -678,15 +687,28 @@ _defineProperty(DataTable, "propTypes", {
|
|
|
678
687
|
*/
|
|
679
688
|
useZebraStyles: PropTypes.bool
|
|
680
689
|
});
|
|
681
|
-
_defineProperty(DataTable, "defaultProps", {
|
|
682
|
-
sortRow: defaultSortRow,
|
|
683
|
-
filterRows: defaultFilterRows,
|
|
684
|
-
locale: 'en',
|
|
685
|
-
size: 'lg',
|
|
686
|
-
overflowMenuOnHover: true,
|
|
687
|
-
translateWithId
|
|
688
|
-
});
|
|
689
690
|
_defineProperty(DataTable, "translationKeys", Object.values(translationKeys));
|
|
691
|
+
// Static properties for sub-components
|
|
692
|
+
_defineProperty(DataTable, "Table", void 0);
|
|
693
|
+
_defineProperty(DataTable, "TableActionList", void 0);
|
|
694
|
+
_defineProperty(DataTable, "TableBatchAction", void 0);
|
|
695
|
+
_defineProperty(DataTable, "TableBatchActions", void 0);
|
|
696
|
+
_defineProperty(DataTable, "TableBody", void 0);
|
|
697
|
+
_defineProperty(DataTable, "TableCell", void 0);
|
|
698
|
+
_defineProperty(DataTable, "TableContainer", void 0);
|
|
699
|
+
_defineProperty(DataTable, "TableExpandHeader", void 0);
|
|
700
|
+
_defineProperty(DataTable, "TableExpandRow", void 0);
|
|
701
|
+
_defineProperty(DataTable, "TableExpandedRow", void 0);
|
|
702
|
+
_defineProperty(DataTable, "TableHead", void 0);
|
|
703
|
+
_defineProperty(DataTable, "TableHeader", void 0);
|
|
704
|
+
_defineProperty(DataTable, "TableRow", void 0);
|
|
705
|
+
_defineProperty(DataTable, "TableSelectAll", void 0);
|
|
706
|
+
_defineProperty(DataTable, "TableSelectRow", void 0);
|
|
707
|
+
_defineProperty(DataTable, "TableToolbar", void 0);
|
|
708
|
+
_defineProperty(DataTable, "TableToolbarAction", void 0);
|
|
709
|
+
_defineProperty(DataTable, "TableToolbarContent", void 0);
|
|
710
|
+
_defineProperty(DataTable, "TableToolbarSearch", void 0);
|
|
711
|
+
_defineProperty(DataTable, "TableToolbarMenu", void 0);
|
|
690
712
|
DataTable.Table = Table;
|
|
691
713
|
DataTable.TableActionList = TableActionList;
|
|
692
714
|
DataTable.TableBatchAction = TableBatchAction;
|
|
@@ -707,6 +729,5 @@ DataTable.TableToolbarAction = TableToolbarAction;
|
|
|
707
729
|
DataTable.TableToolbarContent = TableToolbarContent;
|
|
708
730
|
DataTable.TableToolbarSearch = TableToolbarSearch;
|
|
709
731
|
DataTable.TableToolbarMenu = TableToolbarMenu;
|
|
710
|
-
var DataTable$1 = DataTable;
|
|
711
732
|
|
|
712
|
-
export { DataTable
|
|
733
|
+
export { DataTable as default };
|