@carbon/react 1.70.0 → 1.71.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 +895 -895
- package/es/components/AILabel/index.js +15 -15
- package/es/components/CodeSnippet/CodeSnippet.d.ts +5 -2
- package/es/components/CodeSnippet/CodeSnippet.js +40 -1
- package/es/components/ComboBox/ComboBox.js +19 -22
- package/es/components/ComboButton/index.js +40 -1
- package/es/components/ContentSwitcher/ContentSwitcher.d.ts +2 -2
- package/es/components/ContentSwitcher/ContentSwitcher.js +1 -1
- package/es/components/Copy/Copy.d.ts +5 -2
- package/es/components/Copy/Copy.js +40 -1
- package/es/components/CopyButton/CopyButton.d.ts +5 -2
- package/es/components/CopyButton/CopyButton.js +40 -1
- package/es/components/DataTable/TableSelectRow.js +14 -6
- package/es/components/DataTable/TableToolbarSearch.js +1 -1
- package/es/components/DataTable/stories/examples/TableToolbarFilter.d.ts +1 -1
- package/es/components/DatePicker/plugins/fixEventsPlugin.js +2 -2
- package/es/components/DatePickerInput/DatePickerInput.d.ts +6 -1
- package/es/components/DatePickerInput/DatePickerInput.js +16 -10
- package/es/components/Dropdown/Dropdown.d.ts +5 -0
- package/es/components/Dropdown/Dropdown.js +132 -92
- package/es/components/FeatureFlags/index.js +1 -2
- package/es/components/IconButton/index.d.ts +4 -1
- package/es/components/IconButton/index.js +40 -1
- package/es/components/InlineCheckbox/InlineCheckbox.d.ts +50 -0
- package/es/components/InlineCheckbox/InlineCheckbox.js +3 -6
- package/es/components/InlineCheckbox/index.d.ts +9 -0
- package/es/components/LayoutDirection/LayoutDirection.d.ts +44 -0
- package/es/components/LayoutDirection/LayoutDirectionContext.d.ts +10 -0
- package/es/components/LayoutDirection/useLayoutDirection.d.ts +12 -0
- package/es/components/Menu/MenuItem.js +0 -3
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
- package/es/components/MultiSelect/FilterableMultiSelect.js +1 -2
- package/es/components/MultiSelect/MultiSelect.js +1 -1
- package/es/components/Notification/Notification.d.ts +9 -2
- package/es/components/Notification/Notification.js +16 -2
- package/es/components/NumberInput/NumberInput.d.ts +5 -0
- package/es/components/NumberInput/NumberInput.js +17 -9
- package/es/components/OverflowMenu/next/index.js +40 -1
- package/es/components/Pagination/Pagination.js +1 -1
- package/es/components/PaginationNav/PaginationNav.d.ts +1 -1
- package/es/components/PaginationNav/PaginationNav.js +10 -5
- package/es/components/Tabs/Tabs.js +46 -29
- package/es/components/TextArea/TextArea.d.ts +5 -0
- package/es/components/TextArea/TextArea.js +15 -7
- package/es/components/TextInput/TextInput.d.ts +5 -0
- package/es/components/TextInput/TextInput.js +15 -7
- package/es/components/UIShell/SideNavMenuItem.d.ts +5 -1
- package/es/components/UIShell/SideNavMenuItem.js +7 -2
- package/lib/components/AILabel/index.js +15 -15
- package/lib/components/CodeSnippet/CodeSnippet.d.ts +5 -2
- package/lib/components/CodeSnippet/CodeSnippet.js +40 -1
- package/lib/components/ComboBox/ComboBox.js +19 -22
- package/lib/components/ComboButton/index.js +40 -1
- package/lib/components/ContentSwitcher/ContentSwitcher.d.ts +2 -2
- package/lib/components/ContentSwitcher/ContentSwitcher.js +1 -1
- package/lib/components/Copy/Copy.d.ts +5 -2
- package/lib/components/Copy/Copy.js +40 -1
- package/lib/components/CopyButton/CopyButton.d.ts +5 -2
- package/lib/components/CopyButton/CopyButton.js +40 -1
- package/lib/components/DataTable/TableSelectRow.js +14 -6
- package/lib/components/DataTable/TableToolbarSearch.js +1 -1
- package/lib/components/DataTable/stories/examples/TableToolbarFilter.d.ts +1 -1
- package/lib/components/DatePicker/plugins/fixEventsPlugin.js +2 -2
- package/lib/components/DatePickerInput/DatePickerInput.d.ts +6 -1
- package/lib/components/DatePickerInput/DatePickerInput.js +16 -10
- package/lib/components/Dropdown/Dropdown.d.ts +5 -0
- package/lib/components/Dropdown/Dropdown.js +131 -91
- package/lib/components/FeatureFlags/index.js +1 -2
- package/lib/components/IconButton/index.d.ts +4 -1
- package/lib/components/IconButton/index.js +40 -1
- package/lib/components/InlineCheckbox/InlineCheckbox.d.ts +50 -0
- package/lib/components/InlineCheckbox/InlineCheckbox.js +3 -6
- package/lib/components/InlineCheckbox/index.d.ts +9 -0
- package/lib/components/LayoutDirection/LayoutDirection.d.ts +44 -0
- package/lib/components/LayoutDirection/LayoutDirectionContext.d.ts +10 -0
- package/lib/components/LayoutDirection/useLayoutDirection.d.ts +12 -0
- package/lib/components/Menu/MenuItem.js +0 -3
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
- package/lib/components/MultiSelect/FilterableMultiSelect.js +1 -2
- package/lib/components/MultiSelect/MultiSelect.js +1 -1
- package/lib/components/Notification/Notification.d.ts +9 -2
- package/lib/components/Notification/Notification.js +16 -2
- package/lib/components/NumberInput/NumberInput.d.ts +5 -0
- package/lib/components/NumberInput/NumberInput.js +17 -9
- package/lib/components/OverflowMenu/next/index.js +40 -1
- package/lib/components/Pagination/Pagination.js +1 -1
- package/lib/components/PaginationNav/PaginationNav.d.ts +1 -1
- package/lib/components/PaginationNav/PaginationNav.js +10 -5
- package/lib/components/Tabs/Tabs.js +46 -29
- package/lib/components/TextArea/TextArea.d.ts +5 -0
- package/lib/components/TextArea/TextArea.js +15 -7
- package/lib/components/TextInput/TextInput.d.ts +5 -0
- package/lib/components/TextInput/TextInput.js +15 -7
- package/lib/components/UIShell/SideNavMenuItem.d.ts +5 -1
- package/lib/components/UIShell/SideNavMenuItem.js +7 -2
- package/package.json +4 -4
|
@@ -18,6 +18,7 @@ require('../FluidForm/FluidForm.js');
|
|
|
18
18
|
var FormContext = require('../FluidForm/FormContext.js');
|
|
19
19
|
var useId = require('../../internal/useId.js');
|
|
20
20
|
require('../Text/index.js');
|
|
21
|
+
var deprecate = require('../../prop-types/deprecate.js');
|
|
21
22
|
var Text = require('../Text/Text.js');
|
|
22
23
|
|
|
23
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -29,6 +30,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
29
30
|
const DatePickerInput = /*#__PURE__*/React__default["default"].forwardRef(function DatePickerInput(props, ref) {
|
|
30
31
|
const {
|
|
31
32
|
datePickerType,
|
|
33
|
+
decorator,
|
|
32
34
|
disabled = false,
|
|
33
35
|
helperText,
|
|
34
36
|
hideLabel,
|
|
@@ -71,7 +73,8 @@ const DatePickerInput = /*#__PURE__*/React__default["default"].forwardRef(functi
|
|
|
71
73
|
const wrapperClasses = cx__default["default"](`${prefix}--date-picker-input__wrapper`, {
|
|
72
74
|
[`${prefix}--date-picker-input__wrapper--invalid`]: invalid,
|
|
73
75
|
[`${prefix}--date-picker-input__wrapper--warn`]: warn,
|
|
74
|
-
[`${prefix}--date-picker-input__wrapper--slug`]: slug
|
|
76
|
+
[`${prefix}--date-picker-input__wrapper--slug`]: slug,
|
|
77
|
+
[`${prefix}--date-picker-input__wrapper--decorator`]: decorator
|
|
75
78
|
});
|
|
76
79
|
const labelClasses = cx__default["default"](`${prefix}--label`, {
|
|
77
80
|
[`${prefix}--visually-hidden`]: hideLabel,
|
|
@@ -105,10 +108,10 @@ const DatePickerInput = /*#__PURE__*/React__default["default"].forwardRef(functi
|
|
|
105
108
|
}
|
|
106
109
|
const input = /*#__PURE__*/React__default["default"].createElement("input", inputProps);
|
|
107
110
|
|
|
108
|
-
//
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
111
|
-
|
|
111
|
+
// AILabel always size `mini`
|
|
112
|
+
let normalizedDecorator = /*#__PURE__*/React__default["default"].isValidElement(slug ?? decorator) ? slug ?? decorator : null;
|
|
113
|
+
if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
|
|
114
|
+
normalizedDecorator = /*#__PURE__*/React__default["default"].cloneElement(normalizedDecorator, {
|
|
112
115
|
size: 'mini'
|
|
113
116
|
});
|
|
114
117
|
}
|
|
@@ -120,7 +123,9 @@ const DatePickerInput = /*#__PURE__*/React__default["default"].forwardRef(functi
|
|
|
120
123
|
className: labelClasses
|
|
121
124
|
}, labelText), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
122
125
|
className: wrapperClasses
|
|
123
|
-
}, /*#__PURE__*/React__default["default"].createElement("span", null, input,
|
|
126
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", null, input, slug ? normalizedDecorator : decorator ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
127
|
+
className: `${prefix}--date-picker-input-inner-wrapper--decorator`
|
|
128
|
+
}, normalizedDecorator) : '', isFluid && /*#__PURE__*/React__default["default"].createElement(DatePickerIcon, {
|
|
124
129
|
datePickerType: datePickerType
|
|
125
130
|
}), /*#__PURE__*/React__default["default"].createElement(DatePickerIcon, {
|
|
126
131
|
datePickerType: datePickerType,
|
|
@@ -151,6 +156,10 @@ DatePickerInput.propTypes = {
|
|
|
151
156
|
* * `range` - With calendar dropdown and a date range.
|
|
152
157
|
*/
|
|
153
158
|
datePickerType: PropTypes__default["default"].oneOf(['simple', 'single', 'range']),
|
|
159
|
+
/**
|
|
160
|
+
* **Experimental**: Provide a decorator component to be rendered inside the `RadioButton` component
|
|
161
|
+
*/
|
|
162
|
+
decorator: PropTypes__default["default"].node,
|
|
154
163
|
/**
|
|
155
164
|
* Specify whether or not the input should be disabled
|
|
156
165
|
*/
|
|
@@ -214,10 +223,7 @@ DatePickerInput.propTypes = {
|
|
|
214
223
|
* Specify the size of the Date Picker Input. Currently supports either `sm`, `md`, or `lg` as an option.
|
|
215
224
|
*/
|
|
216
225
|
size: PropTypes__default["default"].oneOf(['sm', 'md', 'lg']),
|
|
217
|
-
|
|
218
|
-
* **Experimental**: Provide a `Slug` component to be rendered inside the `DatePickerInput` component
|
|
219
|
-
*/
|
|
220
|
-
slug: PropTypes__default["default"].node,
|
|
226
|
+
slug: deprecate["default"](PropTypes__default["default"].node, 'The `slug` prop has been deprecated and will be removed in the next major version. Use the decorator prop instead.'),
|
|
221
227
|
/**
|
|
222
228
|
* Specify the type of the `<input>`
|
|
223
229
|
*/
|
|
@@ -27,6 +27,10 @@ export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>,
|
|
|
27
27
|
* **Experimental**: Will attempt to automatically align the floating element to avoid collisions with the viewport and being clipped by ancestor elements.
|
|
28
28
|
*/
|
|
29
29
|
autoAlign?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `Dropdown` component
|
|
32
|
+
*/
|
|
33
|
+
decorator?: ReactNode;
|
|
30
34
|
/**
|
|
31
35
|
* Specify the direction of the dropdown. Can be either top or bottom.
|
|
32
36
|
*/
|
|
@@ -120,6 +124,7 @@ export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>,
|
|
|
120
124
|
*/
|
|
121
125
|
size?: ListBoxSize;
|
|
122
126
|
/**
|
|
127
|
+
* @deprecated please use `decorator` instead.
|
|
123
128
|
* **Experimental**: Provide a `Slug` component to be rendered inside the `Dropdown` component
|
|
124
129
|
*/
|
|
125
130
|
slug?: ReactNode;
|
|
@@ -49,13 +49,50 @@ const defaultItemToString = item => {
|
|
|
49
49
|
}
|
|
50
50
|
return '';
|
|
51
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Custom state reducer for `useSelect` in Downshift, providing control over
|
|
54
|
+
* state changes.
|
|
55
|
+
*
|
|
56
|
+
* This function is called each time `useSelect` updates its internal state or
|
|
57
|
+
* triggers `onStateChange`. It allows for fine-grained control of state
|
|
58
|
+
* updates by modifying or overriding the default changes from Downshift's
|
|
59
|
+
* reducer.
|
|
60
|
+
* https://github.com/downshift-js/downshift/tree/master/src/hooks/useSelect#statereducer
|
|
61
|
+
*
|
|
62
|
+
* @param {Object} state - The current full state of the Downshift component.
|
|
63
|
+
* @param {Object} actionAndChanges - Contains the action type and proposed
|
|
64
|
+
* changes from the default Downshift reducer.
|
|
65
|
+
* @param {Object} actionAndChanges.changes - Suggested state changes.
|
|
66
|
+
* @param {string} actionAndChanges.type - The action type for the state
|
|
67
|
+
* change (e.g., item selection).
|
|
68
|
+
* @returns {Object} - The modified state based on custom logic or default
|
|
69
|
+
* changes if no custom logic applies.
|
|
70
|
+
*/
|
|
71
|
+
function stateReducer(state, actionAndChanges) {
|
|
72
|
+
const {
|
|
73
|
+
changes,
|
|
74
|
+
type
|
|
75
|
+
} = actionAndChanges;
|
|
76
|
+
switch (type) {
|
|
77
|
+
case ItemMouseMove:
|
|
78
|
+
case MenuMouseLeave:
|
|
79
|
+
if (changes.highlightedIndex === state.highlightedIndex) {
|
|
80
|
+
// Prevent state update if highlightedIndex hasn't changed
|
|
81
|
+
return state;
|
|
82
|
+
}
|
|
83
|
+
return changes;
|
|
84
|
+
default:
|
|
85
|
+
return changes;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
52
88
|
const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) => {
|
|
53
89
|
let {
|
|
54
90
|
autoAlign = false,
|
|
55
91
|
className: containerClassName,
|
|
92
|
+
decorator,
|
|
56
93
|
disabled = false,
|
|
57
94
|
direction = 'bottom',
|
|
58
|
-
items,
|
|
95
|
+
items: itemsProp,
|
|
59
96
|
label,
|
|
60
97
|
['aria-label']: ariaLabel,
|
|
61
98
|
ariaLabel: deprecatedAriaLabel,
|
|
@@ -128,49 +165,47 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
|
|
|
128
165
|
const {
|
|
129
166
|
isFluid
|
|
130
167
|
} = React.useContext(FormContext.FormContext);
|
|
131
|
-
const
|
|
168
|
+
const onSelectedItemChange = React.useCallback(_ref3 => {
|
|
169
|
+
let {
|
|
170
|
+
selectedItem
|
|
171
|
+
} = _ref3;
|
|
172
|
+
if (onChange) {
|
|
173
|
+
onChange({
|
|
174
|
+
selectedItem: selectedItem ?? null
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}, [onChange]);
|
|
178
|
+
const isItemDisabled = React.useCallback((item, _index) => {
|
|
179
|
+
const isObject = item !== null && typeof item === 'object';
|
|
180
|
+
return isObject && 'disabled' in item && item.disabled === true;
|
|
181
|
+
}, []);
|
|
182
|
+
const onHighlightedIndexChange = React.useCallback(changes => {
|
|
183
|
+
const {
|
|
184
|
+
highlightedIndex
|
|
185
|
+
} = changes;
|
|
186
|
+
if (highlightedIndex !== undefined && highlightedIndex > -1 && typeof window !== undefined) {
|
|
187
|
+
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
188
|
+
const highlightedItem = itemArray[highlightedIndex];
|
|
189
|
+
if (highlightedItem) {
|
|
190
|
+
highlightedItem.scrollIntoView({
|
|
191
|
+
behavior: 'smooth',
|
|
192
|
+
block: 'nearest'
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}, [prefix]);
|
|
197
|
+
const items = React.useMemo(() => itemsProp, [itemsProp]);
|
|
198
|
+
const selectProps = React.useMemo(() => ({
|
|
132
199
|
items,
|
|
133
200
|
itemToString,
|
|
134
201
|
initialSelectedItem,
|
|
135
202
|
onSelectedItemChange,
|
|
136
203
|
stateReducer,
|
|
137
|
-
isItemDisabled
|
|
138
|
-
|
|
139
|
-
return isObject && 'disabled' in item && item.disabled === true;
|
|
140
|
-
},
|
|
141
|
-
onHighlightedIndexChange: _ref3 => {
|
|
142
|
-
let {
|
|
143
|
-
highlightedIndex
|
|
144
|
-
} = _ref3;
|
|
145
|
-
if (highlightedIndex > -1 && typeof window !== undefined) {
|
|
146
|
-
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
147
|
-
const highlightedItem = itemArray[highlightedIndex];
|
|
148
|
-
if (highlightedItem) {
|
|
149
|
-
highlightedItem.scrollIntoView({
|
|
150
|
-
behavior: 'smooth',
|
|
151
|
-
block: 'nearest'
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
},
|
|
204
|
+
isItemDisabled,
|
|
205
|
+
onHighlightedIndexChange,
|
|
156
206
|
...downshiftProps
|
|
157
|
-
};
|
|
207
|
+
}), [items, itemToString, initialSelectedItem, onSelectedItemChange, stateReducer, isItemDisabled, onHighlightedIndexChange, downshiftProps]);
|
|
158
208
|
const dropdownInstanceId = useId.useId();
|
|
159
|
-
function stateReducer(state, actionAndChanges) {
|
|
160
|
-
const {
|
|
161
|
-
changes,
|
|
162
|
-
type
|
|
163
|
-
} = actionAndChanges;
|
|
164
|
-
switch (type) {
|
|
165
|
-
case ItemMouseMove:
|
|
166
|
-
case MenuMouseLeave:
|
|
167
|
-
return {
|
|
168
|
-
...changes,
|
|
169
|
-
highlightedIndex: state.highlightedIndex
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
return changes;
|
|
173
|
-
}
|
|
174
209
|
|
|
175
210
|
// only set selectedItem if the prop is defined. Setting if it is undefined
|
|
176
211
|
// will overwrite default selected items from useSelect
|
|
@@ -215,80 +250,79 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
|
|
|
215
250
|
[`${prefix}--list-box__wrapper--inline--invalid`]: inline && invalid,
|
|
216
251
|
[`${prefix}--list-box__wrapper--fluid--invalid`]: isFluid && invalid,
|
|
217
252
|
[`${prefix}--list-box__wrapper--fluid--focus`]: isFluid && isFocused && !isOpen,
|
|
218
|
-
[`${prefix}--list-box__wrapper--slug`]: slug
|
|
253
|
+
[`${prefix}--list-box__wrapper--slug`]: slug,
|
|
254
|
+
[`${prefix}--list-box__wrapper--decorator`]: decorator
|
|
219
255
|
});
|
|
220
256
|
const helperId = !helperText ? undefined : `dropdown-helper-text-${dropdownInstanceId}`;
|
|
221
257
|
|
|
222
258
|
// needs to be Capitalized for react to render it correctly
|
|
223
259
|
const ItemToElement = itemToElement;
|
|
224
|
-
const toggleButtonProps = getToggleButtonProps({
|
|
260
|
+
const toggleButtonProps = React.useMemo(() => getToggleButtonProps({
|
|
225
261
|
'aria-label': ariaLabel || deprecatedAriaLabel
|
|
226
|
-
});
|
|
262
|
+
}), [getToggleButtonProps, ariaLabel, deprecatedAriaLabel, isOpen]);
|
|
227
263
|
const helper = helperText && !isFluid ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
228
264
|
id: helperId,
|
|
229
265
|
className: helperClasses
|
|
230
266
|
}, helperText) : null;
|
|
231
|
-
function onSelectedItemChange(_ref4) {
|
|
232
|
-
let {
|
|
233
|
-
selectedItem
|
|
234
|
-
} = _ref4;
|
|
235
|
-
if (onChange) {
|
|
236
|
-
onChange({
|
|
237
|
-
selectedItem: selectedItem ?? null
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
267
|
const handleFocus = evt => {
|
|
242
268
|
setIsFocused(evt.type === 'focus' ? true : false);
|
|
243
269
|
};
|
|
244
270
|
const mergedRef = mergeRefs["default"](toggleButtonProps.ref, ref);
|
|
245
271
|
const [currTimer, setCurrTimer] = React.useState();
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
onClick: evt => {
|
|
251
|
-
// NOTE: does not prevent click
|
|
252
|
-
evt.preventDefault();
|
|
253
|
-
// focus on the element as per readonly input behavior
|
|
254
|
-
mergedRef?.current?.focus();
|
|
255
|
-
},
|
|
256
|
-
onKeyDown: evt => {
|
|
257
|
-
const selectAccessKeys = ['ArrowDown', 'ArrowUp', ' ', 'Enter'];
|
|
258
|
-
// This prevents the select from opening for the above keys
|
|
259
|
-
if (selectAccessKeys.includes(evt.key)) {
|
|
260
|
-
evt.preventDefault();
|
|
261
|
-
}
|
|
272
|
+
const [isTyping, setIsTyping] = React.useState(false);
|
|
273
|
+
const onKeyDownHandler = React.useCallback(evt => {
|
|
274
|
+
if (evt.code !== 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
|
|
275
|
+
setIsTyping(true);
|
|
262
276
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
setIsTyping(true);
|
|
277
|
+
if (isTyping && evt.code === 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
|
|
278
|
+
if (currTimer) {
|
|
279
|
+
clearTimeout(currTimer);
|
|
267
280
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
281
|
+
setCurrTimer(setTimeout(() => {
|
|
282
|
+
setIsTyping(false);
|
|
283
|
+
}, 3000));
|
|
284
|
+
}
|
|
285
|
+
if (toggleButtonProps.onKeyDown) {
|
|
286
|
+
toggleButtonProps.onKeyDown(evt);
|
|
287
|
+
}
|
|
288
|
+
}, [isTyping, currTimer, toggleButtonProps]);
|
|
289
|
+
const readOnlyEventHandlers = React.useMemo(() => {
|
|
290
|
+
if (readOnly) {
|
|
291
|
+
return {
|
|
292
|
+
onClick: evt => {
|
|
293
|
+
// NOTE: does not prevent click
|
|
294
|
+
evt.preventDefault();
|
|
295
|
+
// focus on the element as per readonly input behavior
|
|
296
|
+
mergedRef?.current?.focus();
|
|
297
|
+
},
|
|
298
|
+
onKeyDown: evt => {
|
|
299
|
+
const selectAccessKeys = ['ArrowDown', 'ArrowUp', ' ', 'Enter'];
|
|
300
|
+
// This prevents the select from opening for the above keys
|
|
301
|
+
if (selectAccessKeys.includes(evt.key)) {
|
|
302
|
+
evt.preventDefault();
|
|
303
|
+
}
|
|
271
304
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
toggleButtonProps.onKeyDown(evt);
|
|
278
|
-
}
|
|
305
|
+
};
|
|
306
|
+
} else {
|
|
307
|
+
return {
|
|
308
|
+
onKeyDown: onKeyDownHandler
|
|
309
|
+
};
|
|
279
310
|
}
|
|
280
|
-
};
|
|
311
|
+
}, [readOnly, onKeyDownHandler]);
|
|
281
312
|
const menuProps = React.useMemo(() => getMenuProps({
|
|
282
313
|
ref: enableFloatingStyles || autoAlign ? refs.setFloating : null
|
|
283
|
-
}), [autoAlign, getMenuProps, refs.setFloating]);
|
|
314
|
+
}), [autoAlign, getMenuProps, refs.setFloating, enableFloatingStyles]);
|
|
284
315
|
|
|
285
|
-
//
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
316
|
+
// AILabel is always size `mini`
|
|
317
|
+
const normalizedDecorator = React.useMemo(() => {
|
|
318
|
+
let element = slug ?? decorator;
|
|
319
|
+
if (element && element['type']?.displayName === 'AILabel') {
|
|
320
|
+
return /*#__PURE__*/React__default["default"].cloneElement(element, {
|
|
321
|
+
size: 'mini'
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return /*#__PURE__*/React__default["default"].isValidElement(element) ? element : null;
|
|
325
|
+
}, [slug, decorator]);
|
|
292
326
|
return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
|
|
293
327
|
className: wrapperClasses
|
|
294
328
|
}, other), titleText && /*#__PURE__*/React__default["default"].createElement("label", _rollupPluginBabelHelpers["extends"]({
|
|
@@ -327,7 +361,9 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
|
|
|
327
361
|
}, selectedItem ? renderSelectedItem ? renderSelectedItem(selectedItem) : itemToString(selectedItem) : label), /*#__PURE__*/React__default["default"].createElement(index$1["default"].MenuIcon, {
|
|
328
362
|
isOpen: isOpen,
|
|
329
363
|
translateWithId: translateWithId
|
|
330
|
-
})),
|
|
364
|
+
})), slug ? normalizedDecorator : decorator ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
365
|
+
className: `${prefix}--list-box__inner-wrapper--decorator`
|
|
366
|
+
}, normalizedDecorator) : '', /*#__PURE__*/React__default["default"].createElement(index$1["default"].Menu, menuProps, isOpen && items.map((item, index) => {
|
|
331
367
|
const isObject = item !== null && typeof item === 'object';
|
|
332
368
|
const itemProps = getItemProps({
|
|
333
369
|
item,
|
|
@@ -370,6 +406,10 @@ Dropdown.propTypes = {
|
|
|
370
406
|
* Provide a custom className to be applied on the cds--dropdown node
|
|
371
407
|
*/
|
|
372
408
|
className: PropTypes__default["default"].string,
|
|
409
|
+
/**
|
|
410
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `Dropdown` component
|
|
411
|
+
*/
|
|
412
|
+
decorator: PropTypes__default["default"].node,
|
|
373
413
|
/**
|
|
374
414
|
* Specify the direction of the dropdown. Can be either top or bottom.
|
|
375
415
|
*/
|
|
@@ -463,7 +503,7 @@ Dropdown.propTypes = {
|
|
|
463
503
|
/**
|
|
464
504
|
* **Experimental**: Provide a `Slug` component to be rendered inside the `Dropdown` component
|
|
465
505
|
*/
|
|
466
|
-
slug: PropTypes__default["default"].node,
|
|
506
|
+
slug: deprecate["default"](PropTypes__default["default"].node, 'The `slug` prop for `Dropdown` has ' + 'been deprecated in favor of the new `decorator` prop. It will be removed in the next major release.'),
|
|
467
507
|
/**
|
|
468
508
|
* Provide the title text that will be read by a screen reader when
|
|
469
509
|
* visiting this control
|
|
@@ -129,8 +129,7 @@ function useChangedValue(value, compare, callback) {
|
|
|
129
129
|
*/
|
|
130
130
|
function useFeatureFlag(flag) {
|
|
131
131
|
const scope = React.useContext(FeatureFlagContext);
|
|
132
|
-
|
|
133
|
-
return scope.enabled(flag) ?? false;
|
|
132
|
+
return scope.enabled(flag);
|
|
134
133
|
}
|
|
135
134
|
|
|
136
135
|
/**
|
|
@@ -8,11 +8,14 @@ import React, { ReactNode } from 'react';
|
|
|
8
8
|
import { ButtonSize } from '../Button';
|
|
9
9
|
export declare const IconButtonKinds: readonly ["primary", "secondary", "ghost", "tertiary"];
|
|
10
10
|
export type IconButtonKind = (typeof IconButtonKinds)[number];
|
|
11
|
+
export type DeprecatedIconButtonAlignment = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'left-bottom' | 'left-top' | 'right-bottom' | 'right-top';
|
|
12
|
+
export type NewIconButtonAlignment = 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-end' | 'left-start' | 'right-end' | 'right-start';
|
|
13
|
+
export type IconButtonAlignment = DeprecatedIconButtonAlignment | NewIconButtonAlignment;
|
|
11
14
|
interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
12
15
|
/**
|
|
13
16
|
* Specify how the trigger should align with the tooltip
|
|
14
17
|
*/
|
|
15
|
-
align?:
|
|
18
|
+
align?: IconButtonAlignment;
|
|
16
19
|
/**
|
|
17
20
|
* **Experimental**: Will attempt to automatically align the tooltip
|
|
18
21
|
*/
|
|
@@ -17,6 +17,7 @@ require('../Tooltip/DefinitionTooltip.js');
|
|
|
17
17
|
var Tooltip = require('../Tooltip/Tooltip.js');
|
|
18
18
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
19
19
|
var ButtonBase = require('../Button/ButtonBase.js');
|
|
20
|
+
var deprecateValuesWithin = require('../../prop-types/deprecateValuesWithin.js');
|
|
20
21
|
|
|
21
22
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
23
|
|
|
@@ -25,6 +26,19 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
25
26
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
26
27
|
|
|
27
28
|
const IconButtonKinds = ['primary', 'secondary', 'ghost', 'tertiary'];
|
|
29
|
+
const propMappingFunction = deprecatedValue => {
|
|
30
|
+
const mapping = {
|
|
31
|
+
'top-left': 'top-start',
|
|
32
|
+
'top-right': 'top-end',
|
|
33
|
+
'bottom-left': 'bottom-start',
|
|
34
|
+
'bottom-right': 'bottom-end',
|
|
35
|
+
'left-bottom': 'left-end',
|
|
36
|
+
'left-top': 'left-start',
|
|
37
|
+
'right-bottom': 'right-end',
|
|
38
|
+
'right-top': 'right-start'
|
|
39
|
+
};
|
|
40
|
+
return mapping[deprecatedValue];
|
|
41
|
+
};
|
|
28
42
|
const IconButton = /*#__PURE__*/React__default["default"].forwardRef(function IconButton(_ref, ref) {
|
|
29
43
|
let {
|
|
30
44
|
align,
|
|
@@ -70,7 +84,32 @@ IconButton.propTypes = {
|
|
|
70
84
|
/**
|
|
71
85
|
* Specify how the trigger should align with the tooltip
|
|
72
86
|
*/
|
|
73
|
-
align: PropTypes__default["default"].oneOf(['top', 'top-left',
|
|
87
|
+
align: deprecateValuesWithin["default"](PropTypes__default["default"].oneOf(['top', 'top-left',
|
|
88
|
+
// deprecated use top-start instead
|
|
89
|
+
'top-right',
|
|
90
|
+
// deprecated use top-end instead
|
|
91
|
+
|
|
92
|
+
'bottom', 'bottom-left',
|
|
93
|
+
// deprecated use bottom-start instead
|
|
94
|
+
'bottom-right',
|
|
95
|
+
// deprecated use bottom-end instead
|
|
96
|
+
|
|
97
|
+
'left', 'left-bottom',
|
|
98
|
+
// deprecated use left-end instead
|
|
99
|
+
'left-top',
|
|
100
|
+
// deprecated use left-start instead
|
|
101
|
+
|
|
102
|
+
'right', 'right-bottom',
|
|
103
|
+
// deprecated use right-end instead
|
|
104
|
+
'right-top',
|
|
105
|
+
// deprecated use right-start instead
|
|
106
|
+
|
|
107
|
+
// new values to match floating-ui
|
|
108
|
+
'top-start', 'top-end', 'bottom-start', 'bottom-end', 'left-end', 'left-start', 'right-end', 'right-start']),
|
|
109
|
+
//allowed prop values
|
|
110
|
+
['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end'],
|
|
111
|
+
//optional mapper function
|
|
112
|
+
propMappingFunction),
|
|
74
113
|
/**
|
|
75
114
|
* **Experimental**: Will attempt to automatically align the tooltip
|
|
76
115
|
*/
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface InlineCheckboxProps {
|
|
3
|
+
'aria-label': string;
|
|
4
|
+
/**
|
|
5
|
+
* Deprecated, please use `aria-label` instead.
|
|
6
|
+
* Specify the label for the control
|
|
7
|
+
*/
|
|
8
|
+
ariaLabel?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Specify whether the underlying control is checked,
|
|
11
|
+
* or not
|
|
12
|
+
* @default false
|
|
13
|
+
* */
|
|
14
|
+
checked?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Specify whether the underlying input control should be disabled
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Provide an `id` for the underlying input control
|
|
22
|
+
*/
|
|
23
|
+
id: string;
|
|
24
|
+
/**
|
|
25
|
+
* Specify whether the control is in an indeterminate state
|
|
26
|
+
*/
|
|
27
|
+
indeterminate?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Provide a `name` for the underlying input control
|
|
30
|
+
*/
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* Provide an optional hook that is called each time the input is updated
|
|
34
|
+
*/
|
|
35
|
+
onChange?: (checked: boolean, id: string, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Provide a handler that is invoked when a user clicks on the control
|
|
38
|
+
*/
|
|
39
|
+
onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Provide a handler that is invoked on the key down event for the control
|
|
42
|
+
*/
|
|
43
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Provide an optional tooltip for the InlineCheckbox
|
|
46
|
+
*/
|
|
47
|
+
title?: string;
|
|
48
|
+
}
|
|
49
|
+
declare const InlineCheckbox: React.ForwardRefExoticComponent<InlineCheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
50
|
+
export default InlineCheckbox;
|
|
@@ -20,7 +20,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
20
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
21
21
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
22
22
|
|
|
23
|
-
/** @type any */
|
|
24
23
|
const InlineCheckbox = /*#__PURE__*/React__default["default"].forwardRef(function InlineCheckbox(props, forwardRef) {
|
|
25
24
|
const {
|
|
26
25
|
['aria-label']: ariaLabel,
|
|
@@ -57,15 +56,14 @@ const InlineCheckbox = /*#__PURE__*/React__default["default"].forwardRef(functio
|
|
|
57
56
|
}
|
|
58
57
|
React.useEffect(() => {
|
|
59
58
|
if (inputRef?.current) {
|
|
60
|
-
inputRef.current.indeterminate = indeterminate;
|
|
59
|
+
inputRef.current.indeterminate = indeterminate || false;
|
|
61
60
|
}
|
|
62
61
|
}, [indeterminate]);
|
|
63
62
|
function onClickCheckBoxInput(evt) {
|
|
64
|
-
// If the previous "indeterminate" is true, change "checked" to false. If it is not undefined, we're working on `TableSelectAll`
|
|
65
63
|
if (indeterminate) {
|
|
66
64
|
evt.target.checked = false;
|
|
67
65
|
}
|
|
68
|
-
onClick(evt);
|
|
66
|
+
onClick?.(evt);
|
|
69
67
|
}
|
|
70
68
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
71
69
|
className: `${prefix}--checkbox--inline`
|
|
@@ -130,6 +128,5 @@ InlineCheckbox.propTypes = {
|
|
|
130
128
|
*/
|
|
131
129
|
title: PropTypes__default["default"].string
|
|
132
130
|
};
|
|
133
|
-
var InlineCheckbox$1 = InlineCheckbox;
|
|
134
131
|
|
|
135
|
-
exports["default"] = InlineCheckbox
|
|
132
|
+
exports["default"] = InlineCheckbox;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 InlineCheckbox, { type InlineCheckboxProps } from './InlineCheckbox';
|
|
8
|
+
export default InlineCheckbox;
|
|
9
|
+
export { InlineCheckbox, type InlineCheckboxProps };
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { ElementType, ReactNode } from 'react';
|
|
9
|
+
import { LayoutDirectionContext } from './LayoutDirectionContext';
|
|
10
|
+
type Direction = 'ltr' | 'rtl';
|
|
11
|
+
interface LayoutDirectionProps {
|
|
12
|
+
/**
|
|
13
|
+
* Customize the element type used to render the outermost node
|
|
14
|
+
*/
|
|
15
|
+
as?: ElementType;
|
|
16
|
+
/**
|
|
17
|
+
* Provide child elements or components to be rendered inside of this
|
|
18
|
+
* component
|
|
19
|
+
*/
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Specify the layout direction of this part of the page
|
|
23
|
+
*/
|
|
24
|
+
dir: Direction;
|
|
25
|
+
}
|
|
26
|
+
declare function LayoutDirection({ as: BaseComponent, children, dir, ...rest }: LayoutDirectionProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
declare namespace LayoutDirection {
|
|
28
|
+
var propTypes: {
|
|
29
|
+
/**
|
|
30
|
+
* Customize the element type used to render the outermost node
|
|
31
|
+
*/
|
|
32
|
+
as: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.ReactComponentLike | null | undefined>>;
|
|
33
|
+
/**
|
|
34
|
+
* Provide child elements or components to be rendered inside of this
|
|
35
|
+
* component
|
|
36
|
+
*/
|
|
37
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
38
|
+
/**
|
|
39
|
+
* Specify the layout direction of this part of the page
|
|
40
|
+
*/
|
|
41
|
+
dir: PropTypes.Validator<string>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export { LayoutDirectionContext, LayoutDirection };
|
|
@@ -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 React from 'react';
|
|
8
|
+
export declare const LayoutDirectionContext: React.Context<{
|
|
9
|
+
direction: string;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
* Get access to the current layout direction in context
|
|
9
|
+
*/
|
|
10
|
+
export declare function useLayoutDirection(): {
|
|
11
|
+
direction: string;
|
|
12
|
+
};
|
|
@@ -253,9 +253,6 @@ const MenuItemSelectable = /*#__PURE__*/React.forwardRef(function MenuItemSelect
|
|
|
253
253
|
});
|
|
254
254
|
function handleClick(e) {
|
|
255
255
|
setChecked(!checked);
|
|
256
|
-
if (onChange) {
|
|
257
|
-
onChange(e);
|
|
258
|
-
}
|
|
259
256
|
}
|
|
260
257
|
React.useEffect(() => {
|
|
261
258
|
if (!context.state.hasIcons) {
|