@carbon/react 1.70.0 → 1.71.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 +972 -947
- package/es/components/AILabel/index.js +15 -15
- package/es/components/Checkbox/Checkbox.d.ts +5 -0
- package/es/components/Checkbox/Checkbox.js +16 -7
- package/es/components/CheckboxGroup/CheckboxGroup.d.ts +5 -0
- package/es/components/CheckboxGroup/CheckboxGroup.js +16 -7
- package/es/components/CodeSnippet/CodeSnippet.d.ts +5 -2
- package/es/components/CodeSnippet/CodeSnippet.js +40 -1
- package/es/components/ComboBox/ComboBox.d.ts +1 -1
- package/es/components/ComboBox/ComboBox.js +19 -22
- package/es/components/ComboButton/index.js +40 -1
- package/es/components/ComposedModal/ComposedModal.d.ts +5 -0
- package/es/components/ComposedModal/ComposedModal.js +16 -10
- 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/FluidNumberInput/FluidNumberInput.d.ts +4 -0
- package/es/components/FluidSelect/FluidSelect.d.ts +4 -0
- package/es/components/FluidSelect/FluidSelect.js +5 -1
- package/es/components/FluidTextArea/FluidTextArea.d.ts +4 -0
- package/es/components/FluidTextArea/FluidTextArea.js +5 -1
- package/es/components/FluidTextInput/FluidPasswordInput.d.ts +4 -0
- package/es/components/FluidTextInput/FluidPasswordInput.js +5 -1
- package/es/components/FluidTextInput/FluidTextInput.d.ts +4 -0
- package/es/components/FluidTextInput/FluidTextInput.js +5 -1
- package/es/components/FluidTimePicker/FluidTimePicker.d.ts +4 -0
- package/es/components/FluidTimePicker/FluidTimePicker.js +23 -7
- 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/Modal/Modal.d.ts +5 -0
- package/es/components/Modal/Modal.js +16 -10
- 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 +22 -5
- package/es/components/RadioButton/RadioButton.d.ts +5 -0
- package/es/components/RadioButton/RadioButton.js +16 -7
- package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +5 -0
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +16 -7
- package/es/components/RadioTile/RadioTile.d.ts +5 -0
- package/es/components/RadioTile/RadioTile.js +17 -8
- package/es/components/Tabs/Tabs.js +46 -29
- package/es/components/Tag/DismissibleTag.d.ts +11 -2
- package/es/components/Tag/DismissibleTag.js +13 -5
- package/es/components/Tag/Tag.d.ts +5 -0
- package/es/components/Tag/Tag.js +14 -7
- 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/Tile/Tile.d.ts +21 -1
- package/es/components/Tile/Tile.js +68 -48
- 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/Checkbox/Checkbox.d.ts +5 -0
- package/lib/components/Checkbox/Checkbox.js +16 -7
- package/lib/components/CheckboxGroup/CheckboxGroup.d.ts +5 -0
- package/lib/components/CheckboxGroup/CheckboxGroup.js +16 -7
- package/lib/components/CodeSnippet/CodeSnippet.d.ts +5 -2
- package/lib/components/CodeSnippet/CodeSnippet.js +40 -1
- package/lib/components/ComboBox/ComboBox.d.ts +1 -1
- package/lib/components/ComboBox/ComboBox.js +19 -22
- package/lib/components/ComboButton/index.js +40 -1
- package/lib/components/ComposedModal/ComposedModal.d.ts +5 -0
- package/lib/components/ComposedModal/ComposedModal.js +16 -10
- 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/FluidNumberInput/FluidNumberInput.d.ts +4 -0
- package/lib/components/FluidSelect/FluidSelect.d.ts +4 -0
- package/lib/components/FluidSelect/FluidSelect.js +5 -1
- package/lib/components/FluidTextArea/FluidTextArea.d.ts +4 -0
- package/lib/components/FluidTextArea/FluidTextArea.js +5 -1
- package/lib/components/FluidTextInput/FluidPasswordInput.d.ts +4 -0
- package/lib/components/FluidTextInput/FluidPasswordInput.js +5 -1
- package/lib/components/FluidTextInput/FluidTextInput.d.ts +4 -0
- package/lib/components/FluidTextInput/FluidTextInput.js +5 -1
- package/lib/components/FluidTimePicker/FluidTimePicker.d.ts +4 -0
- package/lib/components/FluidTimePicker/FluidTimePicker.js +23 -7
- 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/Modal/Modal.d.ts +5 -0
- package/lib/components/Modal/Modal.js +16 -10
- 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 +22 -5
- package/lib/components/RadioButton/RadioButton.d.ts +5 -0
- package/lib/components/RadioButton/RadioButton.js +16 -7
- package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +5 -0
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +16 -7
- package/lib/components/RadioTile/RadioTile.d.ts +5 -0
- package/lib/components/RadioTile/RadioTile.js +17 -8
- package/lib/components/Tabs/Tabs.js +46 -29
- package/lib/components/Tag/DismissibleTag.d.ts +11 -2
- package/lib/components/Tag/DismissibleTag.js +13 -5
- package/lib/components/Tag/Tag.d.ts +5 -0
- package/lib/components/Tag/Tag.js +14 -7
- 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/Tile/Tile.d.ts +21 -1
- package/lib/components/Tile/Tile.js +67 -47
- package/lib/components/UIShell/SideNavMenuItem.d.ts +5 -1
- package/lib/components/UIShell/SideNavMenuItem.js +7 -2
- package/package.json +5 -5
|
@@ -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
|
/**
|
|
@@ -90,6 +90,10 @@ export interface FluidNumberInputProps {
|
|
|
90
90
|
* Provide the text that is displayed when the control is in warning state
|
|
91
91
|
*/
|
|
92
92
|
warnText?: React.ReactNode;
|
|
93
|
+
/**
|
|
94
|
+
* Whether or not the component is readonly
|
|
95
|
+
*/
|
|
96
|
+
readOnly?: boolean;
|
|
93
97
|
}
|
|
94
98
|
declare const FluidNumberInput: React.FC<FluidNumberInputProps>;
|
|
95
99
|
export default FluidNumberInput;
|
|
@@ -52,6 +52,10 @@ export interface FluidSelectProps {
|
|
|
52
52
|
* Provide the text that is displayed when the control is in warning state
|
|
53
53
|
*/
|
|
54
54
|
warnText?: React.ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* Whether or not the component is readonly
|
|
57
|
+
*/
|
|
58
|
+
readOnly?: boolean;
|
|
55
59
|
}
|
|
56
60
|
declare const FluidSelect: React.ForwardRefExoticComponent<FluidSelectProps & React.RefAttributes<HTMLSelectElement>>;
|
|
57
61
|
export default FluidSelect;
|
|
@@ -87,7 +87,11 @@ FluidSelect.propTypes = {
|
|
|
87
87
|
/**
|
|
88
88
|
* Provide the text that is displayed when the control is in warning state
|
|
89
89
|
*/
|
|
90
|
-
warnText: PropTypes__default["default"].node
|
|
90
|
+
warnText: PropTypes__default["default"].node,
|
|
91
|
+
/**
|
|
92
|
+
* Whether or not the component is readonly
|
|
93
|
+
*/
|
|
94
|
+
readOnly: PropTypes__default["default"].bool
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
exports["default"] = FluidSelect;
|
|
@@ -91,6 +91,10 @@ export interface FluidTextAreaProps {
|
|
|
91
91
|
* Provide the text that is displayed when the control is in warning state
|
|
92
92
|
*/
|
|
93
93
|
warnText?: React.ReactNode;
|
|
94
|
+
/**
|
|
95
|
+
* Whether or not the component is readonly
|
|
96
|
+
*/
|
|
97
|
+
readOnly?: boolean;
|
|
94
98
|
}
|
|
95
99
|
declare const FluidTextArea: React.FC<FluidTextAreaProps>;
|
|
96
100
|
export default FluidTextArea;
|
|
@@ -125,7 +125,11 @@ FluidTextArea.propTypes = {
|
|
|
125
125
|
/**
|
|
126
126
|
* Provide the text that is displayed when the control is in warning state
|
|
127
127
|
*/
|
|
128
|
-
warnText: PropTypes__default["default"].node
|
|
128
|
+
warnText: PropTypes__default["default"].node,
|
|
129
|
+
/**
|
|
130
|
+
* Whether or not the component is readonly
|
|
131
|
+
*/
|
|
132
|
+
readOnly: PropTypes__default["default"].bool
|
|
129
133
|
};
|
|
130
134
|
|
|
131
135
|
exports["default"] = FluidTextArea;
|
|
@@ -78,6 +78,10 @@ export interface FluidPasswordInputProps {
|
|
|
78
78
|
* Provide the text that is displayed when the control is in warning state
|
|
79
79
|
*/
|
|
80
80
|
warnText?: React.ReactNode;
|
|
81
|
+
/**
|
|
82
|
+
* Whether or not the component is readonly
|
|
83
|
+
*/
|
|
84
|
+
readOnly?: boolean;
|
|
81
85
|
}
|
|
82
86
|
declare const FluidPasswordInput: React.FC<FluidPasswordInputProps>;
|
|
83
87
|
export default FluidPasswordInput;
|
|
@@ -89,5 +89,9 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
|
89
89
|
/**
|
|
90
90
|
* Provide the text that is displayed when the control is in warning state
|
|
91
91
|
*/
|
|
92
|
-
warnText: PropTypes__default["default"].node
|
|
92
|
+
warnText: PropTypes__default["default"].node,
|
|
93
|
+
/**
|
|
94
|
+
* Whether or not the component is readonly
|
|
95
|
+
*/
|
|
96
|
+
readOnly: PropTypes__default["default"].bool
|
|
93
97
|
});
|
|
@@ -65,6 +65,10 @@ export interface FluidTextInputProps {
|
|
|
65
65
|
* Provide the text that is displayed when the control is in warning state
|
|
66
66
|
*/
|
|
67
67
|
warnText?: React.ReactNode;
|
|
68
|
+
/**
|
|
69
|
+
* Whether or not the component is readonly
|
|
70
|
+
*/
|
|
71
|
+
readOnly?: boolean;
|
|
68
72
|
}
|
|
69
73
|
declare const FluidTextInput: React.ForwardRefExoticComponent<FluidTextInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
70
74
|
export default FluidTextInput;
|
|
@@ -107,7 +107,11 @@ FluidTextInput.propTypes = {
|
|
|
107
107
|
/**
|
|
108
108
|
* Provide the text that is displayed when the control is in warning state
|
|
109
109
|
*/
|
|
110
|
-
warnText: PropTypes__default["default"].node
|
|
110
|
+
warnText: PropTypes__default["default"].node,
|
|
111
|
+
/**
|
|
112
|
+
* Whether or not the component is readonly
|
|
113
|
+
*/
|
|
114
|
+
readOnly: PropTypes__default["default"].bool
|
|
111
115
|
};
|
|
112
116
|
|
|
113
117
|
exports["default"] = FluidTextInput;
|
|
@@ -40,6 +40,10 @@ export interface FluidTimePickerProps extends FluidTextInputProps {
|
|
|
40
40
|
* Provide the text that is displayed when the control is in warning state
|
|
41
41
|
*/
|
|
42
42
|
warnText?: React.ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Specify if the component is readonly
|
|
45
|
+
*/
|
|
46
|
+
readOnly?: boolean;
|
|
43
47
|
}
|
|
44
48
|
declare const FluidTimePicker: React.ForwardRefExoticComponent<FluidTimePickerProps & React.RefAttributes<HTMLInputElement>>;
|
|
45
49
|
export default FluidTimePicker;
|
|
@@ -34,6 +34,7 @@ const FluidTimePicker = /*#__PURE__*/React__default["default"].forwardRef(functi
|
|
|
34
34
|
invalidText,
|
|
35
35
|
warn,
|
|
36
36
|
warnText,
|
|
37
|
+
readOnly,
|
|
37
38
|
...other
|
|
38
39
|
} = _ref;
|
|
39
40
|
const prefix = usePrefix.usePrefix();
|
|
@@ -53,6 +54,19 @@ const FluidTimePicker = /*#__PURE__*/React__default["default"].forwardRef(functi
|
|
|
53
54
|
}
|
|
54
55
|
};
|
|
55
56
|
const error = invalid || warn;
|
|
57
|
+
const childrenWithProps = () => {
|
|
58
|
+
if (disabled) {
|
|
59
|
+
return React__default["default"].Children.toArray(children).map(child => /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
60
|
+
disabled: true
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
if (readOnly) {
|
|
64
|
+
return React__default["default"].Children.toArray(children).map(child => /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
65
|
+
readOnly: true
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
return children;
|
|
69
|
+
};
|
|
56
70
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
57
71
|
className: classNames
|
|
58
72
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -60,12 +74,10 @@ const FluidTimePicker = /*#__PURE__*/React__default["default"].forwardRef(functi
|
|
|
60
74
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
61
75
|
className: `${prefix}--time-picker__input`
|
|
62
76
|
}, /*#__PURE__*/React__default["default"].createElement(FluidTextInput["default"], _rollupPluginBabelHelpers["extends"]({
|
|
63
|
-
ref: ref
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
}) : children), error && /*#__PURE__*/React__default["default"].createElement("hr", {
|
|
77
|
+
ref: ref,
|
|
78
|
+
readOnly: readOnly,
|
|
79
|
+
disabled: disabled
|
|
80
|
+
}, other))), childrenWithProps()), error && /*#__PURE__*/React__default["default"].createElement("hr", {
|
|
69
81
|
className: `${prefix}--time-picker__divider`
|
|
70
82
|
}), error && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
71
83
|
className: `${prefix}--form-requirement`
|
|
@@ -108,7 +120,11 @@ FluidTimePicker.propTypes = {
|
|
|
108
120
|
/**
|
|
109
121
|
* Provide the text that is displayed when the control is in warning state
|
|
110
122
|
*/
|
|
111
|
-
warnText: PropTypes__default["default"].node
|
|
123
|
+
warnText: PropTypes__default["default"].node,
|
|
124
|
+
/**
|
|
125
|
+
* Whether or not the component is readonly
|
|
126
|
+
*/
|
|
127
|
+
readOnly: PropTypes__default["default"].bool
|
|
112
128
|
};
|
|
113
129
|
|
|
114
130
|
exports["default"] = FluidTimePicker;
|
|
@@ -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
|
*/
|