@carbon/react 1.54.0 → 1.55.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 +981 -1010
- 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.js +2 -2
- package/es/components/DataTable/TableBatchAction.d.ts +1 -5
- package/es/components/Dropdown/Dropdown.js +3 -1
- package/es/components/Modal/Modal.js +2 -2
- 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/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/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.js +2 -2
- package/lib/components/DataTable/TableBatchAction.d.ts +1 -5
- package/lib/components/Dropdown/Dropdown.js +3 -1
- package/lib/components/Modal/Modal.js +2 -2
- 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/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/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 +3 -3
|
@@ -0,0 +1,196 @@
|
|
|
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 { PropsWithChildren } from 'react';
|
|
9
|
+
export interface CodeSnippetProps {
|
|
10
|
+
/**
|
|
11
|
+
* Specify how the trigger should align with the tooltip
|
|
12
|
+
*/
|
|
13
|
+
align?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'right';
|
|
14
|
+
/**
|
|
15
|
+
* Specify a label to be read by screen readers on the containing textbox
|
|
16
|
+
* node
|
|
17
|
+
*/
|
|
18
|
+
['aria-label']?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Deprecated, please use `aria-label` instead.
|
|
21
|
+
* Specify a label to be read by screen readers on the containing textbox
|
|
22
|
+
* node
|
|
23
|
+
*/
|
|
24
|
+
ariaLabel?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Specify an optional className to be applied to the container node
|
|
27
|
+
*/
|
|
28
|
+
className?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Specify the description for the Copy Button
|
|
31
|
+
*/
|
|
32
|
+
copyButtonDescription?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional text to copy. If not specified, the `children` node's `innerText`
|
|
35
|
+
* will be used as the copy value.
|
|
36
|
+
*/
|
|
37
|
+
copyText?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Specify whether or not the CodeSnippet should be disabled
|
|
40
|
+
*/
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Specify the string displayed when the snippet is copied
|
|
44
|
+
*/
|
|
45
|
+
feedback?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Specify the time it takes for the feedback message to timeout
|
|
48
|
+
*/
|
|
49
|
+
feedbackTimeout?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Specify whether or not a copy button should be used/rendered.
|
|
52
|
+
*/
|
|
53
|
+
hideCopyButton?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Specify whether you are using the light variant of the Code Snippet,
|
|
56
|
+
* typically used for inline snippet to display an alternate color
|
|
57
|
+
*/
|
|
58
|
+
light?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Specify the maximum number of rows to be shown when in collapsed view
|
|
61
|
+
*/
|
|
62
|
+
maxCollapsedNumberOfRows?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Specify the maximum number of rows to be shown when in expanded view
|
|
65
|
+
*/
|
|
66
|
+
maxExpandedNumberOfRows?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Specify the minimum number of rows to be shown when in collapsed view
|
|
69
|
+
*/
|
|
70
|
+
minCollapsedNumberOfRows?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Specify the minimum number of rows to be shown when in expanded view
|
|
73
|
+
*/
|
|
74
|
+
minExpandedNumberOfRows?: number;
|
|
75
|
+
/**
|
|
76
|
+
* An optional handler to listen to the `onClick` even fired by the Copy
|
|
77
|
+
* Button
|
|
78
|
+
*/
|
|
79
|
+
onClick?: (e: MouseEvent) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Specify a string that is displayed when the Code Snippet has been
|
|
82
|
+
* interacted with to show more lines
|
|
83
|
+
*/
|
|
84
|
+
showLessText?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Specify a string that is displayed when the Code Snippet text is more
|
|
87
|
+
* than 15 lines
|
|
88
|
+
*/
|
|
89
|
+
showMoreText?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Provide the type of Code Snippet
|
|
92
|
+
*/
|
|
93
|
+
type?: 'single' | 'inline' | 'multi';
|
|
94
|
+
/**
|
|
95
|
+
* Specify whether or not to wrap the text.
|
|
96
|
+
*/
|
|
97
|
+
wrapText?: boolean;
|
|
98
|
+
}
|
|
99
|
+
declare function CodeSnippet({ align, className, type, children, disabled, feedback, feedbackTimeout, onClick, ['aria-label']: ariaLabel, ariaLabel: deprecatedAriaLabel, copyText, copyButtonDescription, light, showMoreText, showLessText, hideCopyButton, wrapText, maxCollapsedNumberOfRows, maxExpandedNumberOfRows, minCollapsedNumberOfRows, minExpandedNumberOfRows, ...rest }: PropsWithChildren<CodeSnippetProps>): import("react/jsx-runtime").JSX.Element;
|
|
100
|
+
declare namespace CodeSnippet {
|
|
101
|
+
var propTypes: {
|
|
102
|
+
/**
|
|
103
|
+
* Specify how the trigger should align with the tooltip
|
|
104
|
+
*/
|
|
105
|
+
align: PropTypes.Requireable<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Specify a label to be read by screen readers on the containing textbox
|
|
108
|
+
* node
|
|
109
|
+
*/
|
|
110
|
+
"aria-label": PropTypes.Requireable<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Deprecated, please use `aria-label` instead.
|
|
113
|
+
* Specify a label to be read by screen readers on the containing textbox
|
|
114
|
+
* node
|
|
115
|
+
*/
|
|
116
|
+
ariaLabel: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
117
|
+
/**
|
|
118
|
+
* Provide the content of your CodeSnippet as a node or string
|
|
119
|
+
*/
|
|
120
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
121
|
+
/**
|
|
122
|
+
* Specify an optional className to be applied to the container node
|
|
123
|
+
*/
|
|
124
|
+
className: PropTypes.Requireable<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Specify the description for the Copy Button
|
|
127
|
+
*/
|
|
128
|
+
copyButtonDescription: PropTypes.Requireable<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Optional text to copy. If not specified, the `children` node's `innerText`
|
|
131
|
+
* will be used as the copy value.
|
|
132
|
+
*/
|
|
133
|
+
copyText: PropTypes.Requireable<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Specify whether or not the CodeSnippet should be disabled
|
|
136
|
+
*/
|
|
137
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
138
|
+
/**
|
|
139
|
+
* Specify the string displayed when the snippet is copied
|
|
140
|
+
*/
|
|
141
|
+
feedback: PropTypes.Requireable<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Specify the time it takes for the feedback message to timeout
|
|
144
|
+
*/
|
|
145
|
+
feedbackTimeout: PropTypes.Requireable<number>;
|
|
146
|
+
/**
|
|
147
|
+
* Specify whether or not a copy button should be used/rendered.
|
|
148
|
+
*/
|
|
149
|
+
hideCopyButton: PropTypes.Requireable<boolean>;
|
|
150
|
+
/**
|
|
151
|
+
* Specify whether you are using the light variant of the Code Snippet,
|
|
152
|
+
* typically used for inline snippet to display an alternate color
|
|
153
|
+
*/
|
|
154
|
+
light: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
155
|
+
/**
|
|
156
|
+
* Specify the maximum number of rows to be shown when in collapsed view
|
|
157
|
+
*/
|
|
158
|
+
maxCollapsedNumberOfRows: PropTypes.Requireable<number>;
|
|
159
|
+
/**
|
|
160
|
+
* Specify the maximum number of rows to be shown when in expanded view
|
|
161
|
+
*/
|
|
162
|
+
maxExpandedNumberOfRows: PropTypes.Requireable<number>;
|
|
163
|
+
/**
|
|
164
|
+
* Specify the minimum number of rows to be shown when in collapsed view
|
|
165
|
+
*/
|
|
166
|
+
minCollapsedNumberOfRows: PropTypes.Requireable<number>;
|
|
167
|
+
/**
|
|
168
|
+
* Specify the minimum number of rows to be shown when in expanded view
|
|
169
|
+
*/
|
|
170
|
+
minExpandedNumberOfRows: PropTypes.Requireable<number>;
|
|
171
|
+
/**
|
|
172
|
+
* An optional handler to listen to the `onClick` even fired by the Copy
|
|
173
|
+
* Button
|
|
174
|
+
*/
|
|
175
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
176
|
+
/**
|
|
177
|
+
* Specify a string that is displayed when the Code Snippet has been
|
|
178
|
+
* interacted with to show more lines
|
|
179
|
+
*/
|
|
180
|
+
showLessText: PropTypes.Requireable<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Specify a string that is displayed when the Code Snippet text is more
|
|
183
|
+
* than 15 lines
|
|
184
|
+
*/
|
|
185
|
+
showMoreText: PropTypes.Requireable<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Provide the type of Code Snippet
|
|
188
|
+
*/
|
|
189
|
+
type: PropTypes.Requireable<string>;
|
|
190
|
+
/**
|
|
191
|
+
* Specify whether or not to wrap the text.
|
|
192
|
+
*/
|
|
193
|
+
wrapText: PropTypes.Requireable<boolean>;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export default CodeSnippet;
|
|
@@ -36,7 +36,7 @@ const rowHeightInPixels = 16;
|
|
|
36
36
|
const defaultMaxCollapsedNumberOfRows = 15;
|
|
37
37
|
const defaultMaxExpandedNumberOfRows = 0;
|
|
38
38
|
const defaultMinCollapsedNumberOfRows = 3;
|
|
39
|
-
const defaultMinExpandedNumberOfRows =
|
|
39
|
+
const defaultMinExpandedNumberOfRows = 16;
|
|
40
40
|
function CodeSnippet(_ref) {
|
|
41
41
|
let {
|
|
42
42
|
align = 'bottom',
|
|
@@ -67,9 +67,9 @@ function CodeSnippet(_ref) {
|
|
|
67
67
|
const {
|
|
68
68
|
current: uid
|
|
69
69
|
} = React.useRef(uniqueId["default"]());
|
|
70
|
-
const codeContentRef = React.useRef();
|
|
71
|
-
const codeContainerRef = React.useRef();
|
|
72
|
-
const innerCodeRef = React.useRef();
|
|
70
|
+
const codeContentRef = React.useRef(null);
|
|
71
|
+
const codeContainerRef = React.useRef(null);
|
|
72
|
+
const innerCodeRef = React.useRef(null);
|
|
73
73
|
const [hasLeftOverflow, setHasLeftOverflow] = React.useState(false);
|
|
74
74
|
const [hasRightOverflow, setHasRightOverflow] = React.useState(false);
|
|
75
75
|
const getCodeRef = React.useCallback(() => {
|
|
@@ -78,15 +78,17 @@ function CodeSnippet(_ref) {
|
|
|
78
78
|
}
|
|
79
79
|
if (type === 'multi') {
|
|
80
80
|
return codeContentRef;
|
|
81
|
+
} else {
|
|
82
|
+
return innerCodeRef;
|
|
81
83
|
}
|
|
82
84
|
}, [type]);
|
|
83
85
|
const prefix = usePrefix.usePrefix();
|
|
84
86
|
const getCodeRefDimensions = React.useCallback(() => {
|
|
85
87
|
const {
|
|
86
|
-
clientWidth: codeClientWidth,
|
|
87
|
-
scrollLeft: codeScrollLeft,
|
|
88
|
-
scrollWidth: codeScrollWidth
|
|
89
|
-
} = getCodeRef().current;
|
|
88
|
+
clientWidth: codeClientWidth = 0,
|
|
89
|
+
scrollLeft: codeScrollLeft = 0,
|
|
90
|
+
scrollWidth: codeScrollWidth = 0
|
|
91
|
+
} = getCodeRef().current || {};
|
|
90
92
|
return {
|
|
91
93
|
horizontalOverflow: codeScrollWidth > codeClientWidth,
|
|
92
94
|
codeClientWidth,
|
|
@@ -113,7 +115,7 @@ function CodeSnippet(_ref) {
|
|
|
113
115
|
if (codeContentRef?.current && type === 'multi') {
|
|
114
116
|
const {
|
|
115
117
|
height
|
|
116
|
-
} =
|
|
118
|
+
} = codeContentRef.current.getBoundingClientRect();
|
|
117
119
|
if (maxCollapsedNumberOfRows > 0 && (maxExpandedNumberOfRows <= 0 || maxExpandedNumberOfRows > maxCollapsedNumberOfRows) && height > maxCollapsedNumberOfRows * rowHeightInPixels) {
|
|
118
120
|
setShouldShowMoreLessBtn(true);
|
|
119
121
|
} else {
|
|
@@ -127,13 +129,13 @@ function CodeSnippet(_ref) {
|
|
|
127
129
|
handleScroll();
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
|
-
}
|
|
132
|
+
});
|
|
131
133
|
React.useEffect(() => {
|
|
132
134
|
handleScroll();
|
|
133
135
|
}, [handleScroll]);
|
|
134
136
|
const handleCopyClick = evt => {
|
|
135
137
|
if (copyText || innerCodeRef?.current) {
|
|
136
|
-
copy__default["default"](copyText ?? innerCodeRef?.current?.innerText);
|
|
138
|
+
copy__default["default"](copyText ?? innerCodeRef?.current?.innerText ?? '');
|
|
137
139
|
}
|
|
138
140
|
if (onClick) {
|
|
139
141
|
onClick(evt);
|
|
@@ -167,12 +169,11 @@ function CodeSnippet(_ref) {
|
|
|
167
169
|
feedback: feedback,
|
|
168
170
|
feedbackTimeout: feedbackTimeout
|
|
169
171
|
}), /*#__PURE__*/React__default["default"].createElement("code", {
|
|
170
|
-
"aria-live": "assertive",
|
|
171
172
|
id: uid,
|
|
172
173
|
ref: innerCodeRef
|
|
173
174
|
}, children));
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
+
const containerStyle = {};
|
|
176
177
|
if (type === 'multi') {
|
|
177
178
|
const styles = {};
|
|
178
179
|
if (expandedCode) {
|
|
@@ -198,16 +199,16 @@ function CodeSnippet(_ref) {
|
|
|
198
199
|
className: codeSnippetClasses
|
|
199
200
|
}), /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
|
|
200
201
|
ref: codeContainerRef,
|
|
201
|
-
role: type === 'single' || type === 'multi' ? 'textbox' :
|
|
202
|
-
tabIndex: (type === 'single' || type === 'multi') && !disabled ? 0 :
|
|
202
|
+
role: type === 'single' || type === 'multi' ? 'textbox' : undefined,
|
|
203
|
+
tabIndex: (type === 'single' || type === 'multi') && !disabled ? 0 : undefined,
|
|
203
204
|
className: `${prefix}--snippet-container`,
|
|
204
205
|
"aria-label": deprecatedAriaLabel || ariaLabel || 'code-snippet',
|
|
205
|
-
"aria-readonly": type === 'single' || type === 'multi' ? true :
|
|
206
|
-
"aria-multiline": type === 'multi' ? true :
|
|
207
|
-
onScroll: type === 'single' && handleScroll ||
|
|
206
|
+
"aria-readonly": type === 'single' || type === 'multi' ? true : undefined,
|
|
207
|
+
"aria-multiline": type === 'multi' ? true : undefined,
|
|
208
|
+
onScroll: type === 'single' && handleScroll || undefined
|
|
208
209
|
}, containerStyle), /*#__PURE__*/React__default["default"].createElement("pre", {
|
|
209
210
|
ref: codeContentRef,
|
|
210
|
-
onScroll: type === 'multi' && handleScroll ||
|
|
211
|
+
onScroll: type === 'multi' && handleScroll || undefined
|
|
211
212
|
}, /*#__PURE__*/React__default["default"].createElement("code", {
|
|
212
213
|
ref: innerCodeRef
|
|
213
214
|
}, children))), hasLeftOverflow && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -0,0 +1,10 @@
|
|
|
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 CodeSnippet from './CodeSnippet';
|
|
8
|
+
export default CodeSnippet;
|
|
9
|
+
export { CodeSnippet };
|
|
10
|
+
export { default as CodeSnippetSkeleton } from './CodeSnippet.Skeleton';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import Downshift from 'downshift';
|
|
8
8
|
import { ReactNodeLike } from 'prop-types';
|
|
9
|
-
import { type ComponentProps, type ReactNode, type ComponentType, type ReactElement, type RefAttributes, type PropsWithChildren, type
|
|
9
|
+
import { type ComponentProps, type ReactNode, type ComponentType, type ReactElement, type RefAttributes, type PropsWithChildren, type PropsWithRef, type InputHTMLAttributes, type MouseEvent } from 'react';
|
|
10
10
|
import { ListBoxSize } from '../ListBox';
|
|
11
11
|
type ExcludedAttributes = 'id' | 'onChange' | 'onClick' | 'type' | 'size';
|
|
12
12
|
interface OnChangeData<ItemType> {
|
|
@@ -159,7 +159,7 @@ export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLIn
|
|
|
159
159
|
*/
|
|
160
160
|
warnText?: ReactNode;
|
|
161
161
|
}
|
|
162
|
-
type ComboboxComponentProps<ItemType> =
|
|
162
|
+
type ComboboxComponentProps<ItemType> = PropsWithRef<PropsWithChildren<ComboBoxProps<ItemType>> & RefAttributes<HTMLInputElement>>;
|
|
163
163
|
interface ComboBoxComponent {
|
|
164
164
|
<ItemType>(props: ComboboxComponentProps<ItemType>): ReactElement | null;
|
|
165
165
|
}
|
|
@@ -42,9 +42,11 @@ const {
|
|
|
42
42
|
keyDownArrowUp,
|
|
43
43
|
keyDownEscape,
|
|
44
44
|
clickButton,
|
|
45
|
+
clickItem,
|
|
45
46
|
blurButton,
|
|
46
47
|
changeInput,
|
|
47
|
-
blurInput
|
|
48
|
+
blurInput,
|
|
49
|
+
unknown
|
|
48
50
|
} = Downshift__default["default"].stateChangeTypes;
|
|
49
51
|
const defaultItemToString = item => {
|
|
50
52
|
if (typeof item === 'string') {
|
|
@@ -206,15 +208,16 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
206
208
|
switch (type) {
|
|
207
209
|
case keyDownArrowDown:
|
|
208
210
|
case keyDownArrowUp:
|
|
209
|
-
|
|
211
|
+
if (changes.isOpen) {
|
|
212
|
+
updateHighlightedIndex(getHighlightedIndex(changes));
|
|
213
|
+
} else {
|
|
214
|
+
setHighlightedIndex(changes.highlightedIndex);
|
|
215
|
+
}
|
|
210
216
|
break;
|
|
211
217
|
case blurButton:
|
|
212
218
|
case keyDownEscape:
|
|
213
219
|
setHighlightedIndex(changes.highlightedIndex);
|
|
214
220
|
break;
|
|
215
|
-
case clickButton:
|
|
216
|
-
setHighlightedIndex(changes.highlightedIndex);
|
|
217
|
-
break;
|
|
218
221
|
case changeInput:
|
|
219
222
|
updateHighlightedIndex(getHighlightedIndex(changes));
|
|
220
223
|
break;
|
|
@@ -229,6 +232,11 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
229
232
|
}
|
|
230
233
|
}
|
|
231
234
|
break;
|
|
235
|
+
case clickButton:
|
|
236
|
+
case clickItem:
|
|
237
|
+
case unknown:
|
|
238
|
+
setHighlightedIndex(getHighlightedIndex(changes));
|
|
239
|
+
break;
|
|
232
240
|
}
|
|
233
241
|
};
|
|
234
242
|
const handleToggleClick = isOpen => event => {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 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 { IconButton } from '../IconButton';
|
|
9
|
+
import Button from '../Button';
|
|
10
|
+
import { Menu } from '../Menu';
|
|
11
|
+
interface ComboButtonProps {
|
|
12
|
+
/**
|
|
13
|
+
* A collection of `MenuItems` to be rendered as additional actions for this `ComboButton`.
|
|
14
|
+
*/
|
|
15
|
+
children: React.ComponentProps<typeof Menu>['children'];
|
|
16
|
+
/**
|
|
17
|
+
* Additional CSS class names.
|
|
18
|
+
*/
|
|
19
|
+
className?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Specify whether the `ComboButton` should be disabled, or not.
|
|
22
|
+
*/
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Provide the label to be rendered on the primary action button.
|
|
26
|
+
*/
|
|
27
|
+
label: React.ComponentProps<typeof Button>['title'];
|
|
28
|
+
/**
|
|
29
|
+
* Experimental property. Specify how the menu should align with the button element
|
|
30
|
+
*/
|
|
31
|
+
menuAlignment?: React.ComponentProps<typeof Menu>['menuAlignment'];
|
|
32
|
+
/**
|
|
33
|
+
* Provide an optional function to be called when the primary action element is clicked.
|
|
34
|
+
*/
|
|
35
|
+
onClick?: React.ComponentProps<typeof Button>['onClick'];
|
|
36
|
+
/**
|
|
37
|
+
* Specify the size of the buttons and menu.
|
|
38
|
+
*/
|
|
39
|
+
size?: 'sm' | 'md' | 'lg';
|
|
40
|
+
/**
|
|
41
|
+
* Specify how the trigger tooltip should be aligned.
|
|
42
|
+
*/
|
|
43
|
+
tooltipAlignment?: React.ComponentProps<typeof IconButton>['align'];
|
|
44
|
+
/**
|
|
45
|
+
* Optional method that takes in a message `id` and returns an
|
|
46
|
+
* internationalized string.
|
|
47
|
+
*/
|
|
48
|
+
translateWithId?: (id: string) => string;
|
|
49
|
+
}
|
|
50
|
+
declare const ComboButton: React.ForwardRefExoticComponent<ComboButtonProps & React.RefAttributes<HTMLDivElement>>;
|
|
51
|
+
export { ComboButton, type ComboButtonProps };
|
|
@@ -80,10 +80,12 @@ const ComboButton = /*#__PURE__*/React__default["default"].forwardRef(function C
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
function handleOpen() {
|
|
83
|
-
menuRef.current
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
if (menuRef.current) {
|
|
84
|
+
menuRef.current.style.inlineSize = `${width}px`;
|
|
85
|
+
menuRef.current.style.minInlineSize = `${width}px`;
|
|
86
|
+
if (menuAlignment !== 'bottom' && menuAlignment !== 'top') {
|
|
87
|
+
menuRef.current.style.inlineSize = `fit-content`;
|
|
88
|
+
}
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
const containerClasses = cx__default["default"](`${prefix}--combo-button__container`, `${prefix}--combo-button__container--${size}`, {
|
|
@@ -95,7 +97,7 @@ const ComboButton = /*#__PURE__*/React__default["default"].forwardRef(function C
|
|
|
95
97
|
return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
96
98
|
className: containerClasses,
|
|
97
99
|
ref: ref,
|
|
98
|
-
"aria-owns": open ? id :
|
|
100
|
+
"aria-owns": open ? id : undefined
|
|
99
101
|
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
100
102
|
className: primaryActionClasses
|
|
101
103
|
}, /*#__PURE__*/React__default["default"].createElement(Button["default"], {
|
|
@@ -113,7 +115,7 @@ const ComboButton = /*#__PURE__*/React__default["default"].forwardRef(function C
|
|
|
113
115
|
"aria-expanded": open,
|
|
114
116
|
onClick: handleTriggerClick,
|
|
115
117
|
onMouseDown: handleTriggerMousedown,
|
|
116
|
-
"aria-controls": open ? id :
|
|
118
|
+
"aria-controls": open ? id : undefined
|
|
117
119
|
}, _ChevronDown || (_ChevronDown = /*#__PURE__*/React__default["default"].createElement(iconsReact.ChevronDown, null))), /*#__PURE__*/React__default["default"].createElement(Menu.Menu, {
|
|
118
120
|
containerRef: containerRef,
|
|
119
121
|
menuAlignment: menuAlignment,
|
|
@@ -144,7 +146,7 @@ ComboButton.propTypes = {
|
|
|
144
146
|
*/
|
|
145
147
|
disabled: PropTypes__default["default"].bool,
|
|
146
148
|
/**
|
|
147
|
-
* Provide the label to be
|
|
149
|
+
* Provide the label to be rendered on the primary action button.
|
|
148
150
|
*/
|
|
149
151
|
label: PropTypes__default["default"].string.isRequired,
|
|
150
152
|
/**
|
|
@@ -253,11 +253,11 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
|
|
|
253
253
|
}
|
|
254
254
|
}, [open, selectorPrimaryFocus, isOpen]);
|
|
255
255
|
|
|
256
|
-
// Slug is always size `
|
|
256
|
+
// Slug is always size `sm`
|
|
257
257
|
let normalizedSlug;
|
|
258
258
|
if (slug && slug['type']?.displayName === 'Slug') {
|
|
259
259
|
normalizedSlug = /*#__PURE__*/React__default["default"].cloneElement(slug, {
|
|
260
|
-
size: '
|
|
260
|
+
size: 'sm'
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
263
|
return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
@@ -22,11 +22,7 @@ export interface TableBatchActionProps extends React.ButtonHTMLAttributes<HTMLBu
|
|
|
22
22
|
renderIcon?: React.ElementType;
|
|
23
23
|
}
|
|
24
24
|
declare const TableBatchAction: {
|
|
25
|
-
({ renderIcon, iconDescription, ...props }:
|
|
26
|
-
[x: string]: any;
|
|
27
|
-
renderIcon?: import("@carbon/icons-react").CarbonIconType | undefined;
|
|
28
|
-
iconDescription?: string | undefined;
|
|
29
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
({ renderIcon, iconDescription, ...props }: TableBatchActionProps): import("react/jsx-runtime").JSX.Element;
|
|
30
26
|
propTypes: {
|
|
31
27
|
/**
|
|
32
28
|
* Specify if the button is an icon-only button
|
|
@@ -36,7 +36,8 @@ const {
|
|
|
36
36
|
ToggleButtonKeyDownArrowUp,
|
|
37
37
|
ToggleButtonKeyDownHome,
|
|
38
38
|
ToggleButtonKeyDownEnd,
|
|
39
|
-
ItemMouseMove
|
|
39
|
+
ItemMouseMove,
|
|
40
|
+
MenuMouseLeave
|
|
40
41
|
} = Downshift.useSelect.stateChangeTypes;
|
|
41
42
|
const defaultItemToString = item => {
|
|
42
43
|
if (typeof item === 'string') {
|
|
@@ -121,6 +122,7 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
|
|
|
121
122
|
}
|
|
122
123
|
return changes;
|
|
123
124
|
case ItemMouseMove:
|
|
125
|
+
case MenuMouseLeave:
|
|
124
126
|
return {
|
|
125
127
|
...changes,
|
|
126
128
|
highlightedIndex: state.highlightedIndex
|
|
@@ -237,11 +237,11 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
|
|
|
237
237
|
};
|
|
238
238
|
}, []);
|
|
239
239
|
|
|
240
|
-
// Slug is always size `
|
|
240
|
+
// Slug is always size `sm`
|
|
241
241
|
let normalizedSlug;
|
|
242
242
|
if (slug && slug['type']?.displayName === 'Slug') {
|
|
243
243
|
normalizedSlug = /*#__PURE__*/React__default["default"].cloneElement(slug, {
|
|
244
|
-
size: '
|
|
244
|
+
size: 'sm'
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
const modalButton = /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -149,6 +149,9 @@ const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(
|
|
|
149
149
|
if (onMenuChange) {
|
|
150
150
|
onMenuChange(nextIsOpen);
|
|
151
151
|
}
|
|
152
|
+
if (!isOpen) {
|
|
153
|
+
setHighlightedIndex(0);
|
|
154
|
+
}
|
|
152
155
|
}
|
|
153
156
|
function handleOnOuterClick() {
|
|
154
157
|
handleOnMenuChange(false);
|
|
@@ -172,6 +175,34 @@ const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(
|
|
|
172
175
|
break;
|
|
173
176
|
case stateChangeTypes.keyDownEscape:
|
|
174
177
|
handleOnMenuChange(false);
|
|
178
|
+
setHighlightedIndex(0);
|
|
179
|
+
break;
|
|
180
|
+
case stateChangeTypes.changeInput:
|
|
181
|
+
setHighlightedIndex(0);
|
|
182
|
+
break;
|
|
183
|
+
case stateChangeTypes.keyDownEnter:
|
|
184
|
+
if (!isOpen) {
|
|
185
|
+
setHighlightedIndex(0);
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case stateChangeTypes.clickItem:
|
|
189
|
+
if (isOpen) {
|
|
190
|
+
const sortedItems = sortItems(filterItems(items, {
|
|
191
|
+
itemToString: itemToString$1,
|
|
192
|
+
inputValue
|
|
193
|
+
}), {
|
|
194
|
+
selectedItems: {
|
|
195
|
+
top: changes.selectedItems,
|
|
196
|
+
fixed: [],
|
|
197
|
+
'top-after-reopen': topItems
|
|
198
|
+
}[selectionFeedback],
|
|
199
|
+
itemToString: itemToString$1,
|
|
200
|
+
compareItems,
|
|
201
|
+
locale
|
|
202
|
+
});
|
|
203
|
+
const sortedSelectedIndex = sortedItems.indexOf(changes.selectedItem);
|
|
204
|
+
setHighlightedIndex(sortedSelectedIndex);
|
|
205
|
+
}
|
|
175
206
|
break;
|
|
176
207
|
}
|
|
177
208
|
}
|
|
@@ -48,9 +48,11 @@ const {
|
|
|
48
48
|
ToggleButtonKeyDownEscape,
|
|
49
49
|
ToggleButtonKeyDownSpaceButton,
|
|
50
50
|
ItemMouseMove,
|
|
51
|
+
MenuMouseLeave,
|
|
51
52
|
ToggleButtonClick,
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
ToggleButtonKeyDownPageDown,
|
|
54
|
+
ToggleButtonKeyDownPageUp,
|
|
55
|
+
FunctionSetHighlightedIndex
|
|
54
56
|
} = Downshift.useSelect.stateChangeTypes;
|
|
55
57
|
const defaultItemToString = item => {
|
|
56
58
|
if (typeof item === 'string') {
|
|
@@ -146,7 +148,8 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
|
|
|
146
148
|
getMenuProps,
|
|
147
149
|
getItemProps,
|
|
148
150
|
selectedItem,
|
|
149
|
-
highlightedIndex
|
|
151
|
+
highlightedIndex,
|
|
152
|
+
setHighlightedIndex
|
|
150
153
|
} = Downshift.useSelect(selectProps);
|
|
151
154
|
const toggleButtonProps = getToggleButtonProps({
|
|
152
155
|
onFocus: () => {
|
|
@@ -165,6 +168,7 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
|
|
|
165
168
|
setItemsCleared(true);
|
|
166
169
|
}
|
|
167
170
|
if ((match.match(e, keys.Space) || match.match(e, keys.ArrowDown) || match.match(e, keys.Enter)) && !isOpen) {
|
|
171
|
+
setHighlightedIndex(0);
|
|
168
172
|
setItemsCleared(false);
|
|
169
173
|
setIsOpenWrapper(true);
|
|
170
174
|
}
|
|
@@ -248,7 +252,6 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
|
|
|
248
252
|
setTopItems(controlledSelectedItems);
|
|
249
253
|
}
|
|
250
254
|
switch (type) {
|
|
251
|
-
case ItemClick:
|
|
252
255
|
case ToggleButtonKeyDownSpaceButton:
|
|
253
256
|
case ToggleButtonKeyDownEnter:
|
|
254
257
|
if (changes.selectedItem === undefined) {
|
|
@@ -268,11 +271,38 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
|
|
|
268
271
|
break;
|
|
269
272
|
case ToggleButtonClick:
|
|
270
273
|
setIsOpenWrapper(changes.isOpen || false);
|
|
271
|
-
|
|
274
|
+
return {
|
|
275
|
+
...changes,
|
|
276
|
+
highlightedIndex: 0
|
|
277
|
+
};
|
|
278
|
+
case ItemClick:
|
|
279
|
+
setHighlightedIndex(changes.selectedItem);
|
|
280
|
+
onItemChange(changes.selectedItem);
|
|
281
|
+
return {
|
|
282
|
+
...changes,
|
|
283
|
+
highlightedIndex: state.highlightedIndex
|
|
284
|
+
};
|
|
285
|
+
case MenuMouseLeave:
|
|
286
|
+
return {
|
|
287
|
+
...changes,
|
|
288
|
+
highlightedIndex: state.highlightedIndex
|
|
289
|
+
};
|
|
290
|
+
case FunctionSetHighlightedIndex:
|
|
291
|
+
if (!isOpen) {
|
|
292
|
+
return {
|
|
293
|
+
...changes,
|
|
294
|
+
highlightedIndex: 0
|
|
295
|
+
};
|
|
296
|
+
} else {
|
|
297
|
+
return {
|
|
298
|
+
...changes,
|
|
299
|
+
highlightedIndex: props.items.indexOf(highlightedIndex)
|
|
300
|
+
};
|
|
301
|
+
}
|
|
272
302
|
case ToggleButtonKeyDownArrowDown:
|
|
273
303
|
case ToggleButtonKeyDownArrowUp:
|
|
274
|
-
case
|
|
275
|
-
case
|
|
304
|
+
case ToggleButtonKeyDownPageDown:
|
|
305
|
+
case ToggleButtonKeyDownPageUp:
|
|
276
306
|
if (highlightedIndex > -1) {
|
|
277
307
|
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
278
308
|
props.scrollIntoView(itemArray[highlightedIndex]);
|