@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
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
export interface CodeSnippetSkeletonProps extends React.HTMLAttributes<Omit<HTMLDivElement, 'children'>> {
|
|
10
|
+
/**
|
|
11
|
+
* Specify an optional className to be applied to the container node
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The type of the code snippet, including single or multi
|
|
16
|
+
*/
|
|
17
|
+
type?: 'single' | 'multi' | undefined;
|
|
18
|
+
}
|
|
19
|
+
declare function CodeSnippetSkeleton({ className: containerClassName, type, ...rest }: {
|
|
20
|
+
[x: string]: any;
|
|
21
|
+
className: any;
|
|
22
|
+
type?: string | undefined;
|
|
23
|
+
}): import("react/jsx-runtime").JSX.Element | undefined;
|
|
24
|
+
declare namespace CodeSnippetSkeleton {
|
|
25
|
+
var propTypes: {
|
|
26
|
+
/**
|
|
27
|
+
* Specify an optional className to be applied to the container node
|
|
28
|
+
*/
|
|
29
|
+
className: PropTypes.Requireable<string>;
|
|
30
|
+
/**
|
|
31
|
+
* The type of the code snippet, including single or multi
|
|
32
|
+
*/
|
|
33
|
+
type: PropTypes.Requireable<string>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export default CodeSnippetSkeleton;
|
|
37
|
+
export { CodeSnippetSkeleton };
|
|
@@ -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;
|
|
@@ -24,7 +24,7 @@ const rowHeightInPixels = 16;
|
|
|
24
24
|
const defaultMaxCollapsedNumberOfRows = 15;
|
|
25
25
|
const defaultMaxExpandedNumberOfRows = 0;
|
|
26
26
|
const defaultMinCollapsedNumberOfRows = 3;
|
|
27
|
-
const defaultMinExpandedNumberOfRows =
|
|
27
|
+
const defaultMinExpandedNumberOfRows = 16;
|
|
28
28
|
function CodeSnippet(_ref) {
|
|
29
29
|
let {
|
|
30
30
|
align = 'bottom',
|
|
@@ -55,9 +55,9 @@ function CodeSnippet(_ref) {
|
|
|
55
55
|
const {
|
|
56
56
|
current: uid
|
|
57
57
|
} = useRef(uniqueId());
|
|
58
|
-
const codeContentRef = useRef();
|
|
59
|
-
const codeContainerRef = useRef();
|
|
60
|
-
const innerCodeRef = useRef();
|
|
58
|
+
const codeContentRef = useRef(null);
|
|
59
|
+
const codeContainerRef = useRef(null);
|
|
60
|
+
const innerCodeRef = useRef(null);
|
|
61
61
|
const [hasLeftOverflow, setHasLeftOverflow] = useState(false);
|
|
62
62
|
const [hasRightOverflow, setHasRightOverflow] = useState(false);
|
|
63
63
|
const getCodeRef = useCallback(() => {
|
|
@@ -66,15 +66,17 @@ function CodeSnippet(_ref) {
|
|
|
66
66
|
}
|
|
67
67
|
if (type === 'multi') {
|
|
68
68
|
return codeContentRef;
|
|
69
|
+
} else {
|
|
70
|
+
return innerCodeRef;
|
|
69
71
|
}
|
|
70
72
|
}, [type]);
|
|
71
73
|
const prefix = usePrefix();
|
|
72
74
|
const getCodeRefDimensions = useCallback(() => {
|
|
73
75
|
const {
|
|
74
|
-
clientWidth: codeClientWidth,
|
|
75
|
-
scrollLeft: codeScrollLeft,
|
|
76
|
-
scrollWidth: codeScrollWidth
|
|
77
|
-
} = getCodeRef().current;
|
|
76
|
+
clientWidth: codeClientWidth = 0,
|
|
77
|
+
scrollLeft: codeScrollLeft = 0,
|
|
78
|
+
scrollWidth: codeScrollWidth = 0
|
|
79
|
+
} = getCodeRef().current || {};
|
|
78
80
|
return {
|
|
79
81
|
horizontalOverflow: codeScrollWidth > codeClientWidth,
|
|
80
82
|
codeClientWidth,
|
|
@@ -101,7 +103,7 @@ function CodeSnippet(_ref) {
|
|
|
101
103
|
if (codeContentRef?.current && type === 'multi') {
|
|
102
104
|
const {
|
|
103
105
|
height
|
|
104
|
-
} =
|
|
106
|
+
} = codeContentRef.current.getBoundingClientRect();
|
|
105
107
|
if (maxCollapsedNumberOfRows > 0 && (maxExpandedNumberOfRows <= 0 || maxExpandedNumberOfRows > maxCollapsedNumberOfRows) && height > maxCollapsedNumberOfRows * rowHeightInPixels) {
|
|
106
108
|
setShouldShowMoreLessBtn(true);
|
|
107
109
|
} else {
|
|
@@ -115,13 +117,13 @@ function CodeSnippet(_ref) {
|
|
|
115
117
|
handleScroll();
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
|
-
}
|
|
120
|
+
});
|
|
119
121
|
useEffect(() => {
|
|
120
122
|
handleScroll();
|
|
121
123
|
}, [handleScroll]);
|
|
122
124
|
const handleCopyClick = evt => {
|
|
123
125
|
if (copyText || innerCodeRef?.current) {
|
|
124
|
-
copy(copyText ?? innerCodeRef?.current?.innerText);
|
|
126
|
+
copy(copyText ?? innerCodeRef?.current?.innerText ?? '');
|
|
125
127
|
}
|
|
126
128
|
if (onClick) {
|
|
127
129
|
onClick(evt);
|
|
@@ -155,12 +157,11 @@ function CodeSnippet(_ref) {
|
|
|
155
157
|
feedback: feedback,
|
|
156
158
|
feedbackTimeout: feedbackTimeout
|
|
157
159
|
}), /*#__PURE__*/React__default.createElement("code", {
|
|
158
|
-
"aria-live": "assertive",
|
|
159
160
|
id: uid,
|
|
160
161
|
ref: innerCodeRef
|
|
161
162
|
}, children));
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
+
const containerStyle = {};
|
|
164
165
|
if (type === 'multi') {
|
|
165
166
|
const styles = {};
|
|
166
167
|
if (expandedCode) {
|
|
@@ -186,16 +187,16 @@ function CodeSnippet(_ref) {
|
|
|
186
187
|
className: codeSnippetClasses
|
|
187
188
|
}), /*#__PURE__*/React__default.createElement("div", _extends({
|
|
188
189
|
ref: codeContainerRef,
|
|
189
|
-
role: type === 'single' || type === 'multi' ? 'textbox' :
|
|
190
|
-
tabIndex: (type === 'single' || type === 'multi') && !disabled ? 0 :
|
|
190
|
+
role: type === 'single' || type === 'multi' ? 'textbox' : undefined,
|
|
191
|
+
tabIndex: (type === 'single' || type === 'multi') && !disabled ? 0 : undefined,
|
|
191
192
|
className: `${prefix}--snippet-container`,
|
|
192
193
|
"aria-label": deprecatedAriaLabel || ariaLabel || 'code-snippet',
|
|
193
|
-
"aria-readonly": type === 'single' || type === 'multi' ? true :
|
|
194
|
-
"aria-multiline": type === 'multi' ? true :
|
|
195
|
-
onScroll: type === 'single' && handleScroll ||
|
|
194
|
+
"aria-readonly": type === 'single' || type === 'multi' ? true : undefined,
|
|
195
|
+
"aria-multiline": type === 'multi' ? true : undefined,
|
|
196
|
+
onScroll: type === 'single' && handleScroll || undefined
|
|
196
197
|
}, containerStyle), /*#__PURE__*/React__default.createElement("pre", {
|
|
197
198
|
ref: codeContentRef,
|
|
198
|
-
onScroll: type === 'multi' && handleScroll ||
|
|
199
|
+
onScroll: type === 'multi' && handleScroll || undefined
|
|
199
200
|
}, /*#__PURE__*/React__default.createElement("code", {
|
|
200
201
|
ref: innerCodeRef
|
|
201
202
|
}, children))), hasLeftOverflow && /*#__PURE__*/React__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
|
}
|
|
@@ -31,9 +31,11 @@ const {
|
|
|
31
31
|
keyDownArrowUp,
|
|
32
32
|
keyDownEscape,
|
|
33
33
|
clickButton,
|
|
34
|
+
clickItem,
|
|
34
35
|
blurButton,
|
|
35
36
|
changeInput,
|
|
36
|
-
blurInput
|
|
37
|
+
blurInput,
|
|
38
|
+
unknown
|
|
37
39
|
} = Downshift.stateChangeTypes;
|
|
38
40
|
const defaultItemToString = item => {
|
|
39
41
|
if (typeof item === 'string') {
|
|
@@ -195,15 +197,16 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
195
197
|
switch (type) {
|
|
196
198
|
case keyDownArrowDown:
|
|
197
199
|
case keyDownArrowUp:
|
|
198
|
-
|
|
200
|
+
if (changes.isOpen) {
|
|
201
|
+
updateHighlightedIndex(getHighlightedIndex(changes));
|
|
202
|
+
} else {
|
|
203
|
+
setHighlightedIndex(changes.highlightedIndex);
|
|
204
|
+
}
|
|
199
205
|
break;
|
|
200
206
|
case blurButton:
|
|
201
207
|
case keyDownEscape:
|
|
202
208
|
setHighlightedIndex(changes.highlightedIndex);
|
|
203
209
|
break;
|
|
204
|
-
case clickButton:
|
|
205
|
-
setHighlightedIndex(changes.highlightedIndex);
|
|
206
|
-
break;
|
|
207
210
|
case changeInput:
|
|
208
211
|
updateHighlightedIndex(getHighlightedIndex(changes));
|
|
209
212
|
break;
|
|
@@ -218,6 +221,11 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
218
221
|
}
|
|
219
222
|
}
|
|
220
223
|
break;
|
|
224
|
+
case clickButton:
|
|
225
|
+
case clickItem:
|
|
226
|
+
case unknown:
|
|
227
|
+
setHighlightedIndex(getHighlightedIndex(changes));
|
|
228
|
+
break;
|
|
221
229
|
}
|
|
222
230
|
};
|
|
223
231
|
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 };
|
|
@@ -70,10 +70,12 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
function handleOpen() {
|
|
73
|
-
menuRef.current
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
if (menuRef.current) {
|
|
74
|
+
menuRef.current.style.inlineSize = `${width}px`;
|
|
75
|
+
menuRef.current.style.minInlineSize = `${width}px`;
|
|
76
|
+
if (menuAlignment !== 'bottom' && menuAlignment !== 'top') {
|
|
77
|
+
menuRef.current.style.inlineSize = `fit-content`;
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
const containerClasses = cx(`${prefix}--combo-button__container`, `${prefix}--combo-button__container--${size}`, {
|
|
@@ -85,7 +87,7 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
|
|
|
85
87
|
return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
|
|
86
88
|
className: containerClasses,
|
|
87
89
|
ref: ref,
|
|
88
|
-
"aria-owns": open ? id :
|
|
90
|
+
"aria-owns": open ? id : undefined
|
|
89
91
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
90
92
|
className: primaryActionClasses
|
|
91
93
|
}, /*#__PURE__*/React__default.createElement(Button, {
|
|
@@ -103,7 +105,7 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
|
|
|
103
105
|
"aria-expanded": open,
|
|
104
106
|
onClick: handleTriggerClick,
|
|
105
107
|
onMouseDown: handleTriggerMousedown,
|
|
106
|
-
"aria-controls": open ? id :
|
|
108
|
+
"aria-controls": open ? id : undefined
|
|
107
109
|
}, _ChevronDown || (_ChevronDown = /*#__PURE__*/React__default.createElement(ChevronDown, null))), /*#__PURE__*/React__default.createElement(Menu, {
|
|
108
110
|
containerRef: containerRef,
|
|
109
111
|
menuAlignment: menuAlignment,
|
|
@@ -134,7 +136,7 @@ ComboButton.propTypes = {
|
|
|
134
136
|
*/
|
|
135
137
|
disabled: PropTypes.bool,
|
|
136
138
|
/**
|
|
137
|
-
* Provide the label to be
|
|
139
|
+
* Provide the label to be rendered on the primary action button.
|
|
138
140
|
*/
|
|
139
141
|
label: PropTypes.string.isRequired,
|
|
140
142
|
/**
|
|
@@ -68,7 +68,7 @@ export interface ComposedModalProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
68
68
|
*/
|
|
69
69
|
selectorPrimaryFocus?: string;
|
|
70
70
|
/** Specify the CSS selectors that match the floating menus. */
|
|
71
|
-
selectorsFloatingMenus?:
|
|
71
|
+
selectorsFloatingMenus?: string[];
|
|
72
72
|
size?: 'xs' | 'sm' | 'md' | 'lg';
|
|
73
73
|
/**
|
|
74
74
|
* **Experimental**: Provide a `Slug` component to be rendered inside the `ComposedModal` component
|
|
@@ -17,7 +17,7 @@ import mergeRefs from '../../tools/mergeRefs.js';
|
|
|
17
17
|
import cx from 'classnames';
|
|
18
18
|
import toggleClass from '../../tools/toggleClass.js';
|
|
19
19
|
import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy.js';
|
|
20
|
-
import wrapFocus, { wrapFocusWithoutSentinels } from '../../internal/wrapFocus.js';
|
|
20
|
+
import wrapFocus, { wrapFocusWithoutSentinels, elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
|
|
21
21
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
22
22
|
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
23
23
|
import { match } from '../../internal/keyboard/match.js';
|
|
@@ -148,9 +148,9 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
148
148
|
onKeyDown?.(event);
|
|
149
149
|
}
|
|
150
150
|
function handleMousedown(evt) {
|
|
151
|
+
const target = evt.target;
|
|
151
152
|
evt.stopPropagation();
|
|
152
|
-
|
|
153
|
-
if (!isInside && !preventCloseOnClickOutside) {
|
|
153
|
+
if (!preventCloseOnClickOutside && !elementOrParentIsFloatingMenu(target, selectorsFloatingMenus) && innerModal.current && !innerModal.current.contains(target)) {
|
|
154
154
|
closeModal(evt);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -242,11 +242,11 @@ const ComposedModal = /*#__PURE__*/React__default.forwardRef(function ComposedMo
|
|
|
242
242
|
}
|
|
243
243
|
}, [open, selectorPrimaryFocus, isOpen]);
|
|
244
244
|
|
|
245
|
-
// Slug is always size `
|
|
245
|
+
// Slug is always size `sm`
|
|
246
246
|
let normalizedSlug;
|
|
247
247
|
if (slug && slug['type']?.displayName === 'Slug') {
|
|
248
248
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
249
|
-
size: '
|
|
249
|
+
size: 'sm'
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
|
|
@@ -336,7 +336,7 @@ ComposedModal.propTypes = {
|
|
|
336
336
|
/**
|
|
337
337
|
* Specify the CSS selectors that match the floating menus
|
|
338
338
|
*/
|
|
339
|
-
selectorsFloatingMenus: PropTypes.arrayOf(PropTypes.string),
|
|
339
|
+
selectorsFloatingMenus: PropTypes.arrayOf(PropTypes.string.isRequired),
|
|
340
340
|
/**
|
|
341
341
|
* Specify the size variant.
|
|
342
342
|
*/
|
|
@@ -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
|
|
@@ -26,7 +26,8 @@ const {
|
|
|
26
26
|
ToggleButtonKeyDownArrowUp,
|
|
27
27
|
ToggleButtonKeyDownHome,
|
|
28
28
|
ToggleButtonKeyDownEnd,
|
|
29
|
-
ItemMouseMove
|
|
29
|
+
ItemMouseMove,
|
|
30
|
+
MenuMouseLeave
|
|
30
31
|
} = useSelect.stateChangeTypes;
|
|
31
32
|
const defaultItemToString = item => {
|
|
32
33
|
if (typeof item === 'string') {
|
|
@@ -111,6 +112,7 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
111
112
|
}
|
|
112
113
|
return changes;
|
|
113
114
|
case ItemMouseMove:
|
|
115
|
+
case MenuMouseLeave:
|
|
114
116
|
return {
|
|
115
117
|
...changes,
|
|
116
118
|
highlightedIndex: state.highlightedIndex
|
|
@@ -108,7 +108,7 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
108
108
|
function handleMousedown(evt) {
|
|
109
109
|
const target = evt.target;
|
|
110
110
|
evt.stopPropagation();
|
|
111
|
-
if (
|
|
111
|
+
if (!preventCloseOnClickOutside && !elementOrParentIsFloatingMenu(target, selectorsFloatingMenus) && innerModal.current && !innerModal.current.contains(target)) {
|
|
112
112
|
onRequestClose(evt);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -226,11 +226,11 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
|
|
|
226
226
|
};
|
|
227
227
|
}, []);
|
|
228
228
|
|
|
229
|
-
// Slug is always size `
|
|
229
|
+
// Slug is always size `sm`
|
|
230
230
|
let normalizedSlug;
|
|
231
231
|
if (slug && slug['type']?.displayName === 'Slug') {
|
|
232
232
|
normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
|
|
233
|
-
size: '
|
|
233
|
+
size: 'sm'
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
const modalButton = /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -137,6 +137,9 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
137
137
|
if (onMenuChange) {
|
|
138
138
|
onMenuChange(nextIsOpen);
|
|
139
139
|
}
|
|
140
|
+
if (!isOpen) {
|
|
141
|
+
setHighlightedIndex(0);
|
|
142
|
+
}
|
|
140
143
|
}
|
|
141
144
|
function handleOnOuterClick() {
|
|
142
145
|
handleOnMenuChange(false);
|
|
@@ -160,6 +163,34 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
|
|
|
160
163
|
break;
|
|
161
164
|
case stateChangeTypes.keyDownEscape:
|
|
162
165
|
handleOnMenuChange(false);
|
|
166
|
+
setHighlightedIndex(0);
|
|
167
|
+
break;
|
|
168
|
+
case stateChangeTypes.changeInput:
|
|
169
|
+
setHighlightedIndex(0);
|
|
170
|
+
break;
|
|
171
|
+
case stateChangeTypes.keyDownEnter:
|
|
172
|
+
if (!isOpen) {
|
|
173
|
+
setHighlightedIndex(0);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case stateChangeTypes.clickItem:
|
|
177
|
+
if (isOpen) {
|
|
178
|
+
const sortedItems = sortItems(filterItems(items, {
|
|
179
|
+
itemToString,
|
|
180
|
+
inputValue
|
|
181
|
+
}), {
|
|
182
|
+
selectedItems: {
|
|
183
|
+
top: changes.selectedItems,
|
|
184
|
+
fixed: [],
|
|
185
|
+
'top-after-reopen': topItems
|
|
186
|
+
}[selectionFeedback],
|
|
187
|
+
itemToString,
|
|
188
|
+
compareItems,
|
|
189
|
+
locale
|
|
190
|
+
});
|
|
191
|
+
const sortedSelectedIndex = sortedItems.indexOf(changes.selectedItem);
|
|
192
|
+
setHighlightedIndex(sortedSelectedIndex);
|
|
193
|
+
}
|
|
163
194
|
break;
|
|
164
195
|
}
|
|
165
196
|
}
|