@carbon/react 1.73.0-rc.0 → 1.73.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/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +863 -863
- package/es/components/DataTable/DataTable.d.ts +8 -2
- package/es/components/DataTable/DataTable.js +6 -1
- package/es/components/DataTable/TableCell.d.ts +1 -1
- package/es/components/DataTable/TableCell.js +2 -2
- package/es/components/DataTable/TableDecoratorRow.d.ts +33 -0
- package/es/components/DataTable/TableDecoratorRow.js +48 -0
- package/es/components/DataTable/TableExpandRow.js +9 -9
- package/es/components/DataTable/TableHeader.d.ts +6 -1
- package/es/components/DataTable/TableHeader.js +20 -11
- package/es/components/DataTable/TableRow.js +5 -5
- package/es/components/DataTable/TableSlugRow.js +5 -1
- package/es/components/DataTable/index.d.ts +2 -1
- package/es/components/DataTable/index.js +3 -0
- package/es/components/DataTable/tools/normalize.js +3 -2
- package/es/index.js +1 -0
- package/es/prop-types/deprecateComponent.js +22 -0
- package/lib/components/DataTable/DataTable.d.ts +8 -2
- package/lib/components/DataTable/DataTable.js +6 -1
- package/lib/components/DataTable/TableCell.d.ts +1 -1
- package/lib/components/DataTable/TableCell.js +2 -2
- package/lib/components/DataTable/TableDecoratorRow.d.ts +33 -0
- package/lib/components/DataTable/TableDecoratorRow.js +58 -0
- package/lib/components/DataTable/TableExpandRow.js +9 -9
- package/lib/components/DataTable/TableHeader.d.ts +6 -1
- package/lib/components/DataTable/TableHeader.js +20 -11
- package/lib/components/DataTable/TableRow.js +5 -5
- package/lib/components/DataTable/TableSlugRow.js +4 -0
- package/lib/components/DataTable/index.d.ts +2 -1
- package/lib/components/DataTable/index.js +3 -0
- package/lib/components/DataTable/tools/normalize.js +3 -2
- package/lib/index.js +2 -0
- package/lib/prop-types/deprecateComponent.js +26 -0
- package/package.json +4 -4
|
@@ -15,6 +15,7 @@ import TableBatchActions from './TableBatchActions';
|
|
|
15
15
|
import TableBody from './TableBody';
|
|
16
16
|
import TableCell from './TableCell';
|
|
17
17
|
import TableContainer from './TableContainer';
|
|
18
|
+
import TableDecoratorRow from './TableDecoratorRow';
|
|
18
19
|
import TableExpandHeader from './TableExpandHeader';
|
|
19
20
|
import TableExpandRow from './TableExpandRow';
|
|
20
21
|
import TableExpandedRow from './TableExpandedRow';
|
|
@@ -70,6 +71,7 @@ export interface DataTableHeader {
|
|
|
70
71
|
key: string;
|
|
71
72
|
header: React.ReactNode;
|
|
72
73
|
slug?: React.ReactElement;
|
|
74
|
+
decorator?: React.ReactElement;
|
|
73
75
|
}
|
|
74
76
|
export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
|
|
75
77
|
headers: Array<DataTableHeader>;
|
|
@@ -174,7 +176,8 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
|
|
|
174
176
|
cell: DataTableCell<ColTypes>;
|
|
175
177
|
}) => {
|
|
176
178
|
[key: string]: unknown;
|
|
177
|
-
|
|
179
|
+
hasAILabelHeader?: boolean;
|
|
180
|
+
hasDecoratorHeader?: boolean;
|
|
178
181
|
};
|
|
179
182
|
onInputChange: (e: React.ChangeEvent<HTMLInputElement>, defaultValue?: string) => void;
|
|
180
183
|
sortBy: (headerKey: string) => void;
|
|
@@ -318,6 +321,7 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
|
|
|
318
321
|
static TableBody: typeof TableBody;
|
|
319
322
|
static TableCell: typeof TableCell;
|
|
320
323
|
static TableContainer: typeof TableContainer;
|
|
324
|
+
static TableDecoratorRow: typeof TableDecoratorRow;
|
|
321
325
|
static TableExpandHeader: typeof TableExpandHeader;
|
|
322
326
|
static TableExpandRow: typeof TableExpandRow;
|
|
323
327
|
static TableExpandedRow: typeof TableExpandedRow;
|
|
@@ -358,6 +362,7 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
|
|
|
358
362
|
isSortable: boolean | undefined;
|
|
359
363
|
isSortHeader: boolean;
|
|
360
364
|
slug: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
365
|
+
decorator: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
361
366
|
onClick: (event: any) => void;
|
|
362
367
|
};
|
|
363
368
|
/**
|
|
@@ -505,7 +510,8 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
|
|
|
505
510
|
[x: string]: any;
|
|
506
511
|
cell: any;
|
|
507
512
|
}) => {
|
|
508
|
-
|
|
513
|
+
hasAILabelHeader: any;
|
|
514
|
+
hasDecoratorHeader: any;
|
|
509
515
|
};
|
|
510
516
|
/**
|
|
511
517
|
* Helper utility to get all the currently selected rows
|
|
@@ -23,6 +23,7 @@ import TableBatchActions from './TableBatchActions.js';
|
|
|
23
23
|
import TableBody from './TableBody.js';
|
|
24
24
|
import TableCell from './TableCell.js';
|
|
25
25
|
import TableContainer from './TableContainer.js';
|
|
26
|
+
import TableDecoratorRow from './TableDecoratorRow.js';
|
|
26
27
|
import TableExpandHeader from './TableExpandHeader.js';
|
|
27
28
|
import TableExpandRow from './TableExpandRow.js';
|
|
28
29
|
import TableExpandedRow from './TableExpandedRow.js';
|
|
@@ -109,6 +110,7 @@ class DataTable extends React__default.Component {
|
|
|
109
110
|
isSortable,
|
|
110
111
|
isSortHeader: sortHeaderKey === header.key,
|
|
111
112
|
slug: header.slug,
|
|
113
|
+
decorator: header.decorator,
|
|
112
114
|
onClick: event => {
|
|
113
115
|
const nextSortState = getNextSortState(this.props, this.state, {
|
|
114
116
|
key: header.key
|
|
@@ -363,7 +365,8 @@ class DataTable extends React__default.Component {
|
|
|
363
365
|
} = _ref4;
|
|
364
366
|
return {
|
|
365
367
|
...rest,
|
|
366
|
-
|
|
368
|
+
hasAILabelHeader: cell.hasAILabelHeader,
|
|
369
|
+
hasDecoratorHeader: cell.hasDecoratorHeader
|
|
367
370
|
};
|
|
368
371
|
});
|
|
369
372
|
/**
|
|
@@ -743,6 +746,7 @@ _defineProperty(DataTable, "TableBatchActions", void 0);
|
|
|
743
746
|
_defineProperty(DataTable, "TableBody", void 0);
|
|
744
747
|
_defineProperty(DataTable, "TableCell", void 0);
|
|
745
748
|
_defineProperty(DataTable, "TableContainer", void 0);
|
|
749
|
+
_defineProperty(DataTable, "TableDecoratorRow", void 0);
|
|
746
750
|
_defineProperty(DataTable, "TableExpandHeader", void 0);
|
|
747
751
|
_defineProperty(DataTable, "TableExpandRow", void 0);
|
|
748
752
|
_defineProperty(DataTable, "TableExpandedRow", void 0);
|
|
@@ -764,6 +768,7 @@ DataTable.TableBatchActions = TableBatchActions;
|
|
|
764
768
|
DataTable.TableBody = TableBody;
|
|
765
769
|
DataTable.TableCell = TableCell;
|
|
766
770
|
DataTable.TableContainer = TableContainer;
|
|
771
|
+
DataTable.TableDecoratorRow = TableDecoratorRow;
|
|
767
772
|
DataTable.TableExpandHeader = TableExpandHeader;
|
|
768
773
|
DataTable.TableExpandRow = TableExpandRow;
|
|
769
774
|
DataTable.TableExpandedRow = TableExpandedRow;
|
|
@@ -22,7 +22,7 @@ interface TableCellProps extends ReactAttr<HTMLTableCellElement> {
|
|
|
22
22
|
/**
|
|
23
23
|
* Specify if the table cell is in an AI column
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
hasAILabelHeader?: boolean;
|
|
26
26
|
/**
|
|
27
27
|
* The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
|
|
28
28
|
*/
|
|
@@ -14,13 +14,13 @@ const TableCell = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
14
14
|
let {
|
|
15
15
|
children,
|
|
16
16
|
className,
|
|
17
|
-
|
|
17
|
+
hasAILabelHeader,
|
|
18
18
|
colSpan,
|
|
19
19
|
...rest
|
|
20
20
|
} = _ref;
|
|
21
21
|
const prefix = usePrefix();
|
|
22
22
|
const tableCellClassNames = cx(className, {
|
|
23
|
-
[`${prefix}--table-cell--column-slug`]:
|
|
23
|
+
[`${prefix}--table-cell--column-slug`]: hasAILabelHeader
|
|
24
24
|
});
|
|
25
25
|
return /*#__PURE__*/React__default.createElement("td", _extends({
|
|
26
26
|
className: tableCellClassNames ? tableCellClassNames : undefined,
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { ReactNode } from 'react';
|
|
9
|
+
export interface TableDecoratorRowProps {
|
|
10
|
+
/**
|
|
11
|
+
* The CSS class names of the cell that wraps the underlying input control
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
|
|
16
|
+
*/
|
|
17
|
+
decorator?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
declare const TableDecoratorRow: {
|
|
20
|
+
({ className, decorator, }: TableDecoratorRowProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
displayName: string;
|
|
22
|
+
propTypes: {
|
|
23
|
+
/**
|
|
24
|
+
* The CSS class names of the cell that wraps the underlying input control
|
|
25
|
+
*/
|
|
26
|
+
className: PropTypes.Requireable<string>;
|
|
27
|
+
/**
|
|
28
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
|
|
29
|
+
*/
|
|
30
|
+
decorator: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export default TableDecoratorRow;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import React__default from 'react';
|
|
10
|
+
import cx from 'classnames';
|
|
11
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
12
|
+
|
|
13
|
+
const TableDecoratorRow = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
className,
|
|
16
|
+
decorator
|
|
17
|
+
} = _ref;
|
|
18
|
+
const prefix = usePrefix();
|
|
19
|
+
const TableDecoratorRowClasses = cx({
|
|
20
|
+
...(className && {
|
|
21
|
+
[className]: true
|
|
22
|
+
}),
|
|
23
|
+
[`${prefix}--table-column-decorator`]: true,
|
|
24
|
+
[`${prefix}--table-column-decorator--active`]: decorator
|
|
25
|
+
});
|
|
26
|
+
let normalizedDecorator = /*#__PURE__*/React__default.isValidElement(decorator) ? decorator : null;
|
|
27
|
+
if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
|
|
28
|
+
normalizedDecorator = /*#__PURE__*/React__default.cloneElement(normalizedDecorator, {
|
|
29
|
+
size: 'mini'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/React__default.createElement("td", {
|
|
33
|
+
className: TableDecoratorRowClasses
|
|
34
|
+
}, normalizedDecorator);
|
|
35
|
+
};
|
|
36
|
+
TableDecoratorRow.displayName = 'TableDecoratorRow';
|
|
37
|
+
TableDecoratorRow.propTypes = {
|
|
38
|
+
/**
|
|
39
|
+
* The CSS class names of the cell that wraps the underlying input control
|
|
40
|
+
*/
|
|
41
|
+
className: PropTypes.string,
|
|
42
|
+
/**
|
|
43
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
|
|
44
|
+
*/
|
|
45
|
+
decorator: PropTypes.node
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { TableDecoratorRow as default };
|
|
@@ -29,18 +29,18 @@ const TableExpandRow = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
29
29
|
} = _ref;
|
|
30
30
|
const prefix = usePrefix();
|
|
31
31
|
|
|
32
|
-
// We need to put the
|
|
33
|
-
let
|
|
34
|
-
const
|
|
35
|
-
if (child.type?.displayName === 'TableSlugRow') {
|
|
36
|
-
if (child.props.slug) {
|
|
37
|
-
|
|
32
|
+
// We need to put the AILabel and Decorator before the expansion arrow and all other table cells after the arrow.
|
|
33
|
+
let rowHasAILabel;
|
|
34
|
+
const decorator = React__default.Children.toArray(children).map(child => {
|
|
35
|
+
if (child.type?.displayName === 'TableSlugRow' || child.type?.displayName === 'TableDecoratorRow') {
|
|
36
|
+
if (child.props.slug || child.props.decorator?.type.displayName === 'AILabel') {
|
|
37
|
+
rowHasAILabel = true;
|
|
38
38
|
}
|
|
39
39
|
return child;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
const normalizedChildren = React__default.Children.toArray(children).map(child => {
|
|
43
|
-
if (child.type?.displayName !== 'TableSlugRow') {
|
|
43
|
+
if (child.type?.displayName !== 'TableSlugRow' && child.type?.displayName !== 'TableDecoratorRow') {
|
|
44
44
|
return child;
|
|
45
45
|
}
|
|
46
46
|
});
|
|
@@ -48,14 +48,14 @@ const TableExpandRow = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
48
48
|
[`${prefix}--parent-row`]: true,
|
|
49
49
|
[`${prefix}--expandable-row`]: isExpanded,
|
|
50
50
|
[`${prefix}--data-table--selected`]: isSelected,
|
|
51
|
-
[`${prefix}--data-table--slug-row`]:
|
|
51
|
+
[`${prefix}--data-table--slug-row ${prefix}--data-table--ai-label-row`]: rowHasAILabel
|
|
52
52
|
}, rowClassName);
|
|
53
53
|
const previousValue = isExpanded ? 'collapsed' : undefined;
|
|
54
54
|
return /*#__PURE__*/React__default.createElement("tr", _extends({}, rest, {
|
|
55
55
|
ref: ref,
|
|
56
56
|
className: className,
|
|
57
57
|
"data-parent-row": true
|
|
58
|
-
}),
|
|
58
|
+
}), decorator, /*#__PURE__*/React__default.createElement(TableCell, {
|
|
59
59
|
className: `${prefix}--table-expand`,
|
|
60
60
|
"data-previous-value": previousValue,
|
|
61
61
|
headers: expandHeader
|
|
@@ -58,9 +58,14 @@ interface TableHeaderProps extends ReactAttr<HTMLTableCellElement & HTMLButtonEl
|
|
|
58
58
|
*/
|
|
59
59
|
scope?: string;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* @deprecated please use decorator instead.
|
|
62
|
+
* Provide a `Slug` component to be rendered inside the `TableSlugRow` component
|
|
62
63
|
*/
|
|
63
64
|
slug?: ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
|
|
67
|
+
*/
|
|
68
|
+
decorator?: ReactNode;
|
|
64
69
|
/**
|
|
65
70
|
* Specify which direction we are currently sorting by, should be one of DESC,
|
|
66
71
|
* NONE, or ASC.
|
|
@@ -46,6 +46,7 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
|
|
|
46
46
|
className: headerClassName,
|
|
47
47
|
children,
|
|
48
48
|
colSpan,
|
|
49
|
+
decorator,
|
|
49
50
|
isSortable = false,
|
|
50
51
|
isSortHeader,
|
|
51
52
|
onClick,
|
|
@@ -59,18 +60,21 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
|
|
|
59
60
|
const prefix = usePrefix();
|
|
60
61
|
const uniqueId = useId('table-sort');
|
|
61
62
|
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
// AILabel is always size `mini`
|
|
64
|
+
const AILableRef = useRef(null);
|
|
65
|
+
let colHasAILabel;
|
|
66
|
+
let normalizedDecorator = /*#__PURE__*/React__default.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
|
|
67
|
+
if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
|
|
68
|
+
colHasAILabel = true;
|
|
69
|
+
normalizedDecorator = /*#__PURE__*/React__default.cloneElement(normalizedDecorator, {
|
|
67
70
|
size: 'mini',
|
|
68
|
-
ref:
|
|
71
|
+
ref: AILableRef
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
const headerLabelClassNames = cx({
|
|
72
75
|
[`${prefix}--table-header-label`]: true,
|
|
73
|
-
[`${prefix}--table-header-label--slug`]:
|
|
76
|
+
[`${prefix}--table-header-label--slug ${prefix}--table-header-label--ai-label`]: colHasAILabel,
|
|
77
|
+
[`${prefix}--table-header-label--decorator`]: decorator
|
|
74
78
|
});
|
|
75
79
|
if (!isSortable) {
|
|
76
80
|
return /*#__PURE__*/React__default.createElement("th", _extends({}, rest, {
|
|
@@ -81,7 +85,9 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
|
|
|
81
85
|
ref: ref
|
|
82
86
|
}), children ? /*#__PURE__*/React__default.createElement("div", {
|
|
83
87
|
className: headerLabelClassNames
|
|
84
|
-
}, children,
|
|
88
|
+
}, children, /*#__PURE__*/React__default.createElement("div", {
|
|
89
|
+
className: `${prefix}--table-header-label--decorator-inner`
|
|
90
|
+
}, normalizedDecorator)) : null);
|
|
85
91
|
}
|
|
86
92
|
const className = cx(headerClassName, {
|
|
87
93
|
[`${prefix}--table-sort`]: true,
|
|
@@ -96,10 +102,11 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
|
|
|
96
102
|
sortStates
|
|
97
103
|
});
|
|
98
104
|
const headerClasses = cx(headerClassName, `${prefix}--table-sort__header`, {
|
|
99
|
-
[`${prefix}--table-sort__header--
|
|
105
|
+
[`${prefix}--table-sort__header--ai-label`]: colHasAILabel,
|
|
106
|
+
[`${prefix}--table-sort__header--decorator`]: decorator
|
|
100
107
|
});
|
|
101
108
|
const handleClick = evt => {
|
|
102
|
-
if (
|
|
109
|
+
if (colHasAILabel && AILableRef.current && AILableRef.current.contains(evt.target)) {
|
|
103
110
|
return;
|
|
104
111
|
} else if (onClick) {
|
|
105
112
|
return onClick(evt);
|
|
@@ -130,7 +137,9 @@ const TableHeader = /*#__PURE__*/React__default.forwardRef(function TableHeader(
|
|
|
130
137
|
}), /*#__PURE__*/React__default.createElement(ArrowsVertical, {
|
|
131
138
|
size: 20,
|
|
132
139
|
className: `${prefix}--table-sort__icon-unsorted`
|
|
133
|
-
}),
|
|
140
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
141
|
+
className: `${prefix}--table-header-label--decorator-inner`
|
|
142
|
+
}, normalizedDecorator))));
|
|
134
143
|
});
|
|
135
144
|
TableHeader.propTypes = {
|
|
136
145
|
/**
|
|
@@ -12,12 +12,12 @@ import { usePrefix } from '../../internal/usePrefix.js';
|
|
|
12
12
|
|
|
13
13
|
const TableRow = props => {
|
|
14
14
|
const prefix = usePrefix();
|
|
15
|
-
let
|
|
15
|
+
let rowHasAILabel;
|
|
16
16
|
if (props?.children) {
|
|
17
17
|
React__default.Children.toArray(props.children).map(child => {
|
|
18
|
-
if (child.type?.displayName === 'TableSlugRow') {
|
|
19
|
-
if (child.props.slug) {
|
|
20
|
-
|
|
18
|
+
if (child.type?.displayName === 'TableSlugRow' || child.type?.displayName === 'TableDecoratorRow') {
|
|
19
|
+
if (child.props.slug || child.props.decorator?.type.displayName === 'AILabel') {
|
|
20
|
+
rowHasAILabel = true;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
});
|
|
@@ -26,7 +26,7 @@ const TableRow = props => {
|
|
|
26
26
|
// only useful in `TableExpandRow`
|
|
27
27
|
const className = cx(props.className, {
|
|
28
28
|
[`${prefix}--data-table--selected`]: props.isSelected,
|
|
29
|
-
[`${prefix}--data-table--slug-row`]:
|
|
29
|
+
[`${prefix}--data-table--slug-row ${prefix}--data-table--ai-label-row`]: rowHasAILabel
|
|
30
30
|
});
|
|
31
31
|
const {
|
|
32
32
|
ariaLabel,
|
|
@@ -6,15 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
|
-
import React__default from 'react';
|
|
9
|
+
import React__default, { useEffect } from 'react';
|
|
10
10
|
import cx from 'classnames';
|
|
11
11
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
12
|
+
import deprecateComponent from '../../prop-types/deprecateComponent.js';
|
|
12
13
|
|
|
13
14
|
const TableSlugRow = _ref => {
|
|
14
15
|
let {
|
|
15
16
|
className,
|
|
16
17
|
slug
|
|
17
18
|
} = _ref;
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
deprecateComponent('TableSlugRow', 'The `TableSlugRow` component has been deprecated and will be removed in the next major version. Use the TableDecoratorRow component instead.');
|
|
21
|
+
}, []);
|
|
18
22
|
const prefix = usePrefix();
|
|
19
23
|
const TableSlugRowClasses = cx({
|
|
20
24
|
...(className && {
|
|
@@ -13,6 +13,7 @@ import TableBody from './TableBody';
|
|
|
13
13
|
import TableCell from './TableCell';
|
|
14
14
|
import TableContainer from './TableContainer';
|
|
15
15
|
import TableExpandHeader from './TableExpandHeader';
|
|
16
|
+
import TableDecoratorRow from './TableDecoratorRow';
|
|
16
17
|
import TableExpandRow from './TableExpandRow';
|
|
17
18
|
import TableExpandedRow from './TableExpandedRow';
|
|
18
19
|
import TableHead from './TableHead';
|
|
@@ -27,5 +28,5 @@ import TableToolbarContent from './TableToolbarContent';
|
|
|
27
28
|
import TableToolbarSearch from './TableToolbarSearch';
|
|
28
29
|
import TableToolbarMenu from './TableToolbarMenu';
|
|
29
30
|
import type { DataTableSortState } from './state/sortStates';
|
|
30
|
-
export { DataTable, type DataTableCell, type DataTableHeader, type DataTableProps, type DataTableRenderProps, type DataTableSortState, type DataTableRow, type DataTableSize, Table, TableActionList, TableBatchAction, TableBatchActions, TableBody, TableCell, TableContainer, TableExpandHeader, TableExpandRow, TableExpandedRow, TableHead, TableHeader, type TableHeaderTranslationKey, type TableHeaderTranslationArgs, TableRow, TableSelectAll, TableSelectRow, TableSlugRow, TableToolbar, TableToolbarAction, TableToolbarContent, TableToolbarSearch, TableToolbarMenu, };
|
|
31
|
+
export { DataTable, type DataTableCell, type DataTableHeader, type DataTableProps, type DataTableRenderProps, type DataTableSortState, type DataTableRow, type DataTableSize, Table, TableActionList, TableBatchAction, TableBatchActions, TableBody, TableCell, TableContainer, TableDecoratorRow, TableExpandHeader, TableExpandRow, TableExpandedRow, TableHead, TableHeader, type TableHeaderTranslationKey, type TableHeaderTranslationArgs, TableRow, TableSelectAll, TableSelectRow, TableSlugRow, TableToolbar, TableToolbarAction, TableToolbarContent, TableToolbarSearch, TableToolbarMenu, };
|
|
31
32
|
export default DataTable;
|
|
@@ -23,6 +23,8 @@ import TableContainer from './TableContainer.js';
|
|
|
23
23
|
export { default as TableContainer } from './TableContainer.js';
|
|
24
24
|
import TableExpandHeader from './TableExpandHeader.js';
|
|
25
25
|
export { default as TableExpandHeader } from './TableExpandHeader.js';
|
|
26
|
+
import TableDecoratorRow from './TableDecoratorRow.js';
|
|
27
|
+
export { default as TableDecoratorRow } from './TableDecoratorRow.js';
|
|
26
28
|
import TableExpandRow from './TableExpandRow.js';
|
|
27
29
|
export { default as TableExpandRow } from './TableExpandRow.js';
|
|
28
30
|
import TableExpandedRow from './TableExpandedRow.js';
|
|
@@ -57,6 +59,7 @@ DataTable.TableBatchActions = TableBatchActions;
|
|
|
57
59
|
DataTable.TableBody = TableBody;
|
|
58
60
|
DataTable.TableCell = TableCell;
|
|
59
61
|
DataTable.TableContainer = TableContainer;
|
|
62
|
+
DataTable.TableDecoratorRow = TableDecoratorRow;
|
|
60
63
|
DataTable.TableExpandHeader = TableExpandHeader;
|
|
61
64
|
DataTable.TableExpandRow = TableExpandRow;
|
|
62
65
|
DataTable.TableExpandedRow = TableExpandedRow;
|
|
@@ -49,7 +49,8 @@ const normalize = function (rows, headers) {
|
|
|
49
49
|
headers.forEach((_ref, i) => {
|
|
50
50
|
let {
|
|
51
51
|
key,
|
|
52
|
-
slug
|
|
52
|
+
slug,
|
|
53
|
+
decorator
|
|
53
54
|
} = _ref;
|
|
54
55
|
const id = getCellId(row.id, key);
|
|
55
56
|
// Initialize the cell info and state values, namely for editing
|
|
@@ -60,7 +61,7 @@ const normalize = function (rows, headers) {
|
|
|
60
61
|
isEditing: false,
|
|
61
62
|
isValid: true,
|
|
62
63
|
errors: null,
|
|
63
|
-
|
|
64
|
+
hasAILabelHeader: !!(slug || decorator?.type?.displayName === 'AILabel'),
|
|
64
65
|
info: {
|
|
65
66
|
header: key
|
|
66
67
|
}
|
package/es/index.js
CHANGED
|
@@ -220,6 +220,7 @@ export { default as TableBatchActions } from './components/DataTable/TableBatchA
|
|
|
220
220
|
export { default as TableBody } from './components/DataTable/TableBody.js';
|
|
221
221
|
export { default as TableCell } from './components/DataTable/TableCell.js';
|
|
222
222
|
export { default as TableContainer } from './components/DataTable/TableContainer.js';
|
|
223
|
+
export { default as TableDecoratorRow } from './components/DataTable/TableDecoratorRow.js';
|
|
223
224
|
export { default as TableExpandHeader } from './components/DataTable/TableExpandHeader.js';
|
|
224
225
|
export { default as TableExpandRow } from './components/DataTable/TableExpandRow.js';
|
|
225
226
|
export { default as TableExpandedRow } from './components/DataTable/TableExpandedRow.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
|
|
8
|
+
import { warning } from '../internal/warning.js';
|
|
9
|
+
|
|
10
|
+
const didWarnAboutDeprecation = {};
|
|
11
|
+
function deprecateComponent(componentName, message) {
|
|
12
|
+
if (!componentName) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!didWarnAboutDeprecation[componentName]) {
|
|
16
|
+
didWarnAboutDeprecation[componentName] = true;
|
|
17
|
+
process.env.NODE_ENV !== "production" ? warning(false, message || `The ${componentName} component has been deprecated and will be removed in the next major release.`) : void 0;
|
|
18
|
+
}
|
|
19
|
+
return componentName;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { deprecateComponent as default };
|
|
@@ -15,6 +15,7 @@ import TableBatchActions from './TableBatchActions';
|
|
|
15
15
|
import TableBody from './TableBody';
|
|
16
16
|
import TableCell from './TableCell';
|
|
17
17
|
import TableContainer from './TableContainer';
|
|
18
|
+
import TableDecoratorRow from './TableDecoratorRow';
|
|
18
19
|
import TableExpandHeader from './TableExpandHeader';
|
|
19
20
|
import TableExpandRow from './TableExpandRow';
|
|
20
21
|
import TableExpandedRow from './TableExpandedRow';
|
|
@@ -70,6 +71,7 @@ export interface DataTableHeader {
|
|
|
70
71
|
key: string;
|
|
71
72
|
header: React.ReactNode;
|
|
72
73
|
slug?: React.ReactElement;
|
|
74
|
+
decorator?: React.ReactElement;
|
|
73
75
|
}
|
|
74
76
|
export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
|
|
75
77
|
headers: Array<DataTableHeader>;
|
|
@@ -174,7 +176,8 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
|
|
|
174
176
|
cell: DataTableCell<ColTypes>;
|
|
175
177
|
}) => {
|
|
176
178
|
[key: string]: unknown;
|
|
177
|
-
|
|
179
|
+
hasAILabelHeader?: boolean;
|
|
180
|
+
hasDecoratorHeader?: boolean;
|
|
178
181
|
};
|
|
179
182
|
onInputChange: (e: React.ChangeEvent<HTMLInputElement>, defaultValue?: string) => void;
|
|
180
183
|
sortBy: (headerKey: string) => void;
|
|
@@ -318,6 +321,7 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
|
|
|
318
321
|
static TableBody: typeof TableBody;
|
|
319
322
|
static TableCell: typeof TableCell;
|
|
320
323
|
static TableContainer: typeof TableContainer;
|
|
324
|
+
static TableDecoratorRow: typeof TableDecoratorRow;
|
|
321
325
|
static TableExpandHeader: typeof TableExpandHeader;
|
|
322
326
|
static TableExpandRow: typeof TableExpandRow;
|
|
323
327
|
static TableExpandedRow: typeof TableExpandedRow;
|
|
@@ -358,6 +362,7 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
|
|
|
358
362
|
isSortable: boolean | undefined;
|
|
359
363
|
isSortHeader: boolean;
|
|
360
364
|
slug: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
365
|
+
decorator: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
361
366
|
onClick: (event: any) => void;
|
|
362
367
|
};
|
|
363
368
|
/**
|
|
@@ -505,7 +510,8 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
|
|
|
505
510
|
[x: string]: any;
|
|
506
511
|
cell: any;
|
|
507
512
|
}) => {
|
|
508
|
-
|
|
513
|
+
hasAILabelHeader: any;
|
|
514
|
+
hasDecoratorHeader: any;
|
|
509
515
|
};
|
|
510
516
|
/**
|
|
511
517
|
* Helper utility to get all the currently selected rows
|
|
@@ -27,6 +27,7 @@ var TableBatchActions = require('./TableBatchActions.js');
|
|
|
27
27
|
var TableBody = require('./TableBody.js');
|
|
28
28
|
var TableCell = require('./TableCell.js');
|
|
29
29
|
var TableContainer = require('./TableContainer.js');
|
|
30
|
+
var TableDecoratorRow = require('./TableDecoratorRow.js');
|
|
30
31
|
var TableExpandHeader = require('./TableExpandHeader.js');
|
|
31
32
|
var TableExpandRow = require('./TableExpandRow.js');
|
|
32
33
|
var TableExpandedRow = require('./TableExpandedRow.js');
|
|
@@ -119,6 +120,7 @@ class DataTable extends React__default["default"].Component {
|
|
|
119
120
|
isSortable,
|
|
120
121
|
isSortHeader: sortHeaderKey === header.key,
|
|
121
122
|
slug: header.slug,
|
|
123
|
+
decorator: header.decorator,
|
|
122
124
|
onClick: event => {
|
|
123
125
|
const nextSortState = sorting.getNextSortState(this.props, this.state, {
|
|
124
126
|
key: header.key
|
|
@@ -373,7 +375,8 @@ class DataTable extends React__default["default"].Component {
|
|
|
373
375
|
} = _ref4;
|
|
374
376
|
return {
|
|
375
377
|
...rest,
|
|
376
|
-
|
|
378
|
+
hasAILabelHeader: cell.hasAILabelHeader,
|
|
379
|
+
hasDecoratorHeader: cell.hasDecoratorHeader
|
|
377
380
|
};
|
|
378
381
|
});
|
|
379
382
|
/**
|
|
@@ -753,6 +756,7 @@ _rollupPluginBabelHelpers.defineProperty(DataTable, "TableBatchActions", void 0)
|
|
|
753
756
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableBody", void 0);
|
|
754
757
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableCell", void 0);
|
|
755
758
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableContainer", void 0);
|
|
759
|
+
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableDecoratorRow", void 0);
|
|
756
760
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableExpandHeader", void 0);
|
|
757
761
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableExpandRow", void 0);
|
|
758
762
|
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableExpandedRow", void 0);
|
|
@@ -774,6 +778,7 @@ DataTable.TableBatchActions = TableBatchActions["default"];
|
|
|
774
778
|
DataTable.TableBody = TableBody["default"];
|
|
775
779
|
DataTable.TableCell = TableCell["default"];
|
|
776
780
|
DataTable.TableContainer = TableContainer["default"];
|
|
781
|
+
DataTable.TableDecoratorRow = TableDecoratorRow["default"];
|
|
777
782
|
DataTable.TableExpandHeader = TableExpandHeader["default"];
|
|
778
783
|
DataTable.TableExpandRow = TableExpandRow["default"];
|
|
779
784
|
DataTable.TableExpandedRow = TableExpandedRow["default"];
|
|
@@ -22,7 +22,7 @@ interface TableCellProps extends ReactAttr<HTMLTableCellElement> {
|
|
|
22
22
|
/**
|
|
23
23
|
* Specify if the table cell is in an AI column
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
hasAILabelHeader?: boolean;
|
|
26
26
|
/**
|
|
27
27
|
* The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
|
|
28
28
|
*/
|
|
@@ -23,13 +23,13 @@ const TableCell = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref)
|
|
|
23
23
|
let {
|
|
24
24
|
children,
|
|
25
25
|
className,
|
|
26
|
-
|
|
26
|
+
hasAILabelHeader,
|
|
27
27
|
colSpan,
|
|
28
28
|
...rest
|
|
29
29
|
} = _ref;
|
|
30
30
|
const prefix = usePrefix.usePrefix();
|
|
31
31
|
const tableCellClassNames = cx__default["default"](className, {
|
|
32
|
-
[`${prefix}--table-cell--column-slug`]:
|
|
32
|
+
[`${prefix}--table-cell--column-slug`]: hasAILabelHeader
|
|
33
33
|
});
|
|
34
34
|
return /*#__PURE__*/React__default["default"].createElement("td", _rollupPluginBabelHelpers["extends"]({
|
|
35
35
|
className: tableCellClassNames ? tableCellClassNames : undefined,
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { ReactNode } from 'react';
|
|
9
|
+
export interface TableDecoratorRowProps {
|
|
10
|
+
/**
|
|
11
|
+
* The CSS class names of the cell that wraps the underlying input control
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
|
|
16
|
+
*/
|
|
17
|
+
decorator?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
declare const TableDecoratorRow: {
|
|
20
|
+
({ className, decorator, }: TableDecoratorRowProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
displayName: string;
|
|
22
|
+
propTypes: {
|
|
23
|
+
/**
|
|
24
|
+
* The CSS class names of the cell that wraps the underlying input control
|
|
25
|
+
*/
|
|
26
|
+
className: PropTypes.Requireable<string>;
|
|
27
|
+
/**
|
|
28
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
|
|
29
|
+
*/
|
|
30
|
+
decorator: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export default TableDecoratorRow;
|