@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
|
@@ -17,5 +17,5 @@ export declare type ColorSwatchProps = {
|
|
|
17
17
|
* <ColorSwatch color='#23450b' onClick={onClick}/>
|
|
18
18
|
* <ColorSwatch color={{ r: 255, g: 255, b: 0 }} onClick={onClick}/>
|
|
19
19
|
*/
|
|
20
|
-
export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "aria-disabled" | "
|
|
20
|
+
export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "aria-disabled" | "children" | "role" | "className" | "onClick" | "accessKey" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "isActive"> & React.RefAttributes<HTMLDivElement>>;
|
|
21
21
|
export default ColorSwatch;
|
|
@@ -40,8 +40,10 @@ export declare type ComboBoxProps<T> = {
|
|
|
40
40
|
emptyStateMessage?: string;
|
|
41
41
|
/**
|
|
42
42
|
* A custom item renderer can be specified to control the rendering.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
*
|
|
44
|
+
* For keyboard navigation to work, the returned element should use the `id` provided by this function.
|
|
45
|
+
* The `isFocused` state is calculated using this `id` and can be used for specifying the focus styling.
|
|
46
|
+
* If a `MenuItem` is returned, then focus styling is automatically handled.
|
|
45
47
|
*/
|
|
46
48
|
itemRenderer?: (option: SelectOption<T>, states: {
|
|
47
49
|
isSelected: boolean;
|
|
@@ -49,6 +51,13 @@ export declare type ComboBoxProps<T> = {
|
|
|
49
51
|
id: string;
|
|
50
52
|
index: number;
|
|
51
53
|
}) => JSX.Element;
|
|
54
|
+
/**
|
|
55
|
+
* If enabled, virtualization is used for the scrollable dropdown list.
|
|
56
|
+
* Use it if you expect a very long list of items.
|
|
57
|
+
* @default false
|
|
58
|
+
* @beta
|
|
59
|
+
*/
|
|
60
|
+
enableVirtualization?: boolean;
|
|
52
61
|
} & Pick<InputContainerProps, 'status'> & Omit<CommonProps, 'title'>;
|
|
53
62
|
/**
|
|
54
63
|
* ComboBox component that allows typing a value to filter the options in dropdown list.
|
|
@@ -26,13 +26,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
*--------------------------------------------------------------------------------------------*/
|
|
27
27
|
import React from 'react';
|
|
28
28
|
import cx from 'classnames';
|
|
29
|
-
import {
|
|
30
|
-
import { Menu, MenuExtraContent, MenuItem } from '../Menu';
|
|
29
|
+
import { MenuExtraContent } from '../Menu';
|
|
31
30
|
import { Text } from '../Typography';
|
|
32
|
-
import {
|
|
33
|
-
import SvgCaretDownSmall from '@itwin/itwinui-icons-react/cjs/icons/CaretDownSmall';
|
|
31
|
+
import { useTheme, getRandomValue, mergeRefs, } from '../utils';
|
|
34
32
|
import 'tippy.js/animations/shift-away.css';
|
|
35
|
-
import {
|
|
33
|
+
import { ComboBoxActionContext, comboBoxReducer, ComboBoxRefsContext, ComboBoxStateContext, } from './helpers';
|
|
34
|
+
import { ComboBoxDropdown } from './ComboBoxDropdown';
|
|
35
|
+
import { ComboBoxEndIcon } from './ComboBoxEndIcon';
|
|
36
|
+
import { ComboBoxInput } from './ComboBoxInput';
|
|
37
|
+
import { ComboBoxInputContainer } from './ComboBoxInputContainer';
|
|
38
|
+
import { ComboBoxMenu } from './ComboBoxMenu';
|
|
39
|
+
import { ComboBoxMenuItem } from './ComboBoxMenuItem';
|
|
40
|
+
/** Returns either `option.id` or derives a stable id using `idPrefix` and `option.label` (without whitespace) */
|
|
41
|
+
var getOptionId = function (option, idPrefix) {
|
|
42
|
+
var _a;
|
|
43
|
+
return (_a = option.id) !== null && _a !== void 0 ? _a : "".concat(idPrefix, "-option-").concat(option.label.replace(/\s/g, '-'));
|
|
44
|
+
};
|
|
36
45
|
/**
|
|
37
46
|
* ComboBox component that allows typing a value to filter the options in dropdown list.
|
|
38
47
|
* Values can be selected either using mouse clicks or using the Enter key.
|
|
@@ -47,272 +56,155 @@ import { StatusMessage } from '../StatusMessage';
|
|
|
47
56
|
* />
|
|
48
57
|
*/
|
|
49
58
|
export var ComboBox = function (props) {
|
|
50
|
-
var
|
|
59
|
+
var _a;
|
|
60
|
+
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"]);
|
|
51
61
|
// Generate a stateful random id if not specified
|
|
52
62
|
var id = React.useState(function () {
|
|
53
63
|
var _a, _b;
|
|
54
64
|
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(getRandomValue(10));
|
|
55
65
|
})[0];
|
|
56
66
|
useTheme();
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}));
|
|
64
|
-
}, [options, id]);
|
|
65
|
-
var userOnChange = React.useRef(onChange);
|
|
67
|
+
// Refs get set in subcomponents
|
|
68
|
+
var inputRef = React.useRef(null);
|
|
69
|
+
var menuRef = React.useRef(null);
|
|
70
|
+
var toggleButtonRef = React.useRef(null);
|
|
71
|
+
// Latest value of the onChange prop
|
|
72
|
+
var onChangeProp = React.useRef(onChange);
|
|
66
73
|
React.useEffect(function () {
|
|
67
|
-
|
|
74
|
+
onChangeProp.current = onChange;
|
|
68
75
|
}, [onChange]);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
// Record to store all extra information (e.g. original indexes), where the key is the id of the option
|
|
77
|
+
var optionsExtraInfoRef = React.useRef({});
|
|
78
|
+
// Clear the extra info when the options change so that it can be reinitialized below
|
|
79
|
+
React.useEffect(function () {
|
|
80
|
+
optionsExtraInfoRef.current = {};
|
|
81
|
+
}, [options]);
|
|
82
|
+
// Initialize the extra info only if it is not already initialized
|
|
83
|
+
if (options.length > 0 &&
|
|
84
|
+
Object.keys(optionsExtraInfoRef.current).length === 0) {
|
|
85
|
+
options.forEach(function (option, index) {
|
|
86
|
+
optionsExtraInfoRef.current[getOptionId(option, id)] = {
|
|
87
|
+
__originalIndex: index,
|
|
81
88
|
};
|
|
82
|
-
if (itemRenderer) {
|
|
83
|
-
return React.cloneElement(itemRenderer(option, {
|
|
84
|
-
id: getOptionId(index),
|
|
85
|
-
index: index,
|
|
86
|
-
isSelected: false,
|
|
87
|
-
isFocused: false,
|
|
88
|
-
}), additionalProps);
|
|
89
|
-
}
|
|
90
|
-
return (React.createElement(MenuItem, __assign({ id: getOptionId(index), key: getOptionId(index) }, additionalProps, rest), label));
|
|
91
89
|
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
}
|
|
91
|
+
// Reducer where all the component-wide state is stored
|
|
92
|
+
var _d = React.useReducer(comboBoxReducer, {
|
|
93
|
+
isOpen: false,
|
|
94
|
+
selectedIndex: -1,
|
|
95
|
+
focusedIndex: -1,
|
|
96
|
+
}), _e = _d[0], isOpen = _e.isOpen, selectedIndex = _e.selectedIndex, focusedIndex = _e.focusedIndex, dispatch = _d[1];
|
|
97
|
+
React.useEffect(function () {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
// When the dropdown opens
|
|
100
|
+
if (isOpen) {
|
|
101
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); // Focus the input
|
|
102
|
+
setFilteredOptions(options); // Reset the filtered list
|
|
103
|
+
dispatch(['focus']);
|
|
104
|
+
}
|
|
105
|
+
// When the dropdown closes
|
|
106
|
+
else {
|
|
107
|
+
// Reset the focused index
|
|
108
|
+
dispatch(['focus']);
|
|
109
|
+
// Reset the input value
|
|
110
|
+
setInputValue(selectedIndex != undefined && selectedIndex >= 0
|
|
111
|
+
? (_b = options[selectedIndex]) === null || _b === void 0 ? void 0 : _b.label
|
|
112
|
+
: '');
|
|
113
|
+
}
|
|
114
|
+
}, [isOpen, options, selectedIndex]);
|
|
97
115
|
// Set min-width of menu to be same as input
|
|
98
|
-
var
|
|
116
|
+
var _f = React.useState(0), minWidth = _f[0], setMinWidth = _f[1];
|
|
99
117
|
React.useEffect(function () {
|
|
100
118
|
if (inputRef.current) {
|
|
101
119
|
setMinWidth(inputRef.current.offsetWidth);
|
|
102
120
|
}
|
|
103
121
|
}, [isOpen]);
|
|
104
|
-
|
|
122
|
+
// Initialize filtered options to the latest value options
|
|
123
|
+
var _g = React.useState(options), filteredOptions = _g[0], setFilteredOptions = _g[1];
|
|
105
124
|
React.useEffect(function () {
|
|
106
125
|
setFilteredOptions(options);
|
|
126
|
+
dispatch(['focus']);
|
|
107
127
|
}, [options]);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
(
|
|
122
|
-
}, [inputProps]);
|
|
123
|
-
//
|
|
128
|
+
// Filter options based on input value
|
|
129
|
+
var _h = React.useState((_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.value) !== null && _a !== void 0 ? _a : ''), inputValue = _h[0], setInputValue = _h[1];
|
|
130
|
+
var handleOnInput = React.useCallback(function (event) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
var value = event.currentTarget.value;
|
|
133
|
+
setInputValue(value);
|
|
134
|
+
dispatch(['open']); // reopen when typing
|
|
135
|
+
setFilteredOptions((_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, value)) !== null && _a !== void 0 ? _a : options.filter(function (option) {
|
|
136
|
+
return option.label.toLowerCase().includes(value.toLowerCase());
|
|
137
|
+
}));
|
|
138
|
+
if (focusedIndex != -1) {
|
|
139
|
+
dispatch(['focus', -1]);
|
|
140
|
+
}
|
|
141
|
+
(_b = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onChange) === null || _b === void 0 ? void 0 : _b.call(inputProps, event);
|
|
142
|
+
}, [filterFunction, focusedIndex, inputProps, options]);
|
|
143
|
+
// When the value prop changes, update the selectedIndex
|
|
124
144
|
React.useEffect(function () {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
setFocusedIndex(selectedOption ? options.indexOf(selectedOption) : -1);
|
|
132
|
-
}, [selectedValue, options]);
|
|
133
|
-
// Filter options and update focus when input value changes
|
|
145
|
+
dispatch([
|
|
146
|
+
'select',
|
|
147
|
+
options.findIndex(function (option) { return option.value === valueProp; }),
|
|
148
|
+
]);
|
|
149
|
+
}, [options, valueProp]);
|
|
150
|
+
// Call user-defined onChange when the value actually changes
|
|
134
151
|
React.useEffect(function () {
|
|
135
|
-
var _a;
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
var selectedOption = options.find(function (_a) {
|
|
141
|
-
var value = _a.value;
|
|
142
|
-
return value === selectedValue;
|
|
143
|
-
});
|
|
144
|
-
if (!inputValue || (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) === inputValue) {
|
|
145
|
-
setFilteredOptions(options);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
var _filteredOptions = (_a = filterFunction === null || filterFunction === void 0 ? void 0 : filterFunction(options, inputValue)) !== null && _a !== void 0 ? _a : options.filter(function (option) {
|
|
149
|
-
return option.label.toLowerCase().includes(inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase());
|
|
150
|
-
});
|
|
151
|
-
setFilteredOptions(_filteredOptions);
|
|
152
|
-
setFocusedIndex(function (previouslyFocusedIndex) {
|
|
153
|
-
if (_filteredOptions.includes(options[previouslyFocusedIndex])) {
|
|
154
|
-
return previouslyFocusedIndex;
|
|
155
|
-
}
|
|
156
|
-
else if (_filteredOptions.find(function (_a) {
|
|
157
|
-
var value = _a.value;
|
|
158
|
-
return value === selectedValue;
|
|
159
|
-
})) {
|
|
160
|
-
return options.findIndex(function (_a) {
|
|
161
|
-
var value = _a.value;
|
|
162
|
-
return value === selectedValue;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
return -1; // reset focus if previously focused or selected value is not in filtered list
|
|
152
|
+
var _a, _b;
|
|
153
|
+
if (selectedIndex != undefined && selectedIndex >= 0) {
|
|
154
|
+
var value = (_a = options[selectedIndex]) === null || _a === void 0 ? void 0 : _a.value;
|
|
155
|
+
if (value === valueProp) {
|
|
156
|
+
return;
|
|
167
157
|
}
|
|
168
|
-
|
|
169
|
-
}, [inputValue, options, selectedValue, isOpen, filterFunction]);
|
|
170
|
-
var onKeyDown = React.useCallback(function (event) {
|
|
171
|
-
var _a;
|
|
172
|
-
var focusableOptions = getFocusableElements(menuRef.current);
|
|
173
|
-
var focusedIndexInFilteredList = focusableOptions.findIndex(function (_a) {
|
|
174
|
-
var _b;
|
|
175
|
-
var id = _a.id;
|
|
176
|
-
return id === ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.getAttribute('aria-activedescendant'));
|
|
177
|
-
});
|
|
178
|
-
switch (event.key) {
|
|
179
|
-
case 'ArrowDown':
|
|
180
|
-
if (isOpen) {
|
|
181
|
-
var nextIndex_1 = Math.min(focusedIndexInFilteredList + 1, focusableOptions.length - 1);
|
|
182
|
-
setFocusedIndex(options.findIndex(function (_, index) {
|
|
183
|
-
return getOptionId(index) === focusableOptions[nextIndex_1].id;
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
setIsOpen(true); // reopen menu if closed when typing
|
|
188
|
-
}
|
|
189
|
-
event.preventDefault();
|
|
190
|
-
event.stopPropagation();
|
|
191
|
-
break;
|
|
192
|
-
case 'ArrowUp':
|
|
193
|
-
if (isOpen) {
|
|
194
|
-
var previousIndex_1 = Math.max(focusedIndexInFilteredList - 1, 0);
|
|
195
|
-
setFocusedIndex(options.findIndex(function (_, index) {
|
|
196
|
-
return getOptionId(index) === focusableOptions[previousIndex_1].id;
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
event.preventDefault();
|
|
200
|
-
event.stopPropagation();
|
|
201
|
-
break;
|
|
202
|
-
case 'Enter':
|
|
203
|
-
if (isOpen) {
|
|
204
|
-
setSelectedValue(options[focusedIndex].value);
|
|
205
|
-
(_a = userOnChange.current) === null || _a === void 0 ? void 0 : _a.call(userOnChange, options[focusedIndex].value);
|
|
206
|
-
}
|
|
207
|
-
setIsOpen(function (open) { return !open; });
|
|
208
|
-
event.preventDefault();
|
|
209
|
-
event.stopPropagation();
|
|
210
|
-
break;
|
|
211
|
-
case 'Escape':
|
|
212
|
-
setIsOpen(false);
|
|
213
|
-
event.preventDefault();
|
|
214
|
-
event.stopPropagation();
|
|
215
|
-
break;
|
|
216
|
-
case 'Tab':
|
|
217
|
-
setIsOpen(false);
|
|
218
|
-
break;
|
|
219
|
-
default:
|
|
220
|
-
if (!isOpen) {
|
|
221
|
-
setIsOpen(true); // reopen menu if closed when typing
|
|
222
|
-
}
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
}, [focusedIndex, isOpen, options, getOptionId]);
|
|
226
|
-
var menuItems = React.useMemo(function () {
|
|
227
|
-
if (filteredOptions.length === 0) {
|
|
228
|
-
return [
|
|
229
|
-
React.createElement(MenuExtraContent, { key: 0 },
|
|
230
|
-
React.createElement(Text, { isMuted: true }, emptyStateMessage)),
|
|
231
|
-
];
|
|
158
|
+
(_b = onChangeProp.current) === null || _b === void 0 ? void 0 : _b.call(onChangeProp, value);
|
|
232
159
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
return (React.createElement(InputContainer, __assign({ className: className, status: status, statusMessage: typeof message === 'string' ? (React.createElement(StatusMessage, { status: status }, message)) : (React.isValidElement(message) &&
|
|
276
|
-
React.cloneElement(message, { status: status })) }, rest, { id: id }),
|
|
277
|
-
React.createElement("div", { className: 'iui-input-with-icon' },
|
|
278
|
-
React.createElement(Popover, __assign({ placement: 'bottom-start', visible: isOpen, onClickOutside: function (_, _a) {
|
|
279
|
-
var _b;
|
|
280
|
-
var target = _a.target;
|
|
281
|
-
if (!((_b = toggleButtonRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
|
|
282
|
-
setIsOpen(false);
|
|
283
|
-
}
|
|
284
|
-
}, animation: 'shift-away', duration: 200 }, dropdownMenuProps, { content: React.createElement(Menu, { id: "".concat(id, "-list"), className: 'iui-scroll', style: {
|
|
285
|
-
minWidth: minWidth,
|
|
286
|
-
maxWidth: "min(".concat(minWidth * 2, "px, 90vw)"),
|
|
287
|
-
maxHeight: 300,
|
|
288
|
-
}, setFocus: false, role: 'listbox', ref: menuRef }, menuItems), onHide: function (instance) {
|
|
289
|
-
var _a;
|
|
290
|
-
var selectedIndex = options.findIndex(function (_a) {
|
|
291
|
-
var value = _a.value;
|
|
292
|
-
return value === selectedValue;
|
|
293
|
-
});
|
|
294
|
-
setFocusedIndex(selectedIndex);
|
|
295
|
-
if (selectedIndex > -1) {
|
|
296
|
-
setInputValue(options[selectedIndex].label); // update input value to be same as selected value
|
|
297
|
-
}
|
|
298
|
-
(_a = dropdownMenuProps === null || dropdownMenuProps === void 0 ? void 0 : dropdownMenuProps.onHide) === null || _a === void 0 ? void 0 : _a.call(dropdownMenuProps, instance);
|
|
299
|
-
} }),
|
|
300
|
-
React.createElement(Input, __assign({ ref: inputRef, onKeyDown: onKeyDown, onFocus: function () { return setIsOpen(true); }, value: inputValue, "aria-activedescendant": isOpen && focusedIndex > -1
|
|
301
|
-
? getOptionId(focusedIndex)
|
|
302
|
-
: undefined, role: 'combobox', "aria-controls": isOpen ? "".concat(id, "-list") : undefined, "aria-autocomplete": 'list', spellCheck: false, autoCapitalize: 'none', autoCorrect: 'off' }, inputProps, { onChange: onInput }))),
|
|
303
|
-
React.createElement("span", { ref: toggleButtonRef, className: cx('iui-end-icon', {
|
|
304
|
-
'iui-actionable': !(inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled),
|
|
305
|
-
'iui-disabled': inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled,
|
|
306
|
-
'iui-open': isOpen,
|
|
307
|
-
}), onClick: function () {
|
|
308
|
-
var _a;
|
|
309
|
-
if (isOpen) {
|
|
310
|
-
setIsOpen(false);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
314
|
-
}
|
|
160
|
+
}, [options, selectedIndex, valueProp]);
|
|
161
|
+
var getMenuItem = React.useCallback(function (option, filteredIndex) {
|
|
162
|
+
var optionId = getOptionId(option, id);
|
|
163
|
+
var __originalIndex = optionsExtraInfoRef.current[optionId].__originalIndex;
|
|
164
|
+
var customItem = itemRenderer
|
|
165
|
+
? itemRenderer(option, {
|
|
166
|
+
isFocused: focusedIndex === __originalIndex,
|
|
167
|
+
isSelected: selectedIndex === __originalIndex,
|
|
168
|
+
index: __originalIndex,
|
|
169
|
+
id: optionId,
|
|
170
|
+
})
|
|
171
|
+
: null;
|
|
172
|
+
return customItem ? (React.cloneElement(customItem, {
|
|
173
|
+
onClick: function (e) {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
dispatch(['select', __originalIndex]);
|
|
176
|
+
(_b = (_a = customItem.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
177
|
+
},
|
|
178
|
+
// ComboBox.MenuItem handles scrollIntoView, data-iui-index and iui-focused through context
|
|
179
|
+
// but we still need to pass them here for backwards compatibility with MenuItem
|
|
180
|
+
className: cx(customItem.props.className, {
|
|
181
|
+
'iui-focused': focusedIndex === __originalIndex,
|
|
182
|
+
}),
|
|
183
|
+
'data-iui-index': __originalIndex,
|
|
184
|
+
'data-iui-filtered-index': filteredIndex,
|
|
185
|
+
ref: mergeRefs(customItem.props.ref, function (el) {
|
|
186
|
+
if (!enableVirtualization && focusedIndex === __originalIndex) {
|
|
187
|
+
el === null || el === void 0 ? void 0 : el.scrollIntoView({ block: 'nearest' });
|
|
188
|
+
}
|
|
189
|
+
}),
|
|
190
|
+
})) : (React.createElement(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));
|
|
191
|
+
}, [enableVirtualization, focusedIndex, id, itemRenderer, selectedIndex]);
|
|
192
|
+
return (React.createElement(ComboBoxRefsContext.Provider, { value: { inputRef: inputRef, menuRef: menuRef, toggleButtonRef: toggleButtonRef, optionsExtraInfoRef: optionsExtraInfoRef } },
|
|
193
|
+
React.createElement(ComboBoxActionContext.Provider, { value: dispatch },
|
|
194
|
+
React.createElement(ComboBoxStateContext.Provider, { value: {
|
|
195
|
+
id: id,
|
|
196
|
+
minWidth: minWidth,
|
|
197
|
+
isOpen: isOpen,
|
|
198
|
+
focusedIndex: focusedIndex,
|
|
199
|
+
enableVirtualization: enableVirtualization,
|
|
200
|
+
filteredOptions: filteredOptions,
|
|
201
|
+
getMenuItem: getMenuItem,
|
|
315
202
|
} },
|
|
316
|
-
React.createElement(
|
|
203
|
+
React.createElement(ComboBoxInputContainer, __assign({ disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled }, rest),
|
|
204
|
+
React.createElement(ComboBoxInput, __assign({ value: inputValue }, inputProps, { onChange: handleOnInput })),
|
|
205
|
+
React.createElement(ComboBoxEndIcon, { disabled: inputProps === null || inputProps === void 0 ? void 0 : inputProps.disabled, isOpen: isOpen })),
|
|
206
|
+
React.createElement(ComboBoxDropdown, __assign({}, dropdownMenuProps),
|
|
207
|
+
React.createElement(ComboBoxMenu, null, filteredOptions.length > 0 && !enableVirtualization ? (filteredOptions.map(getMenuItem)) : (React.createElement(MenuExtraContent, null,
|
|
208
|
+
React.createElement(Text, { isMuted: true }, emptyStateMessage)))))))));
|
|
317
209
|
};
|
|
318
210
|
export default 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,49 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
/*---------------------------------------------------------------------------------------------
|
|
24
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
|
+
*--------------------------------------------------------------------------------------------*/
|
|
27
|
+
import React from 'react';
|
|
28
|
+
import { Popover, useSafeContext } from '../utils';
|
|
29
|
+
import { ComboBoxStateContext, ComboBoxActionContext, ComboBoxRefsContext, } from './helpers';
|
|
30
|
+
export var ComboBoxDropdown = React.forwardRef(function (props, forwardedRef) {
|
|
31
|
+
var children = props.children, rest = __rest(props, ["children"]);
|
|
32
|
+
var isOpen = useSafeContext(ComboBoxStateContext).isOpen;
|
|
33
|
+
var dispatch = useSafeContext(ComboBoxActionContext);
|
|
34
|
+
var _a = useSafeContext(ComboBoxRefsContext), inputRef = _a.inputRef, toggleButtonRef = _a.toggleButtonRef;
|
|
35
|
+
// sync internal isOpen state with user's visible prop
|
|
36
|
+
React.useEffect(function () {
|
|
37
|
+
if (props.visible != undefined) {
|
|
38
|
+
dispatch([props.visible ? 'open' : 'close']);
|
|
39
|
+
}
|
|
40
|
+
}, [dispatch, props.visible]);
|
|
41
|
+
return (React.createElement(Popover, __assign({ placement: 'bottom-start', visible: isOpen, onClickOutside: React.useCallback(function (_, _a) {
|
|
42
|
+
var _b;
|
|
43
|
+
var target = _a.target;
|
|
44
|
+
if (!((_b = toggleButtonRef.current) === null || _b === void 0 ? void 0 : _b.contains(target))) {
|
|
45
|
+
dispatch(['close']);
|
|
46
|
+
}
|
|
47
|
+
}, [dispatch, toggleButtonRef]), animation: 'shift-away', duration: 200, reference: inputRef, ref: forwardedRef, content: children }, rest)));
|
|
48
|
+
});
|
|
49
|
+
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,48 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
/*---------------------------------------------------------------------------------------------
|
|
24
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
|
+
*--------------------------------------------------------------------------------------------*/
|
|
27
|
+
import cx from 'classnames';
|
|
28
|
+
import React from 'react';
|
|
29
|
+
import { useSafeContext, useMergedRefs } from '../utils';
|
|
30
|
+
import { ComboBoxActionContext, ComboBoxRefsContext } from './helpers';
|
|
31
|
+
import SvgCaretDownSmall from '@itwin/itwinui-icons-react/cjs/icons/CaretDownSmall';
|
|
32
|
+
export var ComboBoxEndIcon = React.forwardRef(function (props, forwardedRef) {
|
|
33
|
+
var className = props.className, children = props.children, onClickProp = props.onClick, disabled = props.disabled, isOpen = props.isOpen, rest = __rest(props, ["className", "children", "onClick", "disabled", "isOpen"]);
|
|
34
|
+
var dispatch = useSafeContext(ComboBoxActionContext);
|
|
35
|
+
var toggleButtonRef = useSafeContext(ComboBoxRefsContext).toggleButtonRef;
|
|
36
|
+
var refs = useMergedRefs(toggleButtonRef, forwardedRef);
|
|
37
|
+
return (React.createElement("span", __assign({ ref: refs, className: cx('iui-end-icon', {
|
|
38
|
+
'iui-actionable': !disabled,
|
|
39
|
+
'iui-disabled': disabled,
|
|
40
|
+
'iui-open': isOpen,
|
|
41
|
+
}, className), onClick: function (e) {
|
|
42
|
+
onClickProp === null || onClickProp === void 0 ? void 0 : onClickProp(e);
|
|
43
|
+
if (!e.isDefaultPrevented()) {
|
|
44
|
+
dispatch([isOpen ? 'close' : 'open']);
|
|
45
|
+
}
|
|
46
|
+
} }, rest), children !== null && children !== void 0 ? children : React.createElement(SvgCaretDownSmall, { "aria-hidden": true })));
|
|
47
|
+
});
|
|
48
|
+
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>>;
|