@ringcentral/spring-ui 1.11.2 → 1.13.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/Accordion.js +90 -34
- package/AccordionHeader.js +72 -20
- package/Alert.js +120 -28
- package/Animation.js +2 -45
- package/Announcement.js +46 -35
- package/Autocomplete.js +1011 -580
- package/Avatar.js +134 -73
- package/AvatarGroup.js +50 -7
- package/Backdrop.js +45 -7
- package/Badge.js +77 -15
- package/Block.js +34 -12
- package/BlockHeader.js +55 -11
- package/BottomNavigation.js +181 -65
- package/BottomNavigationItem.js +93 -30
- package/Button.js +160 -24
- package/CallButton.js +53 -31
- package/Checkbox.js +88 -26
- package/Chip.js +126 -26
- package/CircularProgressIndicator.js +80 -8
- package/ClickAwayListener.js +4 -1
- package/ComponentsProps.js +1 -0
- package/DatePicker.js +611 -190
- package/DateUtilsContext.js +43 -25
- package/Dialer.js +576 -250
- package/Dialog.js +100 -45
- package/Divider.js +43 -7
- package/DragHandle.js +32 -6
- package/Drawer.js +117 -19
- package/Dropdown.js +154 -74
- package/EmptyState.js +63 -11
- package/FabButton.js +51 -17
- package/FocusTrap.js +109 -12
- package/FormField.js +106 -8
- package/FormLabel.js +81 -7
- package/Icon.js +1 -8
- package/IconButton.js +142 -26
- package/IconButtonGroup.js +35 -12
- package/InlineEditable.js +98 -44
- package/LinearProgressIndicator.js +73 -24
- package/Link.js +40 -11
- package/List.js +54 -9
- package/ListItem.js +152 -23
- package/ListItemText.js +44 -16
- package/ListNavigation.js +272 -20
- package/Menu.js +139 -23
- package/MenuActions.js +37 -12
- package/MenuDivider.js +34 -8
- package/MenuFooter.js +36 -12
- package/MenuHeader.js +54 -15
- package/MenuItem.js +402 -33
- package/MenuItemText.js +51 -8
- package/MenuList.js +87 -34
- package/Modal.js +345 -16
- package/NestedMenuContext.js +183 -11
- package/Option.js +32 -34
- package/Overlap.js +54 -7
- package/PageHeader.js +62 -24
- package/PickerTextField.js +156 -33
- package/Popover.js +262 -21
- package/Popper.js +130 -77
- package/PopperPaper.js +54 -8
- package/Portal.js +6 -1
- package/Radio.js +65 -21
- package/RadioGroup.js +56 -17
- package/Rating.js +223 -87
- package/Select.js +387 -41
- package/SingleFilter.js +148 -77
- package/Skeleton.js +68 -17
- package/Slider.js +168 -69
- package/Snackbar.js +122 -59
- package/SortableList.js +32 -12
- package/SortableListDndContext.js +69 -22
- package/SortableListItem.js +92 -47
- package/SortableVirtualizedList.js +52 -28
- package/SplitButton.js +124 -86
- package/Squircle.js +4 -7
- package/StatusIndicator.js +51 -9
- package/Step.js +63 -38
- package/StepButton.js +51 -23
- package/StepConnector.js +48 -8
- package/StepContent.js +68 -25
- package/StepIcon.js +90 -9
- package/StepLabel.js +90 -14
- package/Stepper.js +65 -23
- package/SubMenu.js +203 -99
- package/SwipeableDrawer.js +439 -194
- package/Switch.js +70 -23
- package/Tab.js +120 -57
- package/TabContext.js +59 -15
- package/TabPanel.js +40 -13
- package/Table.js +60 -17
- package/TableBody.js +42 -12
- package/TableCell.js +84 -50
- package/TableContainer.js +32 -10
- package/TableFooter.js +38 -10
- package/TableHead.js +49 -15
- package/TablePagination.js +153 -77
- package/TableRow.js +60 -21
- package/Tabs.js +593 -268
- package/Tag.js +51 -16
- package/Text.js +68 -37
- package/TextField.js +209 -29
- package/Textarea.js +51 -40
- package/TimePicker.js +490 -230
- package/Tooltip.js +48 -23
- package/Tray.js +237 -13
- package/TrayMenu.js +62 -41
- package/VirtualizedList.js +208 -109
- package/VirtualizedMenu.js +359 -29
- package/VisuallyHidden.js +29 -6
- package/chunks/1250.js +98 -0
- package/chunks/1294.js +126 -0
- package/chunks/2956.js +18 -0
- package/chunks/4476.js +460 -0
- package/chunks/4491.js +10 -0
- package/chunks/4535.js +364 -0
- package/chunks/5047.js +3 -0
- package/chunks/6335.js +24 -0
- package/chunks/7279.js +10 -0
- package/chunks/8011.js +8 -0
- package/chunks/8307.js +56 -0
- package/chunks/8467.js +8 -0
- package/chunks/8809.js +8 -0
- package/chunks/{RadioGroup.context.js → 9551.js} +12 -6
- package/chunks/987.js +8 -0
- package/index.css +2624 -2416
- package/index.js +245 -193
- package/internal/utils/index.d.ts +1 -0
- package/internal/utils/setRef.d.ts +2 -0
- package/package.json +8 -8
- package/src/Alert/Alert.type.d.ts +2 -1
- package/src/Animation/components/Fade/Fade.d.ts +4 -2
- package/src/Animation/components/Grow/Grow.d.ts +4 -2
- package/src/Animation/components/ShowHideEye/ShowHideEye.d.ts +1 -1
- package/src/Animation/components/SlideIn/SlideIn.d.ts +4 -2
- package/src/Animation/components/SlideIn/getSlideIn.d.ts +1 -1
- package/src/Animation/hooks/useMotionSafeTransition/useMotionSafeTransition.d.ts +2 -0
- package/src/Autocomplete/SuggestionList/SuggestionList.d.ts +1 -1
- package/src/Autocomplete/useAutocomplete.d.ts +18 -18
- package/src/Autocomplete/useAutocompleteTag.d.ts +18 -18
- package/src/Badge/Badge.d.ts +2 -1
- package/src/Button/Button.classes.d.ts +1 -1
- package/src/ComponentsProps.d.ts +111 -110
- package/src/DatePicker/DatePickerDataAttributes.d.ts +11 -0
- package/src/DatePicker/utils/DatePickerAriaLabelUtils.d.ts +2 -1
- package/src/DatePicker/utils/DatePickerUtils.d.ts +1 -1
- package/src/Dialer/DialDelete/DialDelete.d.ts +2 -2
- package/src/Dialer/DialPad/DialPad.d.ts +2 -2
- package/src/Dialer/Dialer.d.ts +4 -2
- package/src/Dropdown/Dropdown.type.d.ts +2 -2
- package/src/InlineEditable/InlineEditable.type.d.ts +2 -1
- package/src/ListNavigation/useListNavigation.d.ts +3 -3
- package/src/MenuActions/MenuActions.d.ts +2 -2
- package/src/MenuItem/MenuItem.type.d.ts +1 -0
- package/src/MenuItem/useMenuItem.d.ts +1 -1
- package/src/MenuItem/useVirtualizedMenuItem.d.ts +1 -1
- package/src/MenuList/MenuList.type.d.ts +1 -1
- package/src/MenuList/MenuListContext.d.ts +2 -3
- package/src/Modal/Modal.type.d.ts +1 -0
- package/src/NestedMenuContext/MenuOverlayGroupContext.d.ts +2 -2
- package/src/Popover/Popover.classes.d.ts +1 -1
- package/src/Popover/Popover.internal.d.ts +8 -0
- package/src/Popover/Popover.type.d.ts +1 -0
- package/src/Popper/Popper.type.d.ts +10 -7
- package/src/Rating/utils.d.ts +3 -2
- package/src/Select/Select.type.d.ts +7 -5
- package/src/Slider/Slider.d.ts +2 -2
- package/src/Slider/SliderThumb.d.ts +2 -1
- package/src/Squircle/Squircle.d.ts +1 -1
- package/src/StatusIndicator/StatusIndicator.d.ts +2 -1
- package/src/SubMenu/PopperMenu.type.d.ts +4 -1
- package/src/Table/Table.type.d.ts +3 -0
- package/src/Table/TableContext.d.ts +3 -0
- package/src/Table/TableRowContext.d.ts +7 -0
- package/src/Table/index.d.ts +1 -0
- package/src/TableCell/TableCell.classes.d.ts +1 -1
- package/src/TableFooter/TableFooter.classes.d.ts +1 -1
- package/src/TableFooter/TableFooter.type.d.ts +1 -0
- package/src/TableHead/TableHead.classes.d.ts +1 -1
- package/src/TableHead/TableHead.type.d.ts +1 -0
- package/src/TableRow/TableRow.type.d.ts +2 -0
- package/chunks/AccordionContext.js +0 -6
- package/chunks/Alert.js +0 -48
- package/chunks/AvatarGroup.js +0 -22
- package/chunks/Backdrop.js +0 -18
- package/chunks/Badge.js +0 -32
- package/chunks/BottomNavigationItem.js +0 -36
- package/chunks/Button.js +0 -88
- package/chunks/Chip.js +0 -73
- package/chunks/CircularProgressIndicator.js +0 -36
- package/chunks/Divider.js +0 -19
- package/chunks/DragHandle.js +0 -11
- package/chunks/Drawer.js +0 -32
- package/chunks/ExpandCollapseCaret.js +0 -24
- package/chunks/FormLabel.js +0 -27
- package/chunks/Icon.js +0 -25
- package/chunks/IconButtonLabel.js +0 -68
- package/chunks/List.js +0 -22
- package/chunks/ListItem.js +0 -83
- package/chunks/Menu.js +0 -61
- package/chunks/MenuDivider.js +0 -14
- package/chunks/MenuItemText.js +0 -17
- package/chunks/MenuList.js +0 -46
- package/chunks/Modal.js +0 -212
- package/chunks/Overlap.js +0 -25
- package/chunks/PickerTextField.js +0 -85
- package/chunks/Popover.js +0 -53
- package/chunks/PopperPaper.js +0 -15
- package/chunks/Select.js +0 -220
- package/chunks/ShowHideEye.js +0 -56
- package/chunks/SlideIn.js +0 -19
- package/chunks/SortableArrow.js +0 -73
- package/chunks/Squircle.js +0 -31
- package/chunks/StatusIndicator.js +0 -20
- package/chunks/StepConnector.js +0 -21
- package/chunks/StepIcon.js +0 -43
- package/chunks/StepLabel.js +0 -29
- package/chunks/StepperContext.js +0 -9
- package/chunks/TableContext.js +0 -6
- package/chunks/Tablelvl2Context.js +0 -6
- package/chunks/TabsContext.js +0 -6
- package/chunks/TextField.js +0 -110
- package/chunks/Tooltip.js +0 -217
- package/chunks/VirtualizedMenu.js +0 -164
- package/chunks/VisuallyHidden.js +0 -12
- package/chunks/getFade.js +0 -27
- package/chunks/getGrow.js +0 -70
- package/chunks/getSlideIn.js +0 -30
- package/chunks/hasContent.js +0 -3
- package/chunks/useAnimationFrame.js +0 -15
- package/chunks/useFocusTrapStack.js +0 -36
- package/chunks/useHelperTextId.js +0 -22
- package/chunks/useListNavigation.js +0 -199
- package/chunks/useMenuItemSelect.js +0 -273
- package/chunks/useMotionSafeTransition.js +0 -9
- package/chunks/useNestedMenuItem.js +0 -27
- package/chunks/useNestedParentMenu.js +0 -113
- package/chunks/usePrefersReducedMotion.js +0 -36
- package/chunks/useTooltipForceHide.js +0 -27
- package/chunks/useTrayNavigate.js +0 -150
- package/chunks/withTooltip.js +0 -15
package/Select.js
CHANGED
|
@@ -1,41 +1,387 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { combineClasses, combineProps, getTitle, useClasses, useControlled, useEventCallback, useId } from "@ringcentral/spring-base";
|
|
4
|
+
import { useThemeProps } from "@ringcentral/spring-theme";
|
|
5
|
+
import { getGrow } from "./chunks/4476.js";
|
|
6
|
+
import { useHelperTextId, FormField as FormField_FormField } from "./FormField.js";
|
|
7
|
+
import { Menu as Menu_Menu, MenuContext } from "./Menu.js";
|
|
8
|
+
import { MenuItemSelectContext, useMenuItemSelect } from "./MenuItem.js";
|
|
9
|
+
import { MenuList as MenuList_MenuList } from "./MenuList.js";
|
|
10
|
+
import "./Squircle.js";
|
|
11
|
+
import { VirtualizedMenu as VirtualizedMenu_VirtualizedMenu } from "./VirtualizedMenu.js";
|
|
12
|
+
import { hasContent } from "./chunks/5047.js";
|
|
13
|
+
import { usePrefersReducedMotion, ExpandCollapseCaret as ExpandCollapseCaret_ExpandCollapseCaret } from "./chunks/1294.js";
|
|
14
|
+
import { Squircle as Squircle_Squircle } from "./chunks/1250.js";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// extracted by css-extract-rspack-plugin
|
|
21
|
+
/* export default */ var Select = ({"sui-select-chevron":"sui-select-chevron","sui-select-placeholder":"sui-select-placeholder","sui-select-value":"sui-select-value","sui-select-error":"sui-select-error","sui-select-selector":"sui-select-selector","sui-select-menu":"sui-select-menu","sui-select-native-input":"sui-select-native-input","sui-select-content":"sui-select-content","sui-select-outlined-selector-xlarge":"sui-select-outlined-selector-xlarge","sui-select-contained-selector-xlarge":"sui-select-contained-selector-xlarge","sui-select-outlined-selector-large":"sui-select-outlined-selector-large","sui-select-contained-selector-large":"sui-select-contained-selector-large","sui-select-outlined-selector-medium":"sui-select-outlined-selector-medium","sui-select-contained-selector-medium":"sui-select-contained-selector-medium","sui-select-outlined-selector":"sui-select-outlined-selector","sui-select-contained-selector":"sui-select-contained-selector","sui-expanded":"sui-expanded","sui-select-standard-selector":"sui-select-standard-selector","sui-select-root":"sui-select-root","sui-disabled":"sui-disabled"});
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const useSelect = (props)=>{
|
|
25
|
+
const { open, handleOpen } = props;
|
|
26
|
+
const getButtonProps = (otherHandlers = {})=>{
|
|
27
|
+
const eventHandlers = combineProps({
|
|
28
|
+
onClick: ()=>{
|
|
29
|
+
handleOpen(!open);
|
|
30
|
+
},
|
|
31
|
+
onKeyDown: (e)=>{
|
|
32
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
33
|
+
// prevent scroll
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
handleOpen(true);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, otherHandlers);
|
|
39
|
+
return {
|
|
40
|
+
'aria-expanded': open,
|
|
41
|
+
'aria-haspopup': 'listbox',
|
|
42
|
+
...eventHandlers
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const getListboxProps = ()=>({
|
|
46
|
+
role: 'listbox'
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
getButtonProps,
|
|
50
|
+
getListboxProps
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const DEFAULT_PLACEMENT = 'bottom';
|
|
69
|
+
const Select_Select = /*#__PURE__*/ forwardRef((inProps, ref)=>{
|
|
70
|
+
const props = useThemeProps({
|
|
71
|
+
props: inProps,
|
|
72
|
+
name: 'Select'
|
|
73
|
+
});
|
|
74
|
+
const { classes, className, children, name, id: idProp, value: valueProp, selectMode = 'single', defaultValue = selectMode === 'multiple' ? [] : null, onChange: onChangeProp, renderValue = (value)=>Array.isArray(value) ? value.join(', ') : String(value), label, helperText, disabled, required, error, displayEmpty, placeholder, open: openProp, defaultOpen, onOpen, onClose, selectorProps: selectorPropsProp, MenuProps, variant = 'standard', inputProps, size = 'xlarge', virtualize = false, VirtualizedMenuProps: virtualizedMenuPropsProp, data, getSelectedIndex, FormHelperTextProps, ...rest } = props;
|
|
75
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
76
|
+
const [open, setOpen] = useControlled({
|
|
77
|
+
controlled: openProp,
|
|
78
|
+
default: defaultOpen,
|
|
79
|
+
name: 'SuiSelect',
|
|
80
|
+
state: 'open'
|
|
81
|
+
});
|
|
82
|
+
const [didMenuExit, setDidMenuExit] = useState(!open);
|
|
83
|
+
const inputRef = useRef(null);
|
|
84
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
85
|
+
const cls = useClasses('select', classes, className);
|
|
86
|
+
const id = useId(idProp);
|
|
87
|
+
const helperTextId = useHelperTextId({
|
|
88
|
+
helperText,
|
|
89
|
+
id,
|
|
90
|
+
FormHelperTextProps
|
|
91
|
+
});
|
|
92
|
+
const formFieldContentRef = useRef(null);
|
|
93
|
+
useEffect(()=>{
|
|
94
|
+
setAnchorEl(formFieldContentRef.current);
|
|
95
|
+
}, []);
|
|
96
|
+
const handleOpen = useEventCallback((newOpen)=>{
|
|
97
|
+
if (disabled && newOpen) return;
|
|
98
|
+
if (newOpen) setDidMenuExit(false);
|
|
99
|
+
setOpen(newOpen);
|
|
100
|
+
if (newOpen) {
|
|
101
|
+
onOpen?.();
|
|
102
|
+
} else {
|
|
103
|
+
onClose?.();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
useEffect(()=>{
|
|
107
|
+
// close menu when disabled
|
|
108
|
+
if (disabled) {
|
|
109
|
+
handleOpen(false);
|
|
110
|
+
}
|
|
111
|
+
}, [
|
|
112
|
+
disabled,
|
|
113
|
+
handleOpen
|
|
114
|
+
]);
|
|
115
|
+
const [value, setValue] = useControlled({
|
|
116
|
+
controlled: valueProp,
|
|
117
|
+
default: defaultValue,
|
|
118
|
+
name: 'SuiSelect',
|
|
119
|
+
state: 'value'
|
|
120
|
+
});
|
|
121
|
+
const handleInputChange = useEventCallback((e)=>{
|
|
122
|
+
// TODO(next-major): Remove the legacy second onChange argument.
|
|
123
|
+
onChangeProp?.(e, inputRef.current);
|
|
124
|
+
});
|
|
125
|
+
const handleClose = useEventCallback(()=>{
|
|
126
|
+
handleOpen(false);
|
|
127
|
+
});
|
|
128
|
+
const handleInitialFocus = useEventCallback(()=>{
|
|
129
|
+
if (data && value !== null) {
|
|
130
|
+
if (getSelectedIndex) return getSelectedIndex(value);
|
|
131
|
+
if (Array.isArray(value)) {
|
|
132
|
+
// For multiple selection, focus on the last selected item
|
|
133
|
+
const lastSelectedItem = value.at(-1);
|
|
134
|
+
return lastSelectedItem ? data.indexOf(lastSelectedItem) : -1;
|
|
135
|
+
}
|
|
136
|
+
return data.findIndex((v)=>v === value);
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
});
|
|
140
|
+
const handleMenuListChange = useEventCallback((newValue)=>{
|
|
141
|
+
// for uncontrolled mode
|
|
142
|
+
setValue(newValue);
|
|
143
|
+
if (inputRef.current) {
|
|
144
|
+
/**
|
|
145
|
+
* Programatically trigger the onChange event of the native input element.
|
|
146
|
+
* Doing this means we can avoid cloning another event to mimic the ChangeEvent.
|
|
147
|
+
*/ /**
|
|
148
|
+
* Set the value property of the input element, avoiding React's overridden setter.
|
|
149
|
+
* This will cause the input element to update its value and fire the onChange event,
|
|
150
|
+
* `handleInputChange` will then call onChange
|
|
151
|
+
*/ Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set?.call(inputRef.current, newValue);
|
|
152
|
+
const event = new Event('input', {
|
|
153
|
+
bubbles: true
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* When `selectMode` is `multiple`, the default `event.target.value` type is `string`,
|
|
157
|
+
* but it should actually be `string[]`. Since browsers do not natively support this,
|
|
158
|
+
* we need to override the `value` property to ensure it correctly reflects an array.
|
|
159
|
+
*
|
|
160
|
+
* Why do we need `Object.defineProperty` to override `event.target.value`?
|
|
161
|
+
* - The `target` property of an event object is read-only, so we cannot modify it directly.
|
|
162
|
+
* - `Object.defineProperty` allows us to override `event.target`, but it requires returning
|
|
163
|
+
* an object from the getter.
|
|
164
|
+
* - To dynamically override only the `value` property while preserving all other properties
|
|
165
|
+
* and methods of the input element, we use a `Proxy`.
|
|
166
|
+
*
|
|
167
|
+
* How does this approach help?
|
|
168
|
+
* - Ensures `event.target.value` correctly returns a `string[]` instead of a `string`.
|
|
169
|
+
* - Keeps the event object behaving as expected when accessed by event handlers.
|
|
170
|
+
* - Preserves other native properties (`name`, `id`, `type`, etc.) and methods
|
|
171
|
+
* (`focus()`, `blur()`, etc.), preventing potential "Illegal Invocation" errors.
|
|
172
|
+
*/ Object.defineProperty(event, 'target', {
|
|
173
|
+
configurable: true,
|
|
174
|
+
get: ()=>{
|
|
175
|
+
return new Proxy(inputRef.current, {
|
|
176
|
+
get (obj, prop) {
|
|
177
|
+
if (prop === 'value') {
|
|
178
|
+
return newValue; // override 'value'
|
|
179
|
+
}
|
|
180
|
+
return obj[prop];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
inputRef.current?.dispatchEvent(event);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
const { getButtonProps, getListboxProps } = useSelect({
|
|
189
|
+
open,
|
|
190
|
+
handleOpen
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* The non-virtualized Menu/MenuList components have the necessary contexts
|
|
194
|
+
* baked in. For the virtualized Menu, we need to provide the context values.
|
|
195
|
+
*/ const { contextValue: virtualizedContextValue } = useMenuItemSelect({
|
|
196
|
+
value,
|
|
197
|
+
onChange: handleMenuListChange,
|
|
198
|
+
onClose: handleClose,
|
|
199
|
+
selectMode
|
|
200
|
+
});
|
|
201
|
+
const virtualizedMenuContextValue = useMemo(()=>({
|
|
202
|
+
close: handleClose,
|
|
203
|
+
autoFocus: true
|
|
204
|
+
}), [
|
|
205
|
+
handleClose
|
|
206
|
+
]);
|
|
207
|
+
const selectorProps = getButtonProps(combineProps({
|
|
208
|
+
onMouseDown: (event)=>{
|
|
209
|
+
if (disabled || event.button !== 0) return;
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
event.currentTarget.focus();
|
|
212
|
+
}
|
|
213
|
+
}, selectorPropsProp));
|
|
214
|
+
const selectedValue = value !== null || displayEmpty ? renderValue(value) : null;
|
|
215
|
+
const valueId = `${id}-value`;
|
|
216
|
+
const labelId = `${id}-label`;
|
|
217
|
+
let menu = null;
|
|
218
|
+
const baseMenuClasses = {
|
|
219
|
+
paper: cls('menu')
|
|
220
|
+
};
|
|
221
|
+
const basePopperProps = {
|
|
222
|
+
matchAnchorWidth: true
|
|
223
|
+
};
|
|
224
|
+
const popperProps = combineProps(basePopperProps, !virtualize ? MenuProps?.PopperProps : virtualizedMenuPropsProp?.PopperProps);
|
|
225
|
+
const menuClasses = popperProps.matchAnchorWidth ? combineClasses(baseMenuClasses, {
|
|
226
|
+
paper: 'min-w-0'
|
|
227
|
+
}) : baseMenuClasses;
|
|
228
|
+
const onExitComplete = ()=>{
|
|
229
|
+
setDidMenuExit(true);
|
|
230
|
+
};
|
|
231
|
+
const baseMenuProps = {
|
|
232
|
+
onExitComplete,
|
|
233
|
+
placement: DEFAULT_PLACEMENT,
|
|
234
|
+
open,
|
|
235
|
+
anchorEl,
|
|
236
|
+
PopperProps: basePopperProps,
|
|
237
|
+
classes: menuClasses,
|
|
238
|
+
onClose: handleClose
|
|
239
|
+
};
|
|
240
|
+
if (!virtualize) {
|
|
241
|
+
menu = /*#__PURE__*/ jsx(Menu_Menu, {
|
|
242
|
+
...baseMenuProps,
|
|
243
|
+
...MenuProps,
|
|
244
|
+
PopperProps: popperProps,
|
|
245
|
+
classes: combineClasses(menuClasses, MenuProps?.classes),
|
|
246
|
+
motionProps: getYAxisGrowMotion({
|
|
247
|
+
placement: MenuProps?.placement,
|
|
248
|
+
prefersReducedMotion: prefersReducedMotion
|
|
249
|
+
}),
|
|
250
|
+
children: /*#__PURE__*/ jsx(MenuList_MenuList, {
|
|
251
|
+
value: value,
|
|
252
|
+
onChange: handleMenuListChange,
|
|
253
|
+
widget: "select",
|
|
254
|
+
selectMode: selectMode,
|
|
255
|
+
...getListboxProps(),
|
|
256
|
+
children: children
|
|
257
|
+
})
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
menu = /*#__PURE__*/ jsx(MenuContext.Provider, {
|
|
261
|
+
value: virtualizedMenuContextValue,
|
|
262
|
+
children: /*#__PURE__*/ jsx(MenuItemSelectContext.Provider, {
|
|
263
|
+
value: virtualizedContextValue,
|
|
264
|
+
children: /*#__PURE__*/ jsx(VirtualizedMenu_VirtualizedMenu, {
|
|
265
|
+
...baseMenuProps,
|
|
266
|
+
...virtualizedMenuPropsProp,
|
|
267
|
+
PopperProps: popperProps,
|
|
268
|
+
classes: combineClasses(baseMenuProps.classes, virtualizedMenuPropsProp?.classes),
|
|
269
|
+
initialFocus: handleInitialFocus,
|
|
270
|
+
data: data,
|
|
271
|
+
motionProps: getYAxisGrowMotion({
|
|
272
|
+
placement: virtualizedMenuPropsProp?.placement,
|
|
273
|
+
prefersReducedMotion: prefersReducedMotion
|
|
274
|
+
}),
|
|
275
|
+
children: children
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
281
|
+
children: [
|
|
282
|
+
/*#__PURE__*/ jsxs(FormField_FormField, {
|
|
283
|
+
disabled: disabled,
|
|
284
|
+
required: required,
|
|
285
|
+
variant: variant,
|
|
286
|
+
error: error,
|
|
287
|
+
// Make sure the focus style doesn't disappear when the Menu is in its close transition
|
|
288
|
+
focused: open || !open && !didMenuExit,
|
|
289
|
+
htmlFor: id,
|
|
290
|
+
label: label,
|
|
291
|
+
labelProps: {
|
|
292
|
+
id: labelId
|
|
293
|
+
},
|
|
294
|
+
ref: ref,
|
|
295
|
+
contentRef: formFieldContentRef,
|
|
296
|
+
helperText: helperText,
|
|
297
|
+
FormHelperTextProps: {
|
|
298
|
+
id: helperTextId,
|
|
299
|
+
...FormHelperTextProps
|
|
300
|
+
},
|
|
301
|
+
className: cls('root', {
|
|
302
|
+
error
|
|
303
|
+
}),
|
|
304
|
+
classes: {
|
|
305
|
+
outlined: cls('outlined'),
|
|
306
|
+
standard: cls('standard'),
|
|
307
|
+
contained: cls('contained'),
|
|
308
|
+
content: cls('content')
|
|
309
|
+
},
|
|
310
|
+
size: size,
|
|
311
|
+
...rest,
|
|
312
|
+
children: [
|
|
313
|
+
/*#__PURE__*/ jsxs("button", {
|
|
314
|
+
className: cls('selector', `${variant}-selector`, `${variant}-selector-${size}`, {
|
|
315
|
+
expanded: open
|
|
316
|
+
}),
|
|
317
|
+
disabled: disabled,
|
|
318
|
+
"aria-labelledby": label ? `${labelId} ${valueId}` : valueId,
|
|
319
|
+
"aria-describedby": helperTextId,
|
|
320
|
+
...selectorProps,
|
|
321
|
+
id: id,
|
|
322
|
+
type: "button",
|
|
323
|
+
children: [
|
|
324
|
+
hasContent(selectedValue) ? /*#__PURE__*/ jsx("span", {
|
|
325
|
+
id: valueId,
|
|
326
|
+
"aria-live": "polite",
|
|
327
|
+
className: cls('value'),
|
|
328
|
+
title: getTitle(selectedValue),
|
|
329
|
+
children: selectedValue
|
|
330
|
+
}) : /*#__PURE__*/ jsx("span", {
|
|
331
|
+
id: valueId,
|
|
332
|
+
className: cls('placeholder'),
|
|
333
|
+
title: getTitle(placeholder),
|
|
334
|
+
children: placeholder
|
|
335
|
+
}),
|
|
336
|
+
/*#__PURE__*/ jsx(Squircle_Squircle, {
|
|
337
|
+
className: cls('chevron'),
|
|
338
|
+
interactive: false,
|
|
339
|
+
children: /*#__PURE__*/ jsx(ExpandCollapseCaret_ExpandCollapseCaret, {
|
|
340
|
+
size: 'small',
|
|
341
|
+
expanded: open
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
]
|
|
345
|
+
}),
|
|
346
|
+
/*#__PURE__*/ jsx("input", {
|
|
347
|
+
ref: inputRef,
|
|
348
|
+
name: name,
|
|
349
|
+
value: `${value}`,
|
|
350
|
+
disabled: disabled,
|
|
351
|
+
className: cls('native-input'),
|
|
352
|
+
tabIndex: -1,
|
|
353
|
+
"aria-hidden": true,
|
|
354
|
+
"aria-invalid": error,
|
|
355
|
+
onChange: handleInputChange,
|
|
356
|
+
...inputProps
|
|
357
|
+
})
|
|
358
|
+
]
|
|
359
|
+
}),
|
|
360
|
+
anchorEl && menu
|
|
361
|
+
]
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
Select_Select.displayName = 'SuiSelect';
|
|
365
|
+
function getYAxisGrowMotion(params) {
|
|
366
|
+
const { placement = DEFAULT_PLACEMENT, ...rest } = params;
|
|
367
|
+
let verticalTransformOrigin = 'top';
|
|
368
|
+
if (placement === 'top') {
|
|
369
|
+
verticalTransformOrigin = 'bottom';
|
|
370
|
+
}
|
|
371
|
+
return getGrow({
|
|
372
|
+
...rest,
|
|
373
|
+
direction: 'y',
|
|
374
|
+
transformOrigin: {
|
|
375
|
+
vertical: verticalTransformOrigin,
|
|
376
|
+
horizontal: 'center'
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
export { Select as selectStyle, Select_Select as Select, useSelect };
|