@carbon/react 1.63.1 → 1.64.0-rc.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 +1558 -1265
- package/es/components/{Slug → AILabel}/index.js +47 -35
- package/es/components/{AiSkeleton/AiSkeletonIcon.d.ts → AISkeleton/AISkeletonIcon.d.ts} +4 -4
- package/es/components/{AiSkeleton/AiSkeletonIcon.js → AISkeleton/AISkeletonIcon.js} +5 -5
- package/es/components/{AiSkeleton/AiSkeletonPlaceholder.d.ts → AISkeleton/AISkeletonPlaceholder.d.ts} +4 -4
- package/es/components/{AiSkeleton/AiSkeletonPlaceholder.js → AISkeleton/AISkeletonPlaceholder.js} +5 -5
- package/es/components/{AiSkeleton/AiSkeletonText.d.ts → AISkeleton/AISkeletonText.d.ts} +4 -4
- package/es/components/{AiSkeleton/AiSkeletonText.js → AISkeleton/AISkeletonText.js} +3 -3
- package/es/components/AISkeleton/index.d.ts +10 -0
- package/es/components/CheckboxGroup/CheckboxGroup.js +1 -1
- package/es/components/ComboBox/ComboBox.d.ts +21 -6
- package/es/components/ComboBox/ComboBox.js +52 -14
- package/es/components/ComposedModal/ComposedModal.js +1 -1
- package/es/components/DataTable/DataTable.js +1 -1
- package/es/components/DataTable/TableSelectRow.js +2 -1
- package/es/components/DataTable/TableToolbarSearch.js +2 -2
- package/es/components/DatePicker/DatePicker.js +65 -14
- package/es/components/DatePicker/plugins/fixEventsPlugin.js +11 -0
- package/es/components/DatePickerInput/DatePickerInput.js +1 -1
- package/es/components/Dropdown/Dropdown.d.ts +6 -4
- package/es/components/Dropdown/Dropdown.js +18 -10
- package/es/components/FluidMultiSelect/FluidMultiSelect.js +10 -6
- package/es/components/Menu/MenuItem.js +45 -63
- package/es/components/Modal/Modal.js +1 -1
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +6 -4
- package/es/components/MultiSelect/FilterableMultiSelect.js +50 -27
- package/es/components/MultiSelect/MultiSelect.d.ts +6 -4
- package/es/components/MultiSelect/MultiSelect.js +12 -8
- package/es/components/NumberInput/NumberInput.js +2 -2
- package/es/components/OverflowMenu/OverflowMenu.js +2 -1
- package/es/components/OverflowMenu/next/index.js +2 -1
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
- package/es/components/RadioTile/RadioTile.js +1 -1
- package/es/components/Select/Select.js +1 -1
- package/es/components/Tabs/Tabs.js +3 -3
- package/es/components/Tag/DismissibleTag.js +1 -1
- package/es/components/Tag/OperationalTag.js +1 -1
- package/es/components/Tag/SelectableTag.js +3 -1
- package/es/components/Tag/Tag.js +1 -1
- package/es/components/TextArea/TextArea.js +1 -1
- package/es/components/TextInput/PasswordInput.js +5 -0
- package/es/components/TextInput/TextInput.js +1 -1
- package/es/components/Tile/Tile.js +2 -2
- package/es/components/TreeView/TreeNode.d.ts +150 -0
- package/es/components/TreeView/TreeNode.js +22 -15
- package/es/components/TreeView/TreeView.d.ts +59 -0
- package/es/components/TreeView/TreeView.js +37 -23
- package/es/components/TreeView/index.d.ts +11 -0
- package/es/components/UIShell/SwitcherItem.d.ts +4 -0
- package/es/components/UIShell/SwitcherItem.js +7 -1
- package/es/index.d.ts +4 -2
- package/es/index.js +6 -6
- package/es/node_modules/@floating-ui/core/dist/floating-ui.core.mjs.js +143 -0
- package/es/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs.js +39 -0
- package/lib/components/{Slug → AILabel}/index.js +49 -37
- package/lib/components/{AiSkeleton/AiSkeletonIcon.d.ts → AISkeleton/AISkeletonIcon.d.ts} +4 -4
- package/lib/components/{AiSkeleton/AiSkeletonIcon.js → AISkeleton/AISkeletonIcon.js} +5 -5
- package/lib/components/{AiSkeleton/AiSkeletonPlaceholder.d.ts → AISkeleton/AISkeletonPlaceholder.d.ts} +4 -4
- package/lib/components/{AiSkeleton/AiSkeletonPlaceholder.js → AISkeleton/AISkeletonPlaceholder.js} +5 -5
- package/lib/components/{AiSkeleton/AiSkeletonText.d.ts → AISkeleton/AISkeletonText.d.ts} +4 -4
- package/lib/components/{AiSkeleton/AiSkeletonText.js → AISkeleton/AISkeletonText.js} +3 -3
- package/lib/components/AISkeleton/index.d.ts +10 -0
- package/lib/components/CheckboxGroup/CheckboxGroup.js +1 -1
- package/lib/components/ComboBox/ComboBox.d.ts +21 -6
- package/lib/components/ComboBox/ComboBox.js +52 -14
- package/lib/components/ComposedModal/ComposedModal.js +1 -1
- package/lib/components/DataTable/DataTable.js +2 -2
- package/lib/components/DataTable/TableSelectRow.js +2 -1
- package/lib/components/DataTable/TableToolbarSearch.js +2 -2
- package/lib/components/DatePicker/DatePicker.js +65 -14
- package/lib/components/DatePicker/plugins/fixEventsPlugin.js +11 -0
- package/lib/components/DatePickerInput/DatePickerInput.js +1 -1
- package/lib/components/Dropdown/Dropdown.d.ts +6 -4
- package/lib/components/Dropdown/Dropdown.js +18 -10
- package/lib/components/FluidMultiSelect/FluidMultiSelect.js +10 -6
- package/lib/components/Menu/MenuItem.js +44 -62
- package/lib/components/Modal/Modal.js +1 -1
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +6 -4
- package/lib/components/MultiSelect/FilterableMultiSelect.js +49 -26
- package/lib/components/MultiSelect/MultiSelect.d.ts +6 -4
- package/lib/components/MultiSelect/MultiSelect.js +12 -8
- package/lib/components/NumberInput/NumberInput.js +2 -2
- package/lib/components/OverflowMenu/OverflowMenu.js +2 -1
- package/lib/components/OverflowMenu/next/index.js +2 -1
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
- package/lib/components/RadioTile/RadioTile.js +1 -1
- package/lib/components/Select/Select.js +1 -1
- package/lib/components/Tabs/Tabs.js +2 -2
- package/lib/components/Tag/DismissibleTag.js +1 -1
- package/lib/components/Tag/OperationalTag.js +1 -1
- package/lib/components/Tag/SelectableTag.js +3 -1
- package/lib/components/Tag/Tag.js +1 -1
- package/lib/components/TextArea/TextArea.js +1 -1
- package/lib/components/TextInput/PasswordInput.js +5 -0
- package/lib/components/TextInput/TextInput.js +1 -1
- package/lib/components/Tile/Tile.js +2 -2
- package/lib/components/TreeView/TreeNode.d.ts +150 -0
- package/lib/components/TreeView/TreeNode.js +24 -17
- package/lib/components/TreeView/TreeView.d.ts +59 -0
- package/lib/components/TreeView/TreeView.js +39 -25
- package/lib/components/TreeView/index.d.ts +11 -0
- package/lib/components/UIShell/SwitcherItem.d.ts +4 -0
- package/lib/components/UIShell/SwitcherItem.js +7 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.js +20 -14
- package/lib/node_modules/@floating-ui/core/dist/floating-ui.core.mjs.js +148 -0
- package/lib/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs.js +47 -0
- package/package.json +4 -4
- package/scss/components/ai-label/_ai-label.scss +9 -0
- package/scss/components/ai-label/_index.scss +9 -0
- package/es/components/AiSkeleton/index.d.ts +0 -10
- package/es/components/DataTable/tools/instanceId.js +0 -20
- package/lib/components/AiSkeleton/index.d.ts +0 -10
- package/lib/components/DataTable/tools/instanceId.js +0 -24
|
@@ -311,7 +311,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
311
311
|
setIsOpenWrapper(changes.isOpen || false);
|
|
312
312
|
return {
|
|
313
313
|
...changes,
|
|
314
|
-
highlightedIndex: 0
|
|
314
|
+
highlightedIndex: controlledSelectedItems.length > 0 ? 0 : undefined
|
|
315
315
|
};
|
|
316
316
|
case ItemClick:
|
|
317
317
|
setHighlightedIndex(changes.selectedItem);
|
|
@@ -386,7 +386,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
386
386
|
|
|
387
387
|
// Slug is always size `mini`
|
|
388
388
|
let normalizedSlug;
|
|
389
|
-
if (slug && slug['type']?.displayName === '
|
|
389
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
390
390
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
391
391
|
size: 'mini'
|
|
392
392
|
});
|
|
@@ -506,7 +506,8 @@ MultiSelect.propTypes = {
|
|
|
506
506
|
clearSelectionText: PropTypes.string,
|
|
507
507
|
/**
|
|
508
508
|
* Provide a compare function that is used to determine the ordering of
|
|
509
|
-
* options. See 'sortItems' for more control.
|
|
509
|
+
* options. See 'sortItems' for more control. Consider
|
|
510
|
+
* declaring function with `useCallback` to prevent unnecessary re-renders.
|
|
510
511
|
*/
|
|
511
512
|
compareItems: PropTypes.func,
|
|
512
513
|
/**
|
|
@@ -518,10 +519,12 @@ MultiSelect.propTypes = {
|
|
|
518
519
|
*/
|
|
519
520
|
disabled: PropTypes.bool,
|
|
520
521
|
/**
|
|
521
|
-
* Additional props passed to Downshift.
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
522
|
+
* Additional props passed to Downshift.
|
|
523
|
+
*
|
|
524
|
+
* **Use with caution:** anything you define here overrides the components'
|
|
525
|
+
* internal handling of that prop. Downshift APIs and internals are subject to
|
|
526
|
+
* change, and in some cases they can not be shimmed by Carbon to shield you
|
|
527
|
+
* from potentially breaking changes.
|
|
525
528
|
*/
|
|
526
529
|
downshiftProps: PropTypes.object,
|
|
527
530
|
/**
|
|
@@ -558,7 +561,8 @@ MultiSelect.propTypes = {
|
|
|
558
561
|
/**
|
|
559
562
|
* Helper function passed to downshift that allows the library to render a
|
|
560
563
|
* given item to a string label. By default, it extracts the `label` field
|
|
561
|
-
* from a given item to serve as the item label in the list.
|
|
564
|
+
* from a given item to serve as the item label in the list. Consider
|
|
565
|
+
* declaring function with `useCallback` to prevent unnecessary re-renders.
|
|
562
566
|
*/
|
|
563
567
|
itemToString: PropTypes.func,
|
|
564
568
|
/**
|
|
@@ -180,7 +180,7 @@ const NumberInput = /*#__PURE__*/React__default.forwardRef(function NumberInput(
|
|
|
180
180
|
|
|
181
181
|
// Slug is always size `mini`
|
|
182
182
|
let normalizedSlug;
|
|
183
|
-
if (slug && slug['type']?.displayName === '
|
|
183
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
184
184
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
185
185
|
size: 'mini'
|
|
186
186
|
});
|
|
@@ -188,7 +188,7 @@ const NumberInput = /*#__PURE__*/React__default.forwardRef(function NumberInput(
|
|
|
188
188
|
|
|
189
189
|
// Need to update the internal value when the revert button is clicked
|
|
190
190
|
let isRevertActive;
|
|
191
|
-
if (slug && slug['type']?.displayName === '
|
|
191
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
192
192
|
isRevertActive = normalizedSlug.props.revertActive;
|
|
193
193
|
}
|
|
194
194
|
useEffect(() => {
|
|
@@ -405,7 +405,8 @@ class OverflowMenu extends React__default.Component {
|
|
|
405
405
|
id: id,
|
|
406
406
|
ref: mergeRefs(this._triggerRef, ref),
|
|
407
407
|
size: size,
|
|
408
|
-
label: iconDescription
|
|
408
|
+
label: iconDescription,
|
|
409
|
+
kind: "ghost"
|
|
409
410
|
}), /*#__PURE__*/React__default.createElement(IconElement, iconProps)), open && this.state.hasMountedTrigger && wrappedMenuBody));
|
|
410
411
|
}
|
|
411
412
|
}
|
|
@@ -96,7 +96,8 @@ const OverflowMenu = /*#__PURE__*/React__default.forwardRef(function OverflowMen
|
|
|
96
96
|
onMouseDown: handleMousedown,
|
|
97
97
|
ref: floatingRef,
|
|
98
98
|
label: label,
|
|
99
|
-
align: tooltipAlignment
|
|
99
|
+
align: tooltipAlignment,
|
|
100
|
+
kind: "ghost"
|
|
100
101
|
}, /*#__PURE__*/React__default.createElement(IconElement, {
|
|
101
102
|
className: `${prefix}--overflow-menu__icon`
|
|
102
103
|
})), /*#__PURE__*/React__default.createElement(Menu, {
|
|
@@ -101,7 +101,7 @@ const RadioButtonGroup = /*#__PURE__*/React__default.forwardRef((props, ref) =>
|
|
|
101
101
|
|
|
102
102
|
// Slug is always size `mini`
|
|
103
103
|
let normalizedSlug;
|
|
104
|
-
if (slug && slug['type']?.displayName === '
|
|
104
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
105
105
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
106
106
|
size: 'mini',
|
|
107
107
|
kind: 'default'
|
|
@@ -71,7 +71,7 @@ const RadioTile = /*#__PURE__*/React__default.forwardRef(function RadioTile(_ref
|
|
|
71
71
|
|
|
72
72
|
// Slug is always size `xs`
|
|
73
73
|
let normalizedSlug;
|
|
74
|
-
if (slug && slug['type']?.displayName === '
|
|
74
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
75
75
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
76
76
|
size: 'xs'
|
|
77
77
|
});
|
|
@@ -125,7 +125,7 @@ const Select = /*#__PURE__*/React__default.forwardRef(function Select(_ref, ref)
|
|
|
125
125
|
|
|
126
126
|
// Slug is always size `mini`
|
|
127
127
|
let normalizedSlug;
|
|
128
|
-
if (slug && slug['type']?.displayName === '
|
|
128
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
129
129
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
130
130
|
size: 'mini'
|
|
131
131
|
});
|
|
@@ -11,7 +11,7 @@ import { breakpoints } from '@carbon/layout';
|
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import debounce from 'lodash.debounce';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
|
-
import React__default, { useState, useRef, useCallback, useEffect, forwardRef
|
|
14
|
+
import React__default, { useState, useRef, useCallback, useEffect, forwardRef } from 'react';
|
|
15
15
|
import '../Grid/FlexGrid.js';
|
|
16
16
|
import { Grid as GridAsGridComponent } from '../Grid/Grid.js';
|
|
17
17
|
import '../Grid/Row.js';
|
|
@@ -787,7 +787,7 @@ const Tab = /*#__PURE__*/forwardRef(function Tab(_ref8, forwardRef) {
|
|
|
787
787
|
};
|
|
788
788
|
useEvent(dismissIconRef, 'mouseover', onDismissIconMouseEnter);
|
|
789
789
|
useEvent(dismissIconRef, 'mouseleave', onDismissIconMouseLeave);
|
|
790
|
-
|
|
790
|
+
useIsomorphicEffect(() => {
|
|
791
791
|
function handler() {
|
|
792
792
|
const elementTabId = document.getElementById(`${id}`) || tabRef.current;
|
|
793
793
|
if (elementTabId?.closest(`.${prefix}--tabs--vertical`)) {
|
|
@@ -1128,7 +1128,7 @@ function TabPanels(_ref11) {
|
|
|
1128
1128
|
const prefix = usePrefix();
|
|
1129
1129
|
const refs = useRef([]);
|
|
1130
1130
|
const hiddenStates = useRef([]);
|
|
1131
|
-
|
|
1131
|
+
useIsomorphicEffect(() => {
|
|
1132
1132
|
const tabContainer = refs.current[0]?.previousElementSibling;
|
|
1133
1133
|
const isVertical = tabContainer?.classList.contains(`${prefix}--tabs--vertical`);
|
|
1134
1134
|
const parentHasHeight = tabContainer?.parentElement?.style.height;
|
|
@@ -50,7 +50,7 @@ const DismissibleTag = _ref => {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
let normalizedSlug;
|
|
53
|
-
if (slug && slug['type']?.displayName === '
|
|
53
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
54
54
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
55
55
|
size: 'sm',
|
|
56
56
|
kind: 'inline'
|
|
@@ -52,7 +52,7 @@ const OperationalTag = _ref => {
|
|
|
52
52
|
setIsEllipsisApplied(isEllipsisActive(newElement));
|
|
53
53
|
}, [prefix, tagRef]);
|
|
54
54
|
let normalizedSlug;
|
|
55
|
-
if (slug && slug['type']?.displayName === '
|
|
55
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
56
56
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
57
57
|
size: 'sm',
|
|
58
58
|
kind: 'inline'
|
|
@@ -43,7 +43,7 @@ const SelectableTag = _ref => {
|
|
|
43
43
|
setIsEllipsisApplied(isEllipsisActive(newElement));
|
|
44
44
|
}, [prefix, tagRef]);
|
|
45
45
|
let normalizedSlug;
|
|
46
|
-
if (slug && slug['type']?.displayName === '
|
|
46
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
47
47
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
48
48
|
size: 'sm',
|
|
49
49
|
kind: 'inline'
|
|
@@ -65,6 +65,7 @@ const SelectableTag = _ref => {
|
|
|
65
65
|
leaveDelayMs: 0,
|
|
66
66
|
onMouseEnter: () => false
|
|
67
67
|
}, /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
68
|
+
"aria-pressed": selectedTag,
|
|
68
69
|
ref: tagRef,
|
|
69
70
|
slug: slug,
|
|
70
71
|
size: size,
|
|
@@ -79,6 +80,7 @@ const SelectableTag = _ref => {
|
|
|
79
80
|
}, text), normalizedSlug));
|
|
80
81
|
}
|
|
81
82
|
return /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
83
|
+
"aria-pressed": selectedTag,
|
|
82
84
|
ref: tagRef,
|
|
83
85
|
slug: slug,
|
|
84
86
|
size: size,
|
package/es/components/Tag/Tag.js
CHANGED
|
@@ -89,7 +89,7 @@ const Tag = /*#__PURE__*/React__default.forwardRef(function Tag(_ref, forwardRef
|
|
|
89
89
|
|
|
90
90
|
// Slug is always size `md` and `inline`
|
|
91
91
|
let normalizedSlug;
|
|
92
|
-
if (slug && slug['type']?.displayName === '
|
|
92
|
+
if (slug && slug['type']?.displayName === 'AILabel' && !isInteractiveTag) {
|
|
93
93
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
94
94
|
size: 'sm',
|
|
95
95
|
kind: 'inline'
|
|
@@ -255,7 +255,7 @@ const TextArea = /*#__PURE__*/React__default.forwardRef((props, forwardRef) => {
|
|
|
255
255
|
|
|
256
256
|
// Slug is always size `mini`
|
|
257
257
|
let normalizedSlug;
|
|
258
|
-
if (slug && slug['type']?.displayName === '
|
|
258
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
259
259
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
260
260
|
size: 'mini'
|
|
261
261
|
});
|
|
@@ -148,6 +148,11 @@ const PasswordInput = /*#__PURE__*/React__default.forwardRef(function PasswordIn
|
|
|
148
148
|
if (tooltipPosition === 'right' || tooltipPosition === 'left') {
|
|
149
149
|
align = tooltipPosition;
|
|
150
150
|
}
|
|
151
|
+
if (!hidePasswordLabel || hidePasswordLabel.trim() === '') {
|
|
152
|
+
console.warn('Warning: The "hidePasswordLabel" should not be blank.');
|
|
153
|
+
} else if (!showPasswordLabel || showPasswordLabel.trim() === '') {
|
|
154
|
+
console.warn('Warning: The "showPasswordLabel" should not be blank.');
|
|
155
|
+
}
|
|
151
156
|
const input = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("input", _extends({}, textInputProps({
|
|
152
157
|
sharedTextInputProps,
|
|
153
158
|
invalid: normalizedProps.invalid,
|
|
@@ -181,7 +181,7 @@ const TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref
|
|
|
181
181
|
|
|
182
182
|
// Slug is always size `mini`
|
|
183
183
|
let normalizedSlug;
|
|
184
|
-
if (slug && slug['type']?.displayName === '
|
|
184
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
185
185
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
186
186
|
size: 'mini'
|
|
187
187
|
});
|
|
@@ -269,7 +269,7 @@ const SelectableTile = /*#__PURE__*/React__default.forwardRef(function Selectabl
|
|
|
269
269
|
// Slug is always size `xs`
|
|
270
270
|
const slugRef = useRef(null);
|
|
271
271
|
let normalizedSlug;
|
|
272
|
-
if (slug && slug['type']?.displayName === '
|
|
272
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
273
273
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
274
274
|
size: 'xs',
|
|
275
275
|
ref: slugRef
|
|
@@ -495,7 +495,7 @@ const ExpandableTile = /*#__PURE__*/React__default.forwardRef(function Expandabl
|
|
|
495
495
|
|
|
496
496
|
// Slug is always size `xs`
|
|
497
497
|
let normalizedSlug;
|
|
498
|
-
if (slug && slug['type']?.displayName === '
|
|
498
|
+
if (slug && slug['type']?.displayName === 'AILabel') {
|
|
499
499
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
500
500
|
size: 'xs'
|
|
501
501
|
});
|
|
@@ -0,0 +1,150 @@
|
|
|
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 React, { ComponentType, FunctionComponent } from 'react';
|
|
8
|
+
export type TreeNodeProps = {
|
|
9
|
+
/**
|
|
10
|
+
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
11
|
+
* The ID of the active node in the tree
|
|
12
|
+
*/
|
|
13
|
+
active?: string | number;
|
|
14
|
+
/**
|
|
15
|
+
* Specify the children of the TreeNode
|
|
16
|
+
*/
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Specify an optional className to be applied to the TreeNode
|
|
20
|
+
*/
|
|
21
|
+
className?: string;
|
|
22
|
+
/**
|
|
23
|
+
* **[Experimental]** The default expansion state of the node.
|
|
24
|
+
* *This is only supported with the `enable-treeview-controllable` feature flag!*
|
|
25
|
+
*/
|
|
26
|
+
defaultIsExpanded?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
29
|
+
* TreeNode depth to determine spacing
|
|
30
|
+
*/
|
|
31
|
+
depth?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Specify if the TreeNode is disabled
|
|
34
|
+
*/
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Specify the TreeNode's ID. Must be unique in the DOM and is used for props.active and props.selected
|
|
38
|
+
*/
|
|
39
|
+
id?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Specify if the TreeNode is expanded (only applicable to parent nodes)
|
|
42
|
+
*/
|
|
43
|
+
isExpanded?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Rendered label for the TreeNode
|
|
46
|
+
*/
|
|
47
|
+
label: React.ReactNode;
|
|
48
|
+
/**
|
|
49
|
+
* Callback function for when the node receives or loses focus
|
|
50
|
+
*/
|
|
51
|
+
onNodeFocusEvent?: (event: React.FocusEvent<HTMLLIElement>) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Callback function for when the node is selected
|
|
54
|
+
*/
|
|
55
|
+
onSelect?: (event: React.MouseEvent, node?: TreeNodeProps) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Callback function for when a parent node is expanded or collapsed
|
|
58
|
+
*/
|
|
59
|
+
onToggle?: (event: React.MouseEvent, node?: TreeNodeProps) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Callback function for when any node in the tree is selected
|
|
62
|
+
*/
|
|
63
|
+
onTreeSelect?: (event: React.MouseEvent, node?: TreeNodeProps) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Optional prop to allow each node to have an associated icon.
|
|
66
|
+
* Can be a React component class
|
|
67
|
+
*/
|
|
68
|
+
renderIcon?: ComponentType | FunctionComponent;
|
|
69
|
+
/**
|
|
70
|
+
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
71
|
+
* Array containing all selected node IDs in the tree
|
|
72
|
+
*/
|
|
73
|
+
selected?: Array<string | number>;
|
|
74
|
+
/**
|
|
75
|
+
* Specify the value of the TreeNode
|
|
76
|
+
*/
|
|
77
|
+
value?: string;
|
|
78
|
+
} & Omit<React.LiHTMLAttributes<HTMLLIElement>, 'onSelect'>;
|
|
79
|
+
declare const TreeNode: React.ForwardRefExoticComponent<{
|
|
80
|
+
/**
|
|
81
|
+
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
82
|
+
* The ID of the active node in the tree
|
|
83
|
+
*/
|
|
84
|
+
active?: string | number | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Specify the children of the TreeNode
|
|
87
|
+
*/
|
|
88
|
+
children?: React.ReactNode;
|
|
89
|
+
/**
|
|
90
|
+
* Specify an optional className to be applied to the TreeNode
|
|
91
|
+
*/
|
|
92
|
+
className?: string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* **[Experimental]** The default expansion state of the node.
|
|
95
|
+
* *This is only supported with the `enable-treeview-controllable` feature flag!*
|
|
96
|
+
*/
|
|
97
|
+
defaultIsExpanded?: boolean | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
100
|
+
* TreeNode depth to determine spacing
|
|
101
|
+
*/
|
|
102
|
+
depth?: number | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Specify if the TreeNode is disabled
|
|
105
|
+
*/
|
|
106
|
+
disabled?: boolean | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Specify the TreeNode's ID. Must be unique in the DOM and is used for props.active and props.selected
|
|
109
|
+
*/
|
|
110
|
+
id?: string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Specify if the TreeNode is expanded (only applicable to parent nodes)
|
|
113
|
+
*/
|
|
114
|
+
isExpanded?: boolean | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Rendered label for the TreeNode
|
|
117
|
+
*/
|
|
118
|
+
label: React.ReactNode;
|
|
119
|
+
/**
|
|
120
|
+
* Callback function for when the node receives or loses focus
|
|
121
|
+
*/
|
|
122
|
+
onNodeFocusEvent?: ((event: React.FocusEvent<HTMLLIElement>) => void) | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Callback function for when the node is selected
|
|
125
|
+
*/
|
|
126
|
+
onSelect?: ((event: React.MouseEvent, node?: TreeNodeProps) => void) | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Callback function for when a parent node is expanded or collapsed
|
|
129
|
+
*/
|
|
130
|
+
onToggle?: ((event: React.MouseEvent, node?: TreeNodeProps) => void) | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Callback function for when any node in the tree is selected
|
|
133
|
+
*/
|
|
134
|
+
onTreeSelect?: ((event: React.MouseEvent, node?: TreeNodeProps) => void) | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Optional prop to allow each node to have an associated icon.
|
|
137
|
+
* Can be a React component class
|
|
138
|
+
*/
|
|
139
|
+
renderIcon?: React.ComponentType<{}> | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
142
|
+
* Array containing all selected node IDs in the tree
|
|
143
|
+
*/
|
|
144
|
+
selected?: (string | number)[] | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Specify the value of the TreeNode
|
|
147
|
+
*/
|
|
148
|
+
value?: string | undefined;
|
|
149
|
+
} & Omit<React.LiHTMLAttributes<HTMLLIElement>, "onSelect"> & React.RefAttributes<HTMLLIElement>>;
|
|
150
|
+
export default TreeNode;
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React__default, { useRef, useState, useEffect } from 'react';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
9
|
import { CaretDown } from '@carbon/icons-react';
|
|
12
10
|
import cx from 'classnames';
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
11
|
+
import PropTypes from 'prop-types';
|
|
12
|
+
import React__default, { useRef, useState, useEffect } from 'react';
|
|
15
13
|
import { useControllableState } from '../../internal/useControllableState.js';
|
|
14
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
15
|
+
import uniqueId from '../../tools/uniqueId.js';
|
|
16
16
|
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
17
17
|
import { matches, match } from '../../internal/keyboard/match.js';
|
|
18
18
|
import { ArrowLeft, ArrowRight, Enter, Space } from '../../internal/keyboard/keys.js';
|
|
@@ -22,7 +22,7 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
22
22
|
active,
|
|
23
23
|
children,
|
|
24
24
|
className,
|
|
25
|
-
depth,
|
|
25
|
+
depth: propDepth,
|
|
26
26
|
disabled,
|
|
27
27
|
id: nodeId,
|
|
28
28
|
isExpanded,
|
|
@@ -33,10 +33,13 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
33
33
|
onToggle,
|
|
34
34
|
onTreeSelect,
|
|
35
35
|
renderIcon: Icon,
|
|
36
|
-
selected,
|
|
36
|
+
selected: propSelected,
|
|
37
37
|
value,
|
|
38
38
|
...rest
|
|
39
39
|
} = _ref;
|
|
40
|
+
// These are provided by the parent TreeView component
|
|
41
|
+
const depth = propDepth;
|
|
42
|
+
const selected = propSelected;
|
|
40
43
|
const enableTreeviewControllable = useFeatureFlag('enable-treeview-controllable');
|
|
41
44
|
const {
|
|
42
45
|
current: id
|
|
@@ -141,7 +144,7 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
141
144
|
* When focus is on a leaf node or a closed parent node, move focus to
|
|
142
145
|
* its parent node (unless its depth is level 1)
|
|
143
146
|
*/
|
|
144
|
-
findParentTreeNode(currentNode.current
|
|
147
|
+
findParentTreeNode(currentNode.current?.parentNode)?.focus();
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
if (children && match(event, ArrowRight)) {
|
|
@@ -150,7 +153,7 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
150
153
|
* When focus is on an expanded parent node, move focus to the first
|
|
151
154
|
* child node
|
|
152
155
|
*/
|
|
153
|
-
currentNode.current
|
|
156
|
+
(currentNode.current?.lastChild?.firstChild).focus();
|
|
154
157
|
} else {
|
|
155
158
|
if (!enableTreeviewControllable) {
|
|
156
159
|
onToggle?.(event, {
|
|
@@ -217,8 +220,8 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
217
220
|
}, [children, depth, Icon, isExpanded, enableTreeviewControllable, setExpanded]);
|
|
218
221
|
const treeNodeProps = {
|
|
219
222
|
...rest,
|
|
220
|
-
['aria-current']: isActive ||
|
|
221
|
-
['aria-selected']: disabled ?
|
|
223
|
+
['aria-current']: isActive || undefined,
|
|
224
|
+
['aria-selected']: disabled ? undefined : isSelected,
|
|
222
225
|
['aria-disabled']: disabled,
|
|
223
226
|
className: treeNodeClasses,
|
|
224
227
|
id,
|
|
@@ -226,8 +229,9 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
226
229
|
onClick: handleClick,
|
|
227
230
|
onFocus: handleFocusEvent,
|
|
228
231
|
onKeyDown: handleKeyDown,
|
|
229
|
-
|
|
230
|
-
|
|
232
|
+
role: 'treeitem',
|
|
233
|
+
// @ts-ignore
|
|
234
|
+
ref: currentNode
|
|
231
235
|
};
|
|
232
236
|
if (!children) {
|
|
233
237
|
return /*#__PURE__*/React__default.createElement("li", treeNodeProps, /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -247,7 +251,9 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
247
251
|
className: `${prefix}--tree-node__label`,
|
|
248
252
|
ref: currentNodeLabel
|
|
249
253
|
}, /*#__PURE__*/React__default.createElement("span", {
|
|
250
|
-
className: `${prefix}--tree-parent-node__toggle
|
|
254
|
+
className: `${prefix}--tree-parent-node__toggle`
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
,
|
|
251
257
|
disabled: disabled,
|
|
252
258
|
onClick: handleToggleClick
|
|
253
259
|
}, /*#__PURE__*/React__default.createElement(CaretDown, {
|
|
@@ -322,11 +328,13 @@ TreeNode.propTypes = {
|
|
|
322
328
|
* Optional prop to allow each node to have an associated icon.
|
|
323
329
|
* Can be a React component class
|
|
324
330
|
*/
|
|
331
|
+
// @ts-ignore
|
|
325
332
|
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
326
333
|
/**
|
|
327
334
|
* **Note:** this is controlled by the parent TreeView component, do not set manually.
|
|
328
335
|
* Array containing all selected node IDs in the tree
|
|
329
336
|
*/
|
|
337
|
+
// @ts-ignore
|
|
330
338
|
selected: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
331
339
|
/**
|
|
332
340
|
* Specify the value of the TreeNode
|
|
@@ -334,6 +342,5 @@ TreeNode.propTypes = {
|
|
|
334
342
|
value: PropTypes.string
|
|
335
343
|
};
|
|
336
344
|
TreeNode.displayName = 'TreeNode';
|
|
337
|
-
var TreeNode$1 = TreeNode;
|
|
338
345
|
|
|
339
|
-
export { TreeNode
|
|
346
|
+
export { TreeNode as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
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 React from 'react';
|
|
8
|
+
import TreeNode from './TreeNode';
|
|
9
|
+
export type TreeViewProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Mark the active node in the tree, represented by its ID
|
|
12
|
+
*/
|
|
13
|
+
active?: string | number;
|
|
14
|
+
/**
|
|
15
|
+
* Specify the children of the TreeView
|
|
16
|
+
*/
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Specify an optional className to be applied to the TreeView
|
|
20
|
+
*/
|
|
21
|
+
className?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Specify whether or not the label should be hidden
|
|
24
|
+
*/
|
|
25
|
+
hideLabel?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Provide the label text that will be read by a screen reader
|
|
28
|
+
*/
|
|
29
|
+
label: string;
|
|
30
|
+
/**
|
|
31
|
+
* **[Experimental]** Specify the selection mode of the tree.
|
|
32
|
+
* If `multiselect` is `false` then only one node can be selected at a time
|
|
33
|
+
*/
|
|
34
|
+
multiselect?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* **[Experimental]** Callback function that is called when any node is activated.
|
|
37
|
+
* *This is only supported with the `enable-treeview-controllable` feature flag!*
|
|
38
|
+
*/
|
|
39
|
+
onActivate?: (activated?: string | number) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Callback function that is called when any node is selected
|
|
42
|
+
*/
|
|
43
|
+
onSelect?: (selected: Array<string | number>, payload: any) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Array representing all selected node IDs in the tree
|
|
46
|
+
*/
|
|
47
|
+
selected?: Array<string | number>;
|
|
48
|
+
/**
|
|
49
|
+
* Specify the size of the tree from a list of available sizes.
|
|
50
|
+
*/
|
|
51
|
+
size?: 'xs' | 'sm';
|
|
52
|
+
} & React.HTMLAttributes<HTMLUListElement>;
|
|
53
|
+
type TreeViewComponent = {
|
|
54
|
+
(props: TreeViewProps): JSX.Element;
|
|
55
|
+
propTypes?: any;
|
|
56
|
+
TreeNode: typeof TreeNode;
|
|
57
|
+
};
|
|
58
|
+
declare const TreeView: TreeViewComponent;
|
|
59
|
+
export default TreeView;
|