@carbon/react 1.54.0 → 1.55.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 +1065 -1012
- package/es/components/CodeSnippet/CodeSnippet.Skeleton.d.ts +37 -0
- package/es/components/CodeSnippet/CodeSnippet.d.ts +196 -0
- package/es/components/CodeSnippet/CodeSnippet.js +20 -19
- package/es/components/CodeSnippet/index.d.ts +10 -0
- package/es/components/ComboBox/ComboBox.d.ts +2 -2
- package/es/components/ComboBox/ComboBox.js +13 -5
- package/es/components/ComboButton/index.d.ts +51 -0
- package/es/components/ComboButton/index.js +9 -7
- package/es/components/ComposedModal/ComposedModal.d.ts +1 -1
- package/es/components/ComposedModal/ComposedModal.js +6 -6
- package/es/components/DataTable/TableBatchAction.d.ts +1 -5
- package/es/components/Dropdown/Dropdown.js +3 -1
- package/es/components/Modal/Modal.js +3 -3
- package/es/components/MultiSelect/FilterableMultiSelect.js +31 -0
- package/es/components/MultiSelect/MultiSelect.js +37 -7
- package/es/components/Slug/index.js +8 -13
- package/es/components/Tabs/Tabs.js +44 -13
- package/es/components/Tag/DismissibleTag.js +119 -0
- package/es/components/Tag/OperationalTag.js +99 -0
- package/es/components/Tag/SelectableTag.js +98 -0
- package/es/components/Tag/index.d.ts +4 -1
- package/es/components/TreeView/TreeNode.js +1 -1
- package/es/components/UIShell/HeaderMenu.d.ts +219 -0
- package/es/components/UIShell/HeaderMenu.js +22 -10
- package/es/components/UIShell/SideNavMenu.js +11 -1
- package/es/components/UIShell/SideNavMenuItem.d.ts +4 -0
- package/es/components/UIShell/SideNavMenuItem.js +8 -1
- package/es/components/UIShell/SwitcherItem.d.ts +4 -0
- package/es/components/UIShell/SwitcherItem.js +6 -0
- package/es/index.js +5 -2
- package/lib/components/CodeSnippet/CodeSnippet.Skeleton.d.ts +37 -0
- package/lib/components/CodeSnippet/CodeSnippet.d.ts +196 -0
- package/lib/components/CodeSnippet/CodeSnippet.js +20 -19
- package/lib/components/CodeSnippet/index.d.ts +10 -0
- package/lib/components/ComboBox/ComboBox.d.ts +2 -2
- package/lib/components/ComboBox/ComboBox.js +13 -5
- package/lib/components/ComboButton/index.d.ts +51 -0
- package/lib/components/ComboButton/index.js +9 -7
- package/lib/components/ComposedModal/ComposedModal.d.ts +1 -1
- package/lib/components/ComposedModal/ComposedModal.js +5 -5
- package/lib/components/DataTable/TableBatchAction.d.ts +1 -5
- package/lib/components/Dropdown/Dropdown.js +3 -1
- package/lib/components/Modal/Modal.js +3 -3
- package/lib/components/MultiSelect/FilterableMultiSelect.js +31 -0
- package/lib/components/MultiSelect/MultiSelect.js +37 -7
- package/lib/components/Slug/index.js +8 -13
- package/lib/components/Tabs/Tabs.js +44 -13
- package/lib/components/Tag/DismissibleTag.js +129 -0
- package/lib/components/Tag/OperationalTag.js +109 -0
- package/lib/components/Tag/SelectableTag.js +108 -0
- package/lib/components/Tag/index.d.ts +4 -1
- package/lib/components/TreeView/TreeNode.js +1 -1
- package/lib/components/UIShell/HeaderMenu.d.ts +219 -0
- package/lib/components/UIShell/HeaderMenu.js +22 -10
- package/lib/components/UIShell/SideNavMenu.js +11 -1
- package/lib/components/UIShell/SideNavMenuItem.d.ts +4 -0
- package/lib/components/UIShell/SideNavMenuItem.js +8 -1
- package/lib/components/UIShell/SwitcherItem.d.ts +4 -0
- package/lib/components/UIShell/SwitcherItem.js +6 -0
- package/lib/index.js +10 -4
- package/package.json +4 -4
|
@@ -37,9 +37,11 @@ const {
|
|
|
37
37
|
ToggleButtonKeyDownEscape,
|
|
38
38
|
ToggleButtonKeyDownSpaceButton,
|
|
39
39
|
ItemMouseMove,
|
|
40
|
+
MenuMouseLeave,
|
|
40
41
|
ToggleButtonClick,
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
ToggleButtonKeyDownPageDown,
|
|
43
|
+
ToggleButtonKeyDownPageUp,
|
|
44
|
+
FunctionSetHighlightedIndex
|
|
43
45
|
} = useSelect.stateChangeTypes;
|
|
44
46
|
const defaultItemToString = item => {
|
|
45
47
|
if (typeof item === 'string') {
|
|
@@ -135,7 +137,8 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
135
137
|
getMenuProps,
|
|
136
138
|
getItemProps,
|
|
137
139
|
selectedItem,
|
|
138
|
-
highlightedIndex
|
|
140
|
+
highlightedIndex,
|
|
141
|
+
setHighlightedIndex
|
|
139
142
|
} = useSelect(selectProps);
|
|
140
143
|
const toggleButtonProps = getToggleButtonProps({
|
|
141
144
|
onFocus: () => {
|
|
@@ -154,6 +157,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
154
157
|
setItemsCleared(true);
|
|
155
158
|
}
|
|
156
159
|
if ((match(e, Space) || match(e, ArrowDown) || match(e, Enter)) && !isOpen) {
|
|
160
|
+
setHighlightedIndex(0);
|
|
157
161
|
setItemsCleared(false);
|
|
158
162
|
setIsOpenWrapper(true);
|
|
159
163
|
}
|
|
@@ -237,7 +241,6 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
237
241
|
setTopItems(controlledSelectedItems);
|
|
238
242
|
}
|
|
239
243
|
switch (type) {
|
|
240
|
-
case ItemClick:
|
|
241
244
|
case ToggleButtonKeyDownSpaceButton:
|
|
242
245
|
case ToggleButtonKeyDownEnter:
|
|
243
246
|
if (changes.selectedItem === undefined) {
|
|
@@ -257,11 +260,38 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
257
260
|
break;
|
|
258
261
|
case ToggleButtonClick:
|
|
259
262
|
setIsOpenWrapper(changes.isOpen || false);
|
|
260
|
-
|
|
263
|
+
return {
|
|
264
|
+
...changes,
|
|
265
|
+
highlightedIndex: 0
|
|
266
|
+
};
|
|
267
|
+
case ItemClick:
|
|
268
|
+
setHighlightedIndex(changes.selectedItem);
|
|
269
|
+
onItemChange(changes.selectedItem);
|
|
270
|
+
return {
|
|
271
|
+
...changes,
|
|
272
|
+
highlightedIndex: state.highlightedIndex
|
|
273
|
+
};
|
|
274
|
+
case MenuMouseLeave:
|
|
275
|
+
return {
|
|
276
|
+
...changes,
|
|
277
|
+
highlightedIndex: state.highlightedIndex
|
|
278
|
+
};
|
|
279
|
+
case FunctionSetHighlightedIndex:
|
|
280
|
+
if (!isOpen) {
|
|
281
|
+
return {
|
|
282
|
+
...changes,
|
|
283
|
+
highlightedIndex: 0
|
|
284
|
+
};
|
|
285
|
+
} else {
|
|
286
|
+
return {
|
|
287
|
+
...changes,
|
|
288
|
+
highlightedIndex: props.items.indexOf(highlightedIndex)
|
|
289
|
+
};
|
|
290
|
+
}
|
|
261
291
|
case ToggleButtonKeyDownArrowDown:
|
|
262
292
|
case ToggleButtonKeyDownArrowUp:
|
|
263
|
-
case
|
|
264
|
-
case
|
|
293
|
+
case ToggleButtonKeyDownPageDown:
|
|
294
|
+
case ToggleButtonKeyDownPageUp:
|
|
265
295
|
if (highlightedIndex > -1) {
|
|
266
296
|
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
267
297
|
props.scrollIntoView(itemArray[highlightedIndex]);
|
|
@@ -138,26 +138,21 @@ Slug.propTypes = {
|
|
|
138
138
|
*/
|
|
139
139
|
align: PropTypes.oneOf(['top', 'top-left',
|
|
140
140
|
// deprecated use top-start instead
|
|
141
|
-
'top-right',
|
|
141
|
+
'top-start', 'top-right',
|
|
142
142
|
// deprecated use top-end instead
|
|
143
|
-
|
|
144
|
-
'bottom', 'bottom-left',
|
|
143
|
+
'top-end', 'bottom', 'bottom-left',
|
|
145
144
|
// deprecated use bottom-start instead
|
|
146
|
-
'bottom-right',
|
|
145
|
+
'bottom-start', 'bottom-right',
|
|
147
146
|
// deprecated use bottom-end instead
|
|
148
|
-
|
|
149
|
-
'left', 'left-bottom',
|
|
147
|
+
'bottom-end', 'left', 'left-bottom',
|
|
150
148
|
// deprecated use left-end instead
|
|
151
|
-
'left-top',
|
|
149
|
+
'left-end', 'left-top',
|
|
152
150
|
// deprecated use left-start instead
|
|
153
|
-
|
|
154
|
-
'right', 'right-bottom',
|
|
151
|
+
'left-start', 'right', 'right-bottom',
|
|
155
152
|
// deprecated use right-end instead
|
|
156
|
-
'right-top',
|
|
153
|
+
'right-end', 'right-top',
|
|
157
154
|
// deprecated use right-start instead
|
|
158
|
-
|
|
159
|
-
// new values to match floating-ui
|
|
160
|
-
'top-start', 'top-end', 'bottom-start', 'bottom-end', 'left-end', 'left-start', 'right-end', 'right-start']),
|
|
155
|
+
'right-start']),
|
|
161
156
|
/**
|
|
162
157
|
* Will auto-align the popover. This prop is currently experimental and is subject to future changes.
|
|
163
158
|
*/
|
|
@@ -199,7 +199,8 @@ function TabList(_ref2) {
|
|
|
199
199
|
// TODO: V12 - Remove this class
|
|
200
200
|
[`${prefix}--layout--size-lg`]: iconSize === 'lg',
|
|
201
201
|
[`${prefix}--tabs--tall`]: hasSecondaryLabelTabs,
|
|
202
|
-
[`${prefix}--tabs--full-width`]: distributeWidth
|
|
202
|
+
[`${prefix}--tabs--full-width`]: distributeWidth,
|
|
203
|
+
[`${prefix}--tabs--dismissable`]: dismissable
|
|
203
204
|
}, customClassName);
|
|
204
205
|
|
|
205
206
|
// Previous Button
|
|
@@ -541,6 +542,25 @@ const Tab = /*#__PURE__*/forwardRef(function Tab(_ref5, forwardRef) {
|
|
|
541
542
|
const handleClose = evt => {
|
|
542
543
|
evt.stopPropagation();
|
|
543
544
|
onTabCloseRequest?.(index);
|
|
545
|
+
|
|
546
|
+
// set focus after removing tab
|
|
547
|
+
if (tabRef.current && tabRef.current.parentElement) {
|
|
548
|
+
// determine number of tabs, excluding disabled
|
|
549
|
+
const tabCount = Array.from(tabRef.current.parentElement.childNodes).filter(node => {
|
|
550
|
+
const element = node;
|
|
551
|
+
return element.classList.contains('cds--tabs__nav-link') && !element.classList.contains('cds--tabs__nav-item--disabled');
|
|
552
|
+
}).length;
|
|
553
|
+
|
|
554
|
+
// if not removing last tab focus on next tab
|
|
555
|
+
if (tabRef.current && index + 1 !== tabCount) {
|
|
556
|
+
tabRef.current.focus();
|
|
557
|
+
}
|
|
558
|
+
// if removing last tab focus on previous tab
|
|
559
|
+
else {
|
|
560
|
+
const prevTabIndex = (tabCount - 2) * 2;
|
|
561
|
+
tabRef.current.parentElement.childNodes[prevTabIndex]?.focus();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
544
564
|
};
|
|
545
565
|
const handleKeyDown = event => {
|
|
546
566
|
if (dismissable && match(event, Delete)) {
|
|
@@ -549,20 +569,31 @@ const Tab = /*#__PURE__*/forwardRef(function Tab(_ref5, forwardRef) {
|
|
|
549
569
|
onKeyDown?.(event);
|
|
550
570
|
};
|
|
551
571
|
const DismissIcon = /*#__PURE__*/React__default.createElement("div", {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
572
|
+
className: cx({
|
|
573
|
+
[`${prefix}--tabs__nav-item--close`]: dismissable,
|
|
574
|
+
[`${prefix}--tabs__nav-item--close--hidden`]: !dismissable
|
|
575
|
+
})
|
|
576
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
577
|
+
type: "button",
|
|
578
|
+
tabIndex: selectedIndex === index && dismissable ? 0 : -1,
|
|
579
|
+
"aria-disabled": disabled,
|
|
580
|
+
"aria-hidden": selectedIndex === index && dismissable ? 'false' : 'true',
|
|
581
|
+
disabled: disabled,
|
|
582
|
+
className: cx({
|
|
583
|
+
[`${prefix}--tabs__nav-item--close-icon`]: dismissable,
|
|
584
|
+
[`${prefix}--visually-hidden`]: !dismissable,
|
|
585
|
+
[`${prefix}--tabs__nav-item--close-icon--selected`]: selectedIndex === index,
|
|
586
|
+
[`${prefix}--tabs__nav-item--close-icon--disabled`]: disabled
|
|
556
587
|
}),
|
|
557
588
|
onClick: handleClose,
|
|
558
|
-
title:
|
|
589
|
+
title: `Remove ${typeof children === 'string' ? children : ''} tab`,
|
|
559
590
|
ref: dismissIconRef
|
|
560
591
|
}, /*#__PURE__*/React__default.createElement(Close, {
|
|
561
|
-
"aria-hidden": dismissable ? 'false' : 'true',
|
|
562
|
-
"aria-label":
|
|
563
|
-
}));
|
|
592
|
+
"aria-hidden": selectedIndex === index && dismissable ? 'false' : 'true',
|
|
593
|
+
"aria-label": `Press delete to remove ${typeof children === 'string' ? children : ''} tab`
|
|
594
|
+
})));
|
|
564
595
|
const hasIcon = Icon ?? dismissable;
|
|
565
|
-
return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
|
|
596
|
+
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
|
|
566
597
|
"aria-controls": panelId,
|
|
567
598
|
"aria-disabled": disabled,
|
|
568
599
|
"aria-selected": selectedIndex === index,
|
|
@@ -589,17 +620,17 @@ const Tab = /*#__PURE__*/forwardRef(function Tab(_ref5, forwardRef) {
|
|
|
589
620
|
size: 16
|
|
590
621
|
})), /*#__PURE__*/React__default.createElement(Text, {
|
|
591
622
|
className: `${prefix}--tabs__nav-item-label`
|
|
592
|
-
}, children), /*#__PURE__*/React__default.createElement("div", {
|
|
623
|
+
}, children), !dismissable && Icon && /*#__PURE__*/React__default.createElement("div", {
|
|
593
624
|
className: cx(`${prefix}--tabs__nav-item--icon`, {
|
|
594
625
|
[`${prefix}--visually-hidden`]: !hasIcon
|
|
595
626
|
})
|
|
596
|
-
},
|
|
627
|
+
}, !dismissable && Icon && /*#__PURE__*/React__default.createElement(Icon, {
|
|
597
628
|
size: 16
|
|
598
629
|
}))), hasSecondaryLabel && secondaryLabel && /*#__PURE__*/React__default.createElement(Text, {
|
|
599
630
|
as: "div",
|
|
600
631
|
className: `${prefix}--tabs__nav-item-secondary-label`,
|
|
601
632
|
title: secondaryLabel
|
|
602
|
-
}, secondaryLabel));
|
|
633
|
+
}, secondaryLabel)), DismissIcon);
|
|
603
634
|
});
|
|
604
635
|
Tab.propTypes = {
|
|
605
636
|
/**
|
|
@@ -0,0 +1,119 @@
|
|
|
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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
import React__default from 'react';
|
|
11
|
+
import cx from 'classnames';
|
|
12
|
+
import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
|
|
13
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
+
import Tag, { SIZES, TYPES } from './Tag.js';
|
|
15
|
+
import { Close } from '@carbon/icons-react';
|
|
16
|
+
|
|
17
|
+
var _Close;
|
|
18
|
+
const getInstanceId = setupGetInstanceId();
|
|
19
|
+
const DismissibleTag = _ref => {
|
|
20
|
+
let {
|
|
21
|
+
children,
|
|
22
|
+
className,
|
|
23
|
+
disabled,
|
|
24
|
+
id,
|
|
25
|
+
renderIcon,
|
|
26
|
+
title = 'Clear filter',
|
|
27
|
+
onClose,
|
|
28
|
+
slug,
|
|
29
|
+
size,
|
|
30
|
+
type,
|
|
31
|
+
...other
|
|
32
|
+
} = _ref;
|
|
33
|
+
const prefix = usePrefix();
|
|
34
|
+
const tagId = id || `tag-${getInstanceId()}`;
|
|
35
|
+
const tagClasses = cx(`${prefix}--tag--filter`, className);
|
|
36
|
+
const handleClose = event => {
|
|
37
|
+
if (onClose) {
|
|
38
|
+
event.stopPropagation();
|
|
39
|
+
onClose(event);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
let normalizedSlug;
|
|
43
|
+
if (slug && slug['type']?.displayName === 'Slug') {
|
|
44
|
+
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
45
|
+
size: 'sm',
|
|
46
|
+
kind: 'inline'
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Removing onClick from the spread operator
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
|
+
const {
|
|
53
|
+
onClick,
|
|
54
|
+
...otherProps
|
|
55
|
+
} = other;
|
|
56
|
+
return /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
57
|
+
type: type,
|
|
58
|
+
size: size,
|
|
59
|
+
renderIcon: renderIcon,
|
|
60
|
+
disabled: disabled,
|
|
61
|
+
className: tagClasses,
|
|
62
|
+
id: tagId
|
|
63
|
+
}, otherProps), /*#__PURE__*/React__default.createElement("div", {
|
|
64
|
+
className: `${prefix}--interactive--tag-children`
|
|
65
|
+
}, children, normalizedSlug, /*#__PURE__*/React__default.createElement("button", {
|
|
66
|
+
type: "button",
|
|
67
|
+
className: `${prefix}--tag__close-icon`,
|
|
68
|
+
onClick: handleClose,
|
|
69
|
+
disabled: disabled,
|
|
70
|
+
"aria-label": title,
|
|
71
|
+
title: title
|
|
72
|
+
}, _Close || (_Close = /*#__PURE__*/React__default.createElement(Close, null)))));
|
|
73
|
+
};
|
|
74
|
+
DismissibleTag.propTypes = {
|
|
75
|
+
/**
|
|
76
|
+
* Provide content to be rendered inside of a `DismissibleTag`
|
|
77
|
+
*/
|
|
78
|
+
children: PropTypes.node,
|
|
79
|
+
/**
|
|
80
|
+
* Provide a custom className that is applied to the containing <span>
|
|
81
|
+
*/
|
|
82
|
+
className: PropTypes.string,
|
|
83
|
+
/**
|
|
84
|
+
* Specify if the `DismissibleTag` is disabled
|
|
85
|
+
*/
|
|
86
|
+
disabled: PropTypes.bool,
|
|
87
|
+
/**
|
|
88
|
+
* Specify the id for the tag.
|
|
89
|
+
*/
|
|
90
|
+
id: PropTypes.string,
|
|
91
|
+
/**
|
|
92
|
+
* Click handler for filter tag close button.
|
|
93
|
+
*/
|
|
94
|
+
onClose: PropTypes.func,
|
|
95
|
+
/**
|
|
96
|
+
* Optional prop to render a custom icon.
|
|
97
|
+
* Can be a React component class
|
|
98
|
+
*/
|
|
99
|
+
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
100
|
+
/**
|
|
101
|
+
* Specify the size of the Tag. Currently supports either `sm`,
|
|
102
|
+
* `md` (default) or `lg` sizes.
|
|
103
|
+
*/
|
|
104
|
+
size: PropTypes.oneOf(Object.keys(SIZES)),
|
|
105
|
+
/**
|
|
106
|
+
* **Experimental:** Provide a `Slug` component to be rendered inside the `DismissibleTag` component
|
|
107
|
+
*/
|
|
108
|
+
slug: PropTypes.node,
|
|
109
|
+
/**
|
|
110
|
+
* Text to show on clear filters
|
|
111
|
+
*/
|
|
112
|
+
title: PropTypes.string,
|
|
113
|
+
/**
|
|
114
|
+
* Specify the type of the `Tag`
|
|
115
|
+
*/
|
|
116
|
+
type: PropTypes.oneOf(Object.keys(TYPES))
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { DismissibleTag as default };
|
|
@@ -0,0 +1,99 @@
|
|
|
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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
import React__default from 'react';
|
|
11
|
+
import cx from 'classnames';
|
|
12
|
+
import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
|
|
13
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
+
import Tag, { SIZES } from './Tag.js';
|
|
15
|
+
|
|
16
|
+
const getInstanceId = setupGetInstanceId();
|
|
17
|
+
const TYPES = {
|
|
18
|
+
red: 'Red',
|
|
19
|
+
magenta: 'Magenta',
|
|
20
|
+
purple: 'Purple',
|
|
21
|
+
blue: 'Blue',
|
|
22
|
+
cyan: 'Cyan',
|
|
23
|
+
teal: 'Teal',
|
|
24
|
+
green: 'Green',
|
|
25
|
+
gray: 'Gray',
|
|
26
|
+
'cool-gray': 'Cool-Gray',
|
|
27
|
+
'warm-gray': 'Warm-Gray'
|
|
28
|
+
};
|
|
29
|
+
const OperationalTag = _ref => {
|
|
30
|
+
let {
|
|
31
|
+
children,
|
|
32
|
+
className,
|
|
33
|
+
disabled,
|
|
34
|
+
id,
|
|
35
|
+
renderIcon,
|
|
36
|
+
slug,
|
|
37
|
+
size,
|
|
38
|
+
type = 'gray',
|
|
39
|
+
...other
|
|
40
|
+
} = _ref;
|
|
41
|
+
const prefix = usePrefix();
|
|
42
|
+
const tagId = id || `tag-${getInstanceId()}`;
|
|
43
|
+
const tagClasses = cx(`${prefix}--tag--operational`, className);
|
|
44
|
+
let normalizedSlug;
|
|
45
|
+
if (slug && slug['type']?.displayName === 'Slug') {
|
|
46
|
+
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
47
|
+
size: 'sm',
|
|
48
|
+
kind: 'inline'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
52
|
+
type: type,
|
|
53
|
+
size: size,
|
|
54
|
+
renderIcon: renderIcon,
|
|
55
|
+
disabled: disabled,
|
|
56
|
+
className: tagClasses,
|
|
57
|
+
id: tagId
|
|
58
|
+
}, other), /*#__PURE__*/React__default.createElement("div", {
|
|
59
|
+
className: `${prefix}--interactive--tag-children`
|
|
60
|
+
}, children, normalizedSlug));
|
|
61
|
+
};
|
|
62
|
+
OperationalTag.propTypes = {
|
|
63
|
+
/**
|
|
64
|
+
* Provide content to be rendered inside of a `OperationalTag`
|
|
65
|
+
*/
|
|
66
|
+
children: PropTypes.node,
|
|
67
|
+
/**
|
|
68
|
+
* Provide a custom className that is applied to the containing <span>
|
|
69
|
+
*/
|
|
70
|
+
className: PropTypes.string,
|
|
71
|
+
/**
|
|
72
|
+
* Specify if the `OperationalTag` is disabled
|
|
73
|
+
*/
|
|
74
|
+
disabled: PropTypes.bool,
|
|
75
|
+
/**
|
|
76
|
+
* Specify the id for the tag.
|
|
77
|
+
*/
|
|
78
|
+
id: PropTypes.string,
|
|
79
|
+
/**
|
|
80
|
+
* Optional prop to render a custom icon.
|
|
81
|
+
* Can be a React component class
|
|
82
|
+
*/
|
|
83
|
+
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
84
|
+
/**
|
|
85
|
+
* Specify the size of the Tag. Currently supports either `sm`,
|
|
86
|
+
* `md` (default) or `lg` sizes.
|
|
87
|
+
*/
|
|
88
|
+
size: PropTypes.oneOf(Object.keys(SIZES)),
|
|
89
|
+
/**
|
|
90
|
+
* **Experimental:** Provide a `Slug` component to be rendered inside the `OperationalTag` component
|
|
91
|
+
*/
|
|
92
|
+
slug: PropTypes.node,
|
|
93
|
+
/**
|
|
94
|
+
* Specify the type of the `Tag`
|
|
95
|
+
*/
|
|
96
|
+
type: PropTypes.oneOf(Object.keys(TYPES))
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export { OperationalTag as default };
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
import React__default, { useState } from 'react';
|
|
11
|
+
import cx from 'classnames';
|
|
12
|
+
import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
|
|
13
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
+
import Tag, { SIZES } from './Tag.js';
|
|
15
|
+
|
|
16
|
+
const getInstanceId = setupGetInstanceId();
|
|
17
|
+
const SelectableTag = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
children,
|
|
20
|
+
className,
|
|
21
|
+
disabled,
|
|
22
|
+
id,
|
|
23
|
+
renderIcon,
|
|
24
|
+
selected = false,
|
|
25
|
+
slug,
|
|
26
|
+
size,
|
|
27
|
+
...other
|
|
28
|
+
} = _ref;
|
|
29
|
+
const prefix = usePrefix();
|
|
30
|
+
const tagId = id || `tag-${getInstanceId()}`;
|
|
31
|
+
const [selectedTag, setSelectedTag] = useState(selected);
|
|
32
|
+
const tagClasses = cx(`${prefix}--tag--selectable`, className, {
|
|
33
|
+
[`${prefix}--tag--selectable-selected`]: selectedTag
|
|
34
|
+
});
|
|
35
|
+
let normalizedSlug;
|
|
36
|
+
if (slug && slug['type']?.displayName === 'Slug') {
|
|
37
|
+
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
38
|
+
size: 'sm',
|
|
39
|
+
kind: 'inline'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Removing onClick from the spread operator
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
const {
|
|
46
|
+
onClick,
|
|
47
|
+
...otherProps
|
|
48
|
+
} = other;
|
|
49
|
+
return /*#__PURE__*/React__default.createElement(Tag, _extends({
|
|
50
|
+
slug: slug,
|
|
51
|
+
size: size,
|
|
52
|
+
renderIcon: renderIcon,
|
|
53
|
+
disabled: disabled,
|
|
54
|
+
className: tagClasses,
|
|
55
|
+
id: tagId,
|
|
56
|
+
onClick: () => setSelectedTag(!selectedTag)
|
|
57
|
+
}, otherProps), /*#__PURE__*/React__default.createElement("div", {
|
|
58
|
+
className: `${prefix}--interactive--tag-children`
|
|
59
|
+
}, children, normalizedSlug));
|
|
60
|
+
};
|
|
61
|
+
SelectableTag.propTypes = {
|
|
62
|
+
/**
|
|
63
|
+
* Provide content to be rendered inside of a `SelectableTag`
|
|
64
|
+
*/
|
|
65
|
+
children: PropTypes.node,
|
|
66
|
+
/**
|
|
67
|
+
* Provide a custom className that is applied to the containing <span>
|
|
68
|
+
*/
|
|
69
|
+
className: PropTypes.string,
|
|
70
|
+
/**
|
|
71
|
+
* Specify if the `SelectableTag` is disabled
|
|
72
|
+
*/
|
|
73
|
+
disabled: PropTypes.bool,
|
|
74
|
+
/**
|
|
75
|
+
* Specify the id for the tag.
|
|
76
|
+
*/
|
|
77
|
+
id: PropTypes.string,
|
|
78
|
+
/**
|
|
79
|
+
* Optional prop to render a custom icon.
|
|
80
|
+
* Can be a React component class
|
|
81
|
+
*/
|
|
82
|
+
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
83
|
+
/**
|
|
84
|
+
* Specify the state of the selectable tag.
|
|
85
|
+
*/
|
|
86
|
+
selected: PropTypes.bool,
|
|
87
|
+
/**
|
|
88
|
+
* Specify the size of the Tag. Currently supports either `sm`,
|
|
89
|
+
* `md` (default) or `lg` sizes.
|
|
90
|
+
*/
|
|
91
|
+
size: PropTypes.oneOf(Object.keys(SIZES)),
|
|
92
|
+
/**
|
|
93
|
+
* **Experimental:** Provide a `Slug` component to be rendered inside the `SelectableTag` component
|
|
94
|
+
*/
|
|
95
|
+
slug: PropTypes.node
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export { SelectableTag as default };
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import Tag from './Tag';
|
|
8
|
+
import DismissibleTag from './DismissibleTag';
|
|
9
|
+
import OperationalTag from './OperationalTag';
|
|
10
|
+
import SelectableTag from './SelectableTag';
|
|
8
11
|
export * from './Tag.Skeleton';
|
|
9
12
|
export default Tag;
|
|
10
|
-
export { Tag };
|
|
13
|
+
export { Tag, DismissibleTag, OperationalTag, SelectableTag };
|
|
@@ -56,7 +56,7 @@ const TreeNode = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
56
56
|
return /*#__PURE__*/React__default.cloneElement(node, {
|
|
57
57
|
active,
|
|
58
58
|
depth: depth + 1,
|
|
59
|
-
disabled,
|
|
59
|
+
disabled: disabled || node.props.disabled,
|
|
60
60
|
onTreeSelect,
|
|
61
61
|
selected,
|
|
62
62
|
tabIndex: !node.props.disabled && -1 || null
|