@itwin/itwinui-react 1.37.3 → 1.39.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/CHANGELOG.md +34 -0
- package/cjs/core/Breadcrumbs/Breadcrumbs.js +3 -5
- package/cjs/core/Carousel/Carousel.js +21 -12
- package/cjs/core/Carousel/CarouselContext.d.ts +4 -2
- package/cjs/core/Carousel/CarouselDotsList.js +1 -0
- package/cjs/core/Carousel/CarouselNavigation.js +8 -10
- package/cjs/core/Carousel/CarouselSlide.js +3 -7
- package/cjs/core/Carousel/CarouselSlider.js +23 -28
- package/cjs/core/ColorPicker/ColorPickerContext.d.ts +2 -2
- package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/cjs/core/ComboBox/ComboBox.d.ts +11 -2
- package/cjs/core/ComboBox/ComboBox.js +138 -246
- package/cjs/core/ComboBox/ComboBoxDropdown.d.ts +7 -0
- package/cjs/core/ComboBox/ComboBoxDropdown.js +55 -0
- package/cjs/core/ComboBox/ComboBoxEndIcon.d.ts +5 -0
- package/cjs/core/ComboBox/ComboBoxEndIcon.js +54 -0
- package/cjs/core/ComboBox/ComboBoxInput.d.ts +5 -0
- package/cjs/core/ComboBox/ComboBoxInput.js +152 -0
- package/cjs/core/ComboBox/ComboBoxInputContainer.d.ts +8 -0
- package/cjs/core/ComboBox/ComboBoxInputContainer.js +45 -0
- package/cjs/core/ComboBox/ComboBoxMenu.d.ts +3 -0
- package/cjs/core/ComboBox/ComboBoxMenu.js +89 -0
- package/cjs/core/ComboBox/ComboBoxMenuItem.d.ts +21 -0
- package/cjs/core/ComboBox/ComboBoxMenuItem.js +64 -0
- package/cjs/core/ComboBox/helpers.d.ts +32 -0
- package/cjs/core/ComboBox/helpers.js +50 -0
- package/cjs/core/DatePicker/DatePicker.d.ts +1 -1
- package/cjs/core/Modal/Modal.d.ts +1 -1
- package/cjs/core/Modal/Modal.js +6 -6
- package/cjs/core/Modal/ModalButtonBar.d.ts +1 -1
- package/cjs/core/Modal/ModalButtonBar.js +2 -2
- package/cjs/core/Modal/ModalContent.d.ts +1 -1
- package/cjs/core/Modal/ModalContent.js +2 -2
- package/cjs/core/RadioTiles/RadioTile.d.ts +1 -1
- package/cjs/core/RadioTiles/RadioTile.js +7 -9
- package/cjs/core/Select/Select.js +1 -1
- package/cjs/core/Table/Table.js +33 -23
- package/cjs/core/Table/TablePaginator.js +1 -1
- package/cjs/core/Table/filters/FilterToggle.js +3 -2
- package/cjs/core/Table/filters/tableFilters.d.ts +3 -3
- package/cjs/core/Table/hooks/useExpanderCell.js +11 -1
- package/cjs/core/Toast/ToastWrapper.d.ts +7 -5
- package/cjs/core/Toast/ToastWrapper.js +8 -4
- package/cjs/core/Toast/Toaster.d.ts +3 -0
- package/cjs/core/Toast/Toaster.js +110 -6
- package/cjs/core/utils/components/Popover.d.ts +1 -18
- package/cjs/core/utils/components/VirtualScroll.d.ts +35 -1
- package/cjs/core/utils/components/VirtualScroll.js +159 -26
- package/cjs/core/utils/components/WithCSSTransition.d.ts +1 -2
- package/cjs/core/utils/components/icons.d.ts +4 -4
- package/cjs/core/utils/hooks/index.d.ts +1 -0
- package/cjs/core/utils/hooks/index.js +1 -0
- package/cjs/core/utils/hooks/useOverflow.js +4 -2
- package/cjs/core/utils/hooks/useSafeContext.d.ts +6 -0
- package/cjs/core/utils/hooks/useSafeContext.js +23 -0
- package/cjs/core/utils/hooks/useTheme.d.ts +1 -1
- package/esm/core/Breadcrumbs/Breadcrumbs.js +3 -5
- package/esm/core/Carousel/Carousel.js +21 -12
- package/esm/core/Carousel/CarouselContext.d.ts +4 -2
- package/esm/core/Carousel/CarouselDotsList.js +1 -0
- package/esm/core/Carousel/CarouselNavigation.js +8 -10
- package/esm/core/Carousel/CarouselSlide.js +3 -7
- package/esm/core/Carousel/CarouselSlider.js +24 -29
- package/esm/core/ColorPicker/ColorPickerContext.d.ts +2 -2
- package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/esm/core/ComboBox/ComboBox.d.ts +11 -2
- package/esm/core/ComboBox/ComboBox.js +140 -248
- package/esm/core/ComboBox/ComboBoxDropdown.d.ts +7 -0
- package/esm/core/ComboBox/ComboBoxDropdown.js +49 -0
- package/esm/core/ComboBox/ComboBoxEndIcon.d.ts +5 -0
- package/esm/core/ComboBox/ComboBoxEndIcon.js +48 -0
- package/esm/core/ComboBox/ComboBoxInput.d.ts +5 -0
- package/esm/core/ComboBox/ComboBoxInput.js +146 -0
- package/esm/core/ComboBox/ComboBoxInputContainer.d.ts +8 -0
- package/esm/core/ComboBox/ComboBoxInputContainer.js +38 -0
- package/esm/core/ComboBox/ComboBoxMenu.d.ts +3 -0
- package/esm/core/ComboBox/ComboBoxMenu.js +83 -0
- package/esm/core/ComboBox/ComboBoxMenuItem.d.ts +21 -0
- package/esm/core/ComboBox/ComboBoxMenuItem.js +58 -0
- package/esm/core/ComboBox/helpers.d.ts +32 -0
- package/esm/core/ComboBox/helpers.js +43 -0
- package/esm/core/DatePicker/DatePicker.d.ts +1 -1
- package/esm/core/Modal/Modal.d.ts +1 -1
- package/esm/core/Modal/Modal.js +6 -6
- package/esm/core/Modal/ModalButtonBar.d.ts +1 -1
- package/esm/core/Modal/ModalButtonBar.js +2 -2
- package/esm/core/Modal/ModalContent.d.ts +1 -1
- package/esm/core/Modal/ModalContent.js +2 -2
- package/esm/core/RadioTiles/RadioTile.d.ts +1 -1
- package/esm/core/RadioTiles/RadioTile.js +7 -9
- package/esm/core/Select/Select.js +1 -1
- package/esm/core/Table/Table.js +33 -23
- package/esm/core/Table/TablePaginator.js +1 -1
- package/esm/core/Table/filters/FilterToggle.js +3 -2
- package/esm/core/Table/filters/tableFilters.d.ts +3 -3
- package/esm/core/Table/hooks/useExpanderCell.js +8 -1
- package/esm/core/Toast/ToastWrapper.d.ts +7 -5
- package/esm/core/Toast/ToastWrapper.js +8 -3
- package/esm/core/Toast/Toaster.d.ts +3 -0
- package/esm/core/Toast/Toaster.js +88 -7
- package/esm/core/utils/components/Popover.d.ts +1 -18
- package/esm/core/utils/components/VirtualScroll.d.ts +35 -1
- package/esm/core/utils/components/VirtualScroll.js +157 -25
- package/esm/core/utils/components/WithCSSTransition.d.ts +1 -2
- package/esm/core/utils/components/icons.d.ts +4 -4
- package/esm/core/utils/hooks/index.d.ts +1 -0
- package/esm/core/utils/hooks/index.js +1 -0
- package/esm/core/utils/hooks/useOverflow.js +4 -2
- package/esm/core/utils/hooks/useSafeContext.d.ts +6 -0
- package/esm/core/utils/hooks/useSafeContext.js +16 -0
- package/esm/core/utils/hooks/useTheme.d.ts +1 -1
- package/package.json +27 -70
|
@@ -32,13 +32,22 @@ exports.ComboBox = void 0;
|
|
|
32
32
|
*--------------------------------------------------------------------------------------------*/
|
|
33
33
|
var react_1 = __importDefault(require("react"));
|
|
34
34
|
var classnames_1 = __importDefault(require("classnames"));
|
|
35
|
-
var Input_1 = require("../Input");
|
|
36
35
|
var Menu_1 = require("../Menu");
|
|
37
36
|
var Typography_1 = require("../Typography");
|
|
38
37
|
var utils_1 = require("../utils");
|
|
39
|
-
var CaretDownSmall_1 = __importDefault(require("@itwin/itwinui-icons-react/cjs/icons/CaretDownSmall"));
|
|
40
38
|
require("tippy.js/animations/shift-away.css");
|
|
41
|
-
var
|
|
39
|
+
var helpers_1 = require("./helpers");
|
|
40
|
+
var ComboBoxDropdown_1 = require("./ComboBoxDropdown");
|
|
41
|
+
var ComboBoxEndIcon_1 = require("./ComboBoxEndIcon");
|
|
42
|
+
var ComboBoxInput_1 = require("./ComboBoxInput");
|
|
43
|
+
var ComboBoxInputContainer_1 = require("./ComboBoxInputContainer");
|
|
44
|
+
var ComboBoxMenu_1 = require("./ComboBoxMenu");
|
|
45
|
+
var ComboBoxMenuItem_1 = require("./ComboBoxMenuItem");
|
|
46
|
+
/** Returns either `option.id` or derives a stable id using `idPrefix` and `option.label` (without whitespace) */
|
|
47
|
+
var getOptionId = function (option, idPrefix) {
|
|
48
|
+
var _a;
|
|
49
|
+
return (_a = option.id) !== null && _a !== void 0 ? _a : "".concat(idPrefix, "-option-").concat(option.label.replace(/\s/g, '-'));
|
|
50
|
+
};
|
|
42
51
|
/**
|
|
43
52
|
* ComboBox component that allows typing a value to filter the options in dropdown list.
|
|
44
53
|
* Values can be selected either using mouse clicks or using the Enter key.
|
|
@@ -53,273 +62,156 @@ var StatusMessage_1 = require("../StatusMessage");
|
|
|
53
62
|
* />
|
|
54
63
|
*/
|
|
55
64
|
var ComboBox = function (props) {
|
|
56
|
-
var
|
|
65
|
+
var _a;
|
|
66
|
+
var options = props.options, valueProp = props.value, onChange = props.onChange, filterFunction = props.filterFunction, inputProps = props.inputProps, dropdownMenuProps = props.dropdownMenuProps, _b = props.emptyStateMessage, emptyStateMessage = _b === void 0 ? 'No options found' : _b, itemRenderer = props.itemRenderer, _c = props.enableVirtualization, enableVirtualization = _c === void 0 ? false : _c, rest = __rest(props, ["options", "value", "onChange", "filterFunction", "inputProps", "dropdownMenuProps", "emptyStateMessage", "itemRenderer", "enableVirtualization"]);
|
|
57
67
|
// Generate a stateful random id if not specified
|
|
58
68
|
var id = react_1.default.useState(function () {
|
|
59
69
|
var _a, _b;
|
|
60
70
|
return (_b = (_a = props.id) !== null && _a !== void 0 ? _a : ((inputProps === null || inputProps === void 0 ? void 0 : inputProps.id) && "".concat(inputProps.id, "-cb"))) !== null && _b !== void 0 ? _b : "iui-cb-".concat((0, utils_1.getRandomValue)(10));
|
|
61
71
|
})[0];
|
|
62
72
|
(0, utils_1.useTheme)();
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}));
|
|
70
|
-
}, [options, id]);
|
|
71
|
-
var userOnChange = react_1.default.useRef(onChange);
|
|
73
|
+
// Refs get set in subcomponents
|
|
74
|
+
var inputRef = react_1.default.useRef(null);
|
|
75
|
+
var menuRef = react_1.default.useRef(null);
|
|
76
|
+
var toggleButtonRef = react_1.default.useRef(null);
|
|
77
|
+
// Latest value of the onChange prop
|
|
78
|
+
var onChangeProp = react_1.default.useRef(onChange);
|
|
72
79
|
react_1.default.useEffect(function () {
|
|
73
|
-
|
|
80
|
+
onChangeProp.current = onChange;
|
|
74
81
|
}, [onChange]);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
// Record to store all extra information (e.g. original indexes), where the key is the id of the option
|
|
83
|
+
var optionsExtraInfoRef = react_1.default.useRef({});
|
|
84
|
+
// Clear the extra info when the options change so that it can be reinitialized below
|
|
85
|
+
react_1.default.useEffect(function () {
|
|
86
|
+
optionsExtraInfoRef.current = {};
|
|
87
|
+
}, [options]);
|
|
88
|
+
// Initialize the extra info only if it is not already initialized
|
|
89
|
+
if (options.length > 0 &&
|
|
90
|
+
Object.keys(optionsExtraInfoRef.current).length === 0) {
|
|
91
|
+
options.forEach(function (option, index) {
|
|
92
|
+
optionsExtraInfoRef.current[getOptionId(option, id)] = {
|
|
93
|
+
__originalIndex: index,
|
|
87
94
|
};
|
|
88
|
-
if (itemRenderer) {
|
|
89
|
-
return react_1.default.cloneElement(itemRenderer(option, {
|
|
90
|
-
id: getOptionId(index),
|
|
91
|
-
index: index,
|
|
92
|
-
isSelected: false,
|
|
93
|
-
isFocused: false,
|
|
94
|
-
}), additionalProps);
|
|
95
|
-
}
|
|
96
|
-
return (react_1.default.createElement(Menu_1.MenuItem, __assign({ id: getOptionId(index), key: getOptionId(index) }, additionalProps, rest), label));
|
|
97
95
|
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
}
|
|
97
|
+
// Reducer where all the component-wide state is stored
|
|
98
|
+
var _d = react_1.default.useReducer(helpers_1.comboBoxReducer, {
|
|
99
|
+
isOpen: false,
|
|
100
|
+
selectedIndex: -1,
|
|
101
|
+
focusedIndex: -1,
|
|
102
|
+
}), _e = _d[0], isOpen = _e.isOpen, selectedIndex = _e.selectedIndex, focusedIndex = _e.focusedIndex, dispatch = _d[1];
|
|
103
|
+
react_1.default.useEffect(function () {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
// When the dropdown opens
|
|
106
|
+
if (isOpen) {
|
|
107
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); // Focus the input
|
|
108
|
+
setFilteredOptions(options); // Reset the filtered list
|
|
109
|
+
dispatch(['focus']);
|
|
110
|
+
}
|
|
111
|
+
// When the dropdown closes
|
|
112
|
+
else {
|
|
113
|
+
// Reset the focused index
|
|
114
|
+
dispatch(['focus']);
|
|
115
|
+
// Reset the input value
|
|
116
|
+
setInputValue(selectedIndex != undefined && selectedIndex >= 0
|
|
117
|
+
? (_b = options[selectedIndex]) === null || _b === void 0 ? void 0 : _b.label
|
|
118
|
+
: '');
|
|
119
|
+
}
|
|
120
|
+
}, [isOpen, options, selectedIndex]);
|
|
103
121
|
// Set min-width of menu to be same as input
|
|
104
|
-
var
|
|
122
|
+
var _f = react_1.default.useState(0), minWidth = _f[0], setMinWidth = _f[1];
|
|
105
123
|
react_1.default.useEffect(function () {
|
|
106
124
|
if (inputRef.current) {
|
|
107
125
|
setMinWidth(inputRef.current.offsetWidth);
|
|
108
126
|
}
|
|
109
127
|
}, [isOpen]);
|
|
110
|
-
|
|
128
|
+
// Initialize filtered options to the latest value options
|
|
129
|
+
var _g = react_1.default.useState(options), filteredOptions = _g[0], setFilteredOptions = _g[1];
|
|
111
130
|
react_1.default.useEffect(function () {
|
|
112
131
|
setFilteredOptions(options);
|
|
132
|
+
dispatch(['focus']);
|
|
113
133
|
}, [options]);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
(
|
|
128
|
-
}, [inputProps]);
|
|
129
|
-
//
|
|
134
|
+
// Filter options based on input value
|
|
135
|
+
var _h = react_1.default.useState((_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.value) !== null && _a !== void 0 ? _a : ''), inputValue = _h[0], setInputValue = _h[1];
|
|
136
|
+
var handleOnInput = react_1.default.useCallback(function (event) {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
var value = event.currentTarget.value;
|
|
139
|
+
setInputValue(value);
|
|
140
|
+
dispatch(['open']); // reopen when typing
|
|
141
|
+
setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, value)) !== null && _a !== void 0 ? _a : options.filter(function (option) {
|
|
142
|
+
return option.label.toLowerCase().includes(value.toLowerCase());
|
|
143
|
+
}));
|
|
144
|
+
if (focusedIndex != -1) {
|
|
145
|
+
dispatch(['focus', -1]);
|
|
146
|
+
}
|
|
147
|
+
(_b = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _b === void 0 ? void 0 : _b.call(inputProps, event);
|
|
148
|
+
}, [filterFunction, focusedIndex, inputProps, options]);
|
|
149
|
+
// When the value prop changes, update the selectedIndex
|
|
130
150
|
react_1.default.useEffect(function () {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
setFocusedIndex(selectedOption ? options.indexOf(selectedOption) : -1);
|
|
138
|
-
}, [selectedValue, options]);
|
|
139
|
-
// Filter options and update focus when input value changes
|
|
151
|
+
dispatch([
|
|
152
|
+
'select',
|
|
153
|
+
options.findIndex(function (option) { return option.value === valueProp; }),
|
|
154
|
+
]);
|
|
155
|
+
}, [options, valueProp]);
|
|
156
|
+
// Call user-defined onChange when the value actually changes
|
|
140
157
|
react_1.default.useEffect(function () {
|
|
141
|
-
var _a;
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var selectedOption = options.find(function (_a) {
|
|
147
|
-
var value = _a.value;
|
|
148
|
-
return value === selectedValue;
|
|
149
|
-
});
|
|
150
|
-
if (!inputValue || (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) === inputValue) {
|
|
151
|
-
setFilteredOptions(options);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
var _filteredOptions = (_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, inputValue)) !== null && _a !== void 0 ? _a : options.filter(function (option) {
|
|
155
|
-
return option.label.toLowerCase().includes(inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase());
|
|
156
|
-
});
|
|
157
|
-
setFilteredOptions(_filteredOptions);
|
|
158
|
-
setFocusedIndex(function (previouslyFocusedIndex) {
|
|
159
|
-
if (_filteredOptions.includes(options[previouslyFocusedIndex])) {
|
|
160
|
-
return previouslyFocusedIndex;
|
|
161
|
-
}
|
|
162
|
-
else if (_filteredOptions.find(function (_a) {
|
|
163
|
-
var value = _a.value;
|
|
164
|
-
return value === selectedValue;
|
|
165
|
-
})) {
|
|
166
|
-
return options.findIndex(function (_a) {
|
|
167
|
-
var value = _a.value;
|
|
168
|
-
return value === selectedValue;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
return -1; // reset focus if previously focused or selected value is not in filtered list
|
|
158
|
+
var _a, _b;
|
|
159
|
+
if (selectedIndex != undefined && selectedIndex >= 0) {
|
|
160
|
+
var value = (_a = options[selectedIndex]) === null || _a === void 0 ? void 0 : _a.value;
|
|
161
|
+
if (value === valueProp) {
|
|
162
|
+
return;
|
|
173
163
|
}
|
|
174
|
-
|
|
175
|
-
}, [inputValue, options, selectedValue, isOpen, filterFunction]);
|
|
176
|
-
var onKeyDown = react_1.default.useCallback(function (event) {
|
|
177
|
-
var _a;
|
|
178
|
-
var focusableOptions = (0, utils_1.getFocusableElements)(menuRef.current);
|
|
179
|
-
var focusedIndexInFilteredList = focusableOptions.findIndex(function (_a) {
|
|
180
|
-
var _b;
|
|
181
|
-
var id = _a.id;
|
|
182
|
-
return id === ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.getAttribute('aria-activedescendant'));
|
|
183
|
-
});
|
|
184
|
-
switch (event.key) {
|
|
185
|
-
case 'ArrowDown':
|
|
186
|
-
if (isOpen) {
|
|
187
|
-
var nextIndex_1 = Math.min(focusedIndexInFilteredList + 1, focusableOptions.length - 1);
|
|
188
|
-
setFocusedIndex(options.findIndex(function (_, index) {
|
|
189
|
-
return getOptionId(index) === focusableOptions[nextIndex_1].id;
|
|
190
|
-
}));
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
setIsOpen(true); // reopen menu if closed when typing
|
|
194
|
-
}
|
|
195
|
-
event.preventDefault();
|
|
196
|
-
event.stopPropagation();
|
|
197
|
-
break;
|
|
198
|
-
case 'ArrowUp':
|
|
199
|
-
if (isOpen) {
|
|
200
|
-
var previousIndex_1 = Math.max(focusedIndexInFilteredList - 1, 0);
|
|
201
|
-
setFocusedIndex(options.findIndex(function (_, index) {
|
|
202
|
-
return getOptionId(index) === focusableOptions[previousIndex_1].id;
|
|
203
|
-
}));
|
|
204
|
-
}
|
|
205
|
-
event.preventDefault();
|
|
206
|
-
event.stopPropagation();
|
|
207
|
-
break;
|
|
208
|
-
case 'Enter':
|
|
209
|
-
if (isOpen) {
|
|
210
|
-
setSelectedValue(options[focusedIndex].value);
|
|
211
|
-
(_a = userOnChange.current) === null || _a === void 0 ? void 0 : _a.call(userOnChange, options[focusedIndex].value);
|
|
212
|
-
}
|
|
213
|
-
setIsOpen(function (open) { return !open; });
|
|
214
|
-
event.preventDefault();
|
|
215
|
-
event.stopPropagation();
|
|
216
|
-
break;
|
|
217
|
-
case 'Escape':
|
|
218
|
-
setIsOpen(false);
|
|
219
|
-
event.preventDefault();
|
|
220
|
-
event.stopPropagation();
|
|
221
|
-
break;
|
|
222
|
-
case 'Tab':
|
|
223
|
-
setIsOpen(false);
|
|
224
|
-
break;
|
|
225
|
-
default:
|
|
226
|
-
if (!isOpen) {
|
|
227
|
-
setIsOpen(true); // reopen menu if closed when typing
|
|
228
|
-
}
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
}, [focusedIndex, isOpen, options, getOptionId]);
|
|
232
|
-
var menuItems = react_1.default.useMemo(function () {
|
|
233
|
-
if (filteredOptions.length === 0) {
|
|
234
|
-
return [
|
|
235
|
-
react_1.default.createElement(Menu_1.MenuExtraContent, { key: 0 },
|
|
236
|
-
react_1.default.createElement(Typography_1.Text, { isMuted: true }, emptyStateMessage)),
|
|
237
|
-
];
|
|
164
|
+
(_b = onChangeProp.current) === null || _b === void 0 ? void 0 : _b.call(onChangeProp, value);
|
|
238
165
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return (react_1.default.createElement(utils_1.InputContainer, __assign({ className: className, status: status, statusMessage: typeof message === 'string' ? (react_1.default.createElement(StatusMessage_1.StatusMessage, { status: status }, message)) : (react_1.default.isValidElement(message) &&
|
|
282
|
-
react_1.default.cloneElement(message, { status: status })) }, rest, { id: id }),
|
|
283
|
-
react_1.default.createElement("div", { className: 'iui-input-with-icon' },
|
|
284
|
-
react_1.default.createElement(utils_1.Popover, __assign({ placement: 'bottom-start', visible: isOpen, onClickOutside: function (_, _a) {
|
|
285
|
-
var _b;
|
|
286
|
-
var target = _a.target;
|
|
287
|
-
if (!((_b = toggleButtonRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
|
|
288
|
-
setIsOpen(false);
|
|
289
|
-
}
|
|
290
|
-
}, animation: 'shift-away', duration: 200 }, dropdownMenuProps, { content: react_1.default.createElement(Menu_1.Menu, { id: "".concat(id, "-list"), className: 'iui-scroll', style: {
|
|
291
|
-
minWidth: minWidth,
|
|
292
|
-
maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"),
|
|
293
|
-
maxHeight: 300,
|
|
294
|
-
}, setFocus: false, role: 'listbox', ref: menuRef }, menuItems), onHide: function (instance) {
|
|
295
|
-
var _a;
|
|
296
|
-
var selectedIndex = options.findIndex(function (_a) {
|
|
297
|
-
var value = _a.value;
|
|
298
|
-
return value === selectedValue;
|
|
299
|
-
});
|
|
300
|
-
setFocusedIndex(selectedIndex);
|
|
301
|
-
if (selectedIndex > -1) {
|
|
302
|
-
setInputValue(options[selectedIndex].label); // update input value to be same as selected value
|
|
303
|
-
}
|
|
304
|
-
(_a = dropdownMenuProps === null || dropdownMenuProps === void 0 ? void 0 : dropdownMenuProps.onHide) === null || _a === void 0 ? void 0 : _a.call(dropdownMenuProps, instance);
|
|
305
|
-
} }),
|
|
306
|
-
react_1.default.createElement(Input_1.Input, __assign({ ref: inputRef, onKeyDown: onKeyDown, onFocus: function () { return setIsOpen(true); }, value: inputValue, "aria-activedescendant": isOpen && focusedIndex > -1
|
|
307
|
-
? getOptionId(focusedIndex)
|
|
308
|
-
: undefined, role: 'combobox', "aria-controls": isOpen ? "".concat(id, "-list") : undefined, "aria-autocomplete": 'list', spellCheck: false, autoCapitalize: 'none', autoCorrect: 'off' }, inputProps, { onChange: onInput }))),
|
|
309
|
-
react_1.default.createElement("span", { ref: toggleButtonRef, className: (0, classnames_1.default)('iui-end-icon', {
|
|
310
|
-
'iui-actionable': !(inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled),
|
|
311
|
-
'iui-disabled': inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled,
|
|
312
|
-
'iui-open': isOpen,
|
|
313
|
-
}), onClick: function () {
|
|
314
|
-
var _a;
|
|
315
|
-
if (isOpen) {
|
|
316
|
-
setIsOpen(false);
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
320
|
-
}
|
|
166
|
+
}, [options, selectedIndex, valueProp]);
|
|
167
|
+
var getMenuItem = react_1.default.useCallback(function (option, filteredIndex) {
|
|
168
|
+
var optionId = getOptionId(option, id);
|
|
169
|
+
var __originalIndex = optionsExtraInfoRef.current[optionId].__originalIndex;
|
|
170
|
+
var customItem = itemRenderer
|
|
171
|
+
? itemRenderer(option, {
|
|
172
|
+
isFocused: focusedIndex === __originalIndex,
|
|
173
|
+
isSelected: selectedIndex === __originalIndex,
|
|
174
|
+
index: __originalIndex,
|
|
175
|
+
id: optionId,
|
|
176
|
+
})
|
|
177
|
+
: null;
|
|
178
|
+
return customItem ? (react_1.default.cloneElement(customItem, {
|
|
179
|
+
onClick: function (e) {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
dispatch(['select', __originalIndex]);
|
|
182
|
+
(_b = (_a = customItem.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
183
|
+
},
|
|
184
|
+
// ComboBox.MenuItem handles scrollIntoView, data-iui-index and iui-focused through context
|
|
185
|
+
// but we still need to pass them here for backwards compatibility with MenuItem
|
|
186
|
+
className: (0, classnames_1.default)(customItem.props.className, {
|
|
187
|
+
'iui-focused': focusedIndex === __originalIndex,
|
|
188
|
+
}),
|
|
189
|
+
'data-iui-index': __originalIndex,
|
|
190
|
+
'data-iui-filtered-index': filteredIndex,
|
|
191
|
+
ref: (0, utils_1.mergeRefs)(customItem.props.ref, function (el) {
|
|
192
|
+
if (!enableVirtualization && focusedIndex === __originalIndex) {
|
|
193
|
+
el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
})) : (react_1.default.createElement(ComboBoxMenuItem_1.ComboBoxMenuItem, __assign({ key: optionId, id: optionId }, option, { isSelected: selectedIndex === __originalIndex, onClick: function () { return dispatch(['select', __originalIndex]); }, index: __originalIndex, "data-iui-filtered-index": filteredIndex }), option.label));
|
|
197
|
+
}, [enableVirtualization, focusedIndex, id, itemRenderer, selectedIndex]);
|
|
198
|
+
return (react_1.default.createElement(helpers_1.ComboBoxRefsContext.Provider, { value: { inputRef: inputRef, menuRef: menuRef, toggleButtonRef: toggleButtonRef, optionsExtraInfoRef: optionsExtraInfoRef } },
|
|
199
|
+
react_1.default.createElement(helpers_1.ComboBoxActionContext.Provider, { value: dispatch },
|
|
200
|
+
react_1.default.createElement(helpers_1.ComboBoxStateContext.Provider, { value: {
|
|
201
|
+
id: id,
|
|
202
|
+
minWidth: minWidth,
|
|
203
|
+
isOpen: isOpen,
|
|
204
|
+
focusedIndex: focusedIndex,
|
|
205
|
+
enableVirtualization: enableVirtualization,
|
|
206
|
+
filteredOptions: filteredOptions,
|
|
207
|
+
getMenuItem: getMenuItem,
|
|
321
208
|
} },
|
|
322
|
-
react_1.default.createElement(
|
|
209
|
+
react_1.default.createElement(ComboBoxInputContainer_1.ComboBoxInputContainer, __assign({ disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled }, rest),
|
|
210
|
+
react_1.default.createElement(ComboBoxInput_1.ComboBoxInput, __assign({ value: inputValue }, inputProps, { onChange: handleOnInput })),
|
|
211
|
+
react_1.default.createElement(ComboBoxEndIcon_1.ComboBoxEndIcon, { disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled, isOpen: isOpen })),
|
|
212
|
+
react_1.default.createElement(ComboBoxDropdown_1.ComboBoxDropdown, __assign({}, dropdownMenuProps),
|
|
213
|
+
react_1.default.createElement(ComboBoxMenu_1.ComboBoxMenu, null, filteredOptions.length > 0 && !enableVirtualization ? (filteredOptions.map(getMenuItem)) : (react_1.default.createElement(Menu_1.MenuExtraContent, null,
|
|
214
|
+
react_1.default.createElement(Typography_1.Text, { isMuted: true }, emptyStateMessage)))))))));
|
|
323
215
|
};
|
|
324
216
|
exports.ComboBox = ComboBox;
|
|
325
217
|
exports.default = exports.ComboBox;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PopoverProps } from '../utils';
|
|
3
|
+
declare type ComboBoxDropdownProps = PopoverProps & {
|
|
4
|
+
children: JSX.Element;
|
|
5
|
+
};
|
|
6
|
+
export declare const ComboBoxDropdown: React.ForwardRefExoticComponent<Pick<ComboBoxDropdownProps, "disabled" | "children" | "placement" | "trigger" | "visible" | "content" | "render" | "animateFill" | "appendTo" | "aria" | "delay" | "duration" | "followCursor" | "getReferenceClientRect" | "hideOnClick" | "ignoreAttributes" | "inlinePositioning" | "interactive" | "interactiveBorder" | "interactiveDebounce" | "moveTransition" | "offset" | "plugins" | "popperOptions" | "showOnCreate" | "sticky" | "touch" | "triggerTarget" | "onAfterUpdate" | "onBeforeUpdate" | "onCreate" | "onDestroy" | "onHidden" | "onHide" | "onMount" | "onShow" | "onShown" | "onTrigger" | "onUntrigger" | "onClickOutside" | "allowHTML" | "animation" | "arrow" | "inertia" | "maxWidth" | "role" | "theme" | "zIndex" | "className" | "singleton" | "reference"> & React.RefAttributes<Element>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.ComboBoxDropdown = void 0;
|
|
29
|
+
/*---------------------------------------------------------------------------------------------
|
|
30
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
31
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
32
|
+
*--------------------------------------------------------------------------------------------*/
|
|
33
|
+
var react_1 = __importDefault(require("react"));
|
|
34
|
+
var utils_1 = require("../utils");
|
|
35
|
+
var helpers_1 = require("./helpers");
|
|
36
|
+
exports.ComboBoxDropdown = react_1.default.forwardRef(function (props, forwardedRef) {
|
|
37
|
+
var children = props.children, rest = __rest(props, ["children"]);
|
|
38
|
+
var isOpen = (0, utils_1.useSafeContext)(helpers_1.ComboBoxStateContext).isOpen;
|
|
39
|
+
var dispatch = (0, utils_1.useSafeContext)(helpers_1.ComboBoxActionContext);
|
|
40
|
+
var _a = (0, utils_1.useSafeContext)(helpers_1.ComboBoxRefsContext), inputRef = _a.inputRef, toggleButtonRef = _a.toggleButtonRef;
|
|
41
|
+
// sync internal isOpen state with user's visible prop
|
|
42
|
+
react_1.default.useEffect(function () {
|
|
43
|
+
if (props.visible != undefined) {
|
|
44
|
+
dispatch([props.visible ? 'open' : 'close']);
|
|
45
|
+
}
|
|
46
|
+
}, [dispatch, props.visible]);
|
|
47
|
+
return (react_1.default.createElement(utils_1.Popover, __assign({ placement: 'bottom-start', visible: isOpen, onClickOutside: react_1.default.useCallback(function (_, _a) {
|
|
48
|
+
var _b;
|
|
49
|
+
var target = _a.target;
|
|
50
|
+
if (!((_b = toggleButtonRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
|
|
51
|
+
dispatch(['close']);
|
|
52
|
+
}
|
|
53
|
+
}, [dispatch, toggleButtonRef]), animation: 'shift-away', duration: 200, reference: inputRef, ref: forwardedRef, content: children }, rest)));
|
|
54
|
+
});
|
|
55
|
+
exports.ComboBoxDropdown.displayName = 'ComboBoxDropdown';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const ComboBoxEndIcon: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | keyof React.HTMLAttributes<HTMLSpanElement>> & {
|
|
3
|
+
disabled?: boolean | undefined;
|
|
4
|
+
isOpen?: boolean | undefined;
|
|
5
|
+
} & React.RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.ComboBoxEndIcon = void 0;
|
|
29
|
+
/*---------------------------------------------------------------------------------------------
|
|
30
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
31
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
32
|
+
*--------------------------------------------------------------------------------------------*/
|
|
33
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
34
|
+
var react_1 = __importDefault(require("react"));
|
|
35
|
+
var utils_1 = require("../utils");
|
|
36
|
+
var helpers_1 = require("./helpers");
|
|
37
|
+
var CaretDownSmall_1 = __importDefault(require("@itwin/itwinui-icons-react/cjs/icons/CaretDownSmall"));
|
|
38
|
+
exports.ComboBoxEndIcon = react_1.default.forwardRef(function (props, forwardedRef) {
|
|
39
|
+
var className = props.className, children = props.children, onClickProp = props.onClick, disabled = props.disabled, isOpen = props.isOpen, rest = __rest(props, ["className", "children", "onClick", "disabled", "isOpen"]);
|
|
40
|
+
var dispatch = (0, utils_1.useSafeContext)(helpers_1.ComboBoxActionContext);
|
|
41
|
+
var toggleButtonRef = (0, utils_1.useSafeContext)(helpers_1.ComboBoxRefsContext).toggleButtonRef;
|
|
42
|
+
var refs = (0, utils_1.useMergedRefs)(toggleButtonRef, forwardedRef);
|
|
43
|
+
return (react_1.default.createElement("span", __assign({ ref: refs, className: (0, classnames_1.default)('iui-end-icon', {
|
|
44
|
+
'iui-actionable': !disabled,
|
|
45
|
+
'iui-disabled': disabled,
|
|
46
|
+
'iui-open': isOpen,
|
|
47
|
+
}, className), onClick: function (e) {
|
|
48
|
+
onClickProp === null || onClickProp === void 0 ? void 0 : onClickProp(e);
|
|
49
|
+
if (!e.isDefaultPrevented()) {
|
|
50
|
+
dispatch([isOpen ? 'close' : 'open']);
|
|
51
|
+
}
|
|
52
|
+
} }, rest), children !== null && children !== void 0 ? children : react_1.default.createElement(CaretDownSmall_1.default, { "aria-hidden": true })));
|
|
53
|
+
});
|
|
54
|
+
exports.ComboBoxEndIcon.displayName = 'ComboBoxEndIcon';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const ComboBoxInput: React.ForwardRefExoticComponent<{
|
|
3
|
+
setFocus?: boolean | undefined;
|
|
4
|
+
size?: "small" | "large" | undefined;
|
|
5
|
+
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & React.RefAttributes<HTMLInputElement>>;
|