@ringcentral/spring-ui 1.12.0 → 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.
Files changed (213) hide show
  1. package/Accordion.js +90 -34
  2. package/AccordionHeader.js +71 -21
  3. package/Alert.js +120 -28
  4. package/Animation.js +2 -46
  5. package/Announcement.js +46 -35
  6. package/Autocomplete.js +1011 -583
  7. package/Avatar.js +134 -73
  8. package/AvatarGroup.js +50 -7
  9. package/Backdrop.js +45 -7
  10. package/Badge.js +77 -15
  11. package/Block.js +34 -12
  12. package/BlockHeader.js +57 -15
  13. package/BottomNavigation.js +181 -65
  14. package/BottomNavigationItem.js +93 -30
  15. package/Button.js +160 -24
  16. package/CallButton.js +53 -31
  17. package/Checkbox.js +88 -26
  18. package/Chip.js +126 -26
  19. package/CircularProgressIndicator.js +80 -8
  20. package/ClickAwayListener.js +4 -1
  21. package/ComponentsProps.js +1 -0
  22. package/DatePicker.js +611 -192
  23. package/DateUtilsContext.js +43 -25
  24. package/Dialer.js +564 -253
  25. package/Dialog.js +99 -45
  26. package/Divider.js +43 -7
  27. package/DragHandle.js +32 -6
  28. package/Drawer.js +117 -19
  29. package/Dropdown.js +154 -77
  30. package/EmptyState.js +65 -15
  31. package/FabButton.js +51 -17
  32. package/FocusTrap.js +109 -12
  33. package/FormField.js +108 -12
  34. package/FormLabel.js +81 -7
  35. package/Icon.js +1 -8
  36. package/IconButton.js +142 -26
  37. package/IconButtonGroup.js +35 -12
  38. package/InlineEditable.js +98 -44
  39. package/LinearProgressIndicator.js +73 -24
  40. package/Link.js +40 -11
  41. package/List.js +54 -9
  42. package/ListItem.js +152 -23
  43. package/ListItemText.js +44 -17
  44. package/ListNavigation.js +272 -20
  45. package/Menu.js +139 -23
  46. package/MenuActions.js +37 -12
  47. package/MenuDivider.js +34 -8
  48. package/MenuFooter.js +36 -12
  49. package/MenuHeader.js +54 -16
  50. package/MenuItem.js +402 -35
  51. package/MenuItemText.js +51 -9
  52. package/MenuList.js +87 -36
  53. package/Modal.js +345 -16
  54. package/NestedMenuContext.js +183 -11
  55. package/Option.js +32 -36
  56. package/Overlap.js +54 -7
  57. package/PageHeader.js +62 -24
  58. package/PickerTextField.js +156 -35
  59. package/Popover.js +262 -21
  60. package/Popper.js +112 -62
  61. package/PopperPaper.js +54 -8
  62. package/Portal.js +6 -1
  63. package/Radio.js +65 -21
  64. package/RadioGroup.js +56 -17
  65. package/Rating.js +223 -87
  66. package/Select.js +387 -44
  67. package/SingleFilter.js +148 -79
  68. package/Skeleton.js +68 -17
  69. package/Slider.js +167 -69
  70. package/Snackbar.js +122 -59
  71. package/SortableList.js +32 -12
  72. package/SortableListDndContext.js +69 -22
  73. package/SortableListItem.js +92 -47
  74. package/SortableVirtualizedList.js +44 -20
  75. package/SplitButton.js +124 -89
  76. package/Squircle.js +4 -7
  77. package/StatusIndicator.js +51 -9
  78. package/Step.js +63 -38
  79. package/StepButton.js +51 -23
  80. package/StepConnector.js +48 -8
  81. package/StepContent.js +67 -24
  82. package/StepIcon.js +90 -9
  83. package/StepLabel.js +90 -14
  84. package/Stepper.js +65 -23
  85. package/SubMenu.js +203 -101
  86. package/SwipeableDrawer.js +439 -194
  87. package/Switch.js +70 -23
  88. package/Tab.js +120 -57
  89. package/TabContext.js +59 -15
  90. package/TabPanel.js +40 -13
  91. package/Table.js +60 -17
  92. package/TableBody.js +42 -12
  93. package/TableCell.js +84 -50
  94. package/TableContainer.js +32 -10
  95. package/TableFooter.js +38 -10
  96. package/TableHead.js +49 -15
  97. package/TablePagination.js +153 -79
  98. package/TableRow.js +60 -21
  99. package/Tabs.js +592 -271
  100. package/Tag.js +51 -16
  101. package/Text.js +68 -37
  102. package/TextField.js +209 -31
  103. package/Textarea.js +51 -42
  104. package/TimePicker.js +490 -232
  105. package/Tooltip.js +48 -23
  106. package/Tray.js +237 -13
  107. package/TrayMenu.js +62 -43
  108. package/VirtualizedList.js +205 -107
  109. package/VirtualizedMenu.js +359 -29
  110. package/VisuallyHidden.js +29 -6
  111. package/chunks/1250.js +98 -0
  112. package/chunks/1294.js +126 -0
  113. package/chunks/2956.js +18 -0
  114. package/chunks/4476.js +460 -0
  115. package/chunks/4491.js +10 -0
  116. package/chunks/4535.js +364 -0
  117. package/chunks/5047.js +3 -0
  118. package/chunks/6335.js +24 -0
  119. package/chunks/7279.js +10 -0
  120. package/chunks/8011.js +8 -0
  121. package/chunks/8307.js +56 -0
  122. package/chunks/8467.js +8 -0
  123. package/chunks/8809.js +8 -0
  124. package/chunks/{RadioGroup.context.js → 9551.js} +12 -6
  125. package/chunks/987.js +8 -0
  126. package/index.css +2436 -2261
  127. package/index.js +245 -195
  128. package/internal/utils/setRef.d.ts +2 -1
  129. package/package.json +4 -4
  130. package/src/Animation/hooks/useMotionSafeTransition/useMotionSafeTransition.d.ts +2 -0
  131. package/src/Autocomplete/SuggestionList/SuggestionList.d.ts +1 -1
  132. package/src/Button/Button.classes.d.ts +1 -1
  133. package/src/ComponentsProps.d.ts +111 -110
  134. package/src/DatePicker/DatePickerDataAttributes.d.ts +11 -0
  135. package/src/DatePicker/utils/DatePickerUtils.d.ts +1 -1
  136. package/src/MenuItem/MenuItem.type.d.ts +1 -0
  137. package/src/MenuList/MenuListContext.d.ts +2 -3
  138. package/src/Modal/Modal.type.d.ts +1 -0
  139. package/src/Popover/Popover.classes.d.ts +1 -1
  140. package/src/Popover/Popover.internal.d.ts +8 -0
  141. package/src/Popover/Popover.type.d.ts +1 -0
  142. package/src/Select/Select.type.d.ts +6 -4
  143. package/src/Table/Table.type.d.ts +3 -0
  144. package/src/Table/TableContext.d.ts +3 -0
  145. package/src/Table/TableRowContext.d.ts +7 -0
  146. package/src/Table/index.d.ts +1 -0
  147. package/src/TableCell/TableCell.classes.d.ts +1 -1
  148. package/src/TableFooter/TableFooter.classes.d.ts +1 -1
  149. package/src/TableFooter/TableFooter.type.d.ts +1 -0
  150. package/src/TableHead/TableHead.classes.d.ts +1 -1
  151. package/src/TableHead/TableHead.type.d.ts +1 -0
  152. package/src/TableRow/TableRow.type.d.ts +2 -0
  153. package/chunks/AccordionContext.js +0 -6
  154. package/chunks/Alert.js +0 -48
  155. package/chunks/AvatarGroup.js +0 -22
  156. package/chunks/Backdrop.js +0 -18
  157. package/chunks/Badge.js +0 -32
  158. package/chunks/BottomNavigationItem.js +0 -36
  159. package/chunks/Button.js +0 -88
  160. package/chunks/Chip.js +0 -73
  161. package/chunks/CircularProgressIndicator.js +0 -36
  162. package/chunks/Divider.js +0 -19
  163. package/chunks/DragHandle.js +0 -11
  164. package/chunks/Drawer.js +0 -33
  165. package/chunks/ExpandCollapseCaret.js +0 -24
  166. package/chunks/FormLabel.js +0 -27
  167. package/chunks/Icon.js +0 -25
  168. package/chunks/IconButtonLabel.js +0 -68
  169. package/chunks/List.js +0 -22
  170. package/chunks/ListItem.js +0 -83
  171. package/chunks/Menu.js +0 -61
  172. package/chunks/MenuDivider.js +0 -14
  173. package/chunks/MenuItemText.js +0 -18
  174. package/chunks/MenuList.js +0 -47
  175. package/chunks/Modal.js +0 -211
  176. package/chunks/Overlap.js +0 -25
  177. package/chunks/PickerTextField.js +0 -85
  178. package/chunks/Popover.js +0 -61
  179. package/chunks/PopperPaper.js +0 -15
  180. package/chunks/Select.js +0 -225
  181. package/chunks/ShowHideEye.js +0 -56
  182. package/chunks/SlideIn.js +0 -20
  183. package/chunks/SortableArrow.js +0 -73
  184. package/chunks/Squircle.js +0 -31
  185. package/chunks/StatusIndicator.js +0 -20
  186. package/chunks/StepConnector.js +0 -21
  187. package/chunks/StepIcon.js +0 -43
  188. package/chunks/StepLabel.js +0 -29
  189. package/chunks/StepperContext.js +0 -9
  190. package/chunks/TableContext.js +0 -6
  191. package/chunks/Tablelvl2Context.js +0 -6
  192. package/chunks/TabsContext.js +0 -6
  193. package/chunks/TextField.js +0 -110
  194. package/chunks/Tooltip.js +0 -217
  195. package/chunks/VirtualizedMenu.js +0 -162
  196. package/chunks/VisuallyHidden.js +0 -12
  197. package/chunks/composeEventHandlers.js +0 -10
  198. package/chunks/getFade.js +0 -27
  199. package/chunks/getGrow.js +0 -70
  200. package/chunks/getSlideIn.js +0 -30
  201. package/chunks/hasContent.js +0 -3
  202. package/chunks/useAnimationFrame.js +0 -15
  203. package/chunks/useFocusTrapStack.js +0 -38
  204. package/chunks/useHelperTextId.js +0 -24
  205. package/chunks/useListNavigation.js +0 -199
  206. package/chunks/useMenuItemSelect.js +0 -282
  207. package/chunks/useMotionSafeTransition.js +0 -9
  208. package/chunks/useNestedMenuItem.js +0 -27
  209. package/chunks/useNestedParentMenu.js +0 -113
  210. package/chunks/usePrefersReducedMotion.js +0 -36
  211. package/chunks/useTooltipForceHide.js +0 -27
  212. package/chunks/useTrayNavigate.js +0 -150
  213. package/chunks/withTooltip.js +0 -15
@@ -1,47 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useMemo, useRef, useLayoutEffect } from 'react';
3
- import { useClasses, useForkRef, useWindowContext } from '@ringcentral/spring-base';
4
- import { useThemeProps } from '@ringcentral/spring-theme';
5
- import { L as List } from './List.js';
6
- import { u as useMenuContext } from './Menu.js';
7
- import { c as useMenuItemSelect, e as MenuListContext, a as MenuItemSelectContext } from './useMenuItemSelect.js';
8
- import '@mui/utils';
9
- import 'tabbable';
10
- import './useListNavigation.js';
11
- import '../VirtualizedList.js';
12
-
13
- const MenuList = forwardRef((inProps, ref) => {
14
- const props = useThemeProps({ props: inProps, name: 'MenuList' });
15
- const { classes, className, children, widget, selectMode = 'single', nowrap, value: valueProp, onChange, autoFocus: autoFocusProp, ...rest } = props;
16
- const menuContext = useMenuContext();
17
- const autoFocus = Boolean(autoFocusProp ?? menuContext?.autoFocus);
18
- const cls = useClasses('menu-list', classes, className);
19
- const menuListContextValue = useMemo(() => ({
20
- nowrap,
21
- }), [nowrap]);
22
- const { contextValue } = useMenuItemSelect({
23
- widget,
24
- selectMode,
25
- value: valueProp,
26
- onChange,
27
- autoFocus,
28
- });
29
- const actions = useRef(null);
30
- const listRef = useRef(null);
31
- const handleListRef = useForkRef(listRef, ref);
32
- const { document } = useWindowContext();
33
- useLayoutEffect(() => {
34
- if (autoFocus &&
35
- !listRef.current?.contains(document?.activeElement ?? null)) {
36
- actions.current?.focus();
37
- }
38
- }, [autoFocus]);
39
- const listRole = widget === 'select' ? 'listbox' : 'menu';
40
- const listboxProps = widget === 'select'
41
- ? { 'aria-multiselectable': selectMode === 'multiple' }
42
- : {};
43
- return (jsx(List, { className: cls('root'), role: listRole, ...listboxProps, ...rest, ref: handleListRef, actions: actions, children: jsx(MenuListContext.Provider, { value: menuListContextValue, children: jsx(MenuItemSelectContext.Provider, { value: contextValue, children: children }) }) }));
44
- });
45
- MenuList.displayName = 'SuiMenuList';
46
-
47
- export { MenuList as M };
package/chunks/Modal.js DELETED
@@ -1,211 +0,0 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { createContext, useContext, useRef, useCallback, useLayoutEffect, forwardRef, useState, useEffect } from 'react';
3
- import { useAriaHideOutside, useForkRef, useClasses, useEventCallback, useBodyScrollLock, useWindowContext } from '@ringcentral/spring-base';
4
- import { useThemeProps, useTheme } from '@ringcentral/spring-theme';
5
- import { FocusTrap, Portal } from '@mui/base';
6
- import { motion } from 'framer-motion';
7
- import './Icon.js';
8
- import { u as usePrefersReducedMotion } from './usePrefersReducedMotion.js';
9
- import { g as getFade } from './getFade.js';
10
- import { u as useFocusTrapStack } from './useFocusTrapStack.js';
11
- import { B as Backdrop } from './Backdrop.js';
12
-
13
- const ModalContext = createContext(null);
14
- const useModalContext = () => useContext(ModalContext);
15
-
16
- const createOverlayBranchRegistry = () => {
17
- const branchRefCounts = new Map();
18
- const listeners = new Set();
19
- const notify = (node, isRegistered) => {
20
- for (const listener of [...listeners]) {
21
- listener(node, isRegistered);
22
- }
23
- };
24
- return {
25
- getBranches: () => new Set(branchRefCounts.keys()),
26
- register: (node) => {
27
- const currentCount = branchRefCounts.get(node) ?? 0;
28
- branchRefCounts.set(node, currentCount + 1);
29
- if (currentCount === 0) {
30
- notify(node, true);
31
- }
32
- let isCleanedUp = false;
33
- return () => {
34
- if (isCleanedUp) {
35
- return;
36
- }
37
- isCleanedUp = true;
38
- const currentCount = branchRefCounts.get(node);
39
- if (!currentCount) {
40
- return;
41
- }
42
- if (currentCount > 1) {
43
- branchRefCounts.set(node, currentCount - 1);
44
- return;
45
- }
46
- branchRefCounts.delete(node);
47
- notify(node, false);
48
- };
49
- },
50
- subscribe: (listener) => {
51
- listeners.add(listener);
52
- return () => {
53
- listeners.delete(listener);
54
- };
55
- },
56
- };
57
- };
58
- const useOverlayBranchRegistry = () => {
59
- const registryRef = useRef();
60
- if (!registryRef.current) {
61
- registryRef.current = createOverlayBranchRegistry();
62
- }
63
- return registryRef.current;
64
- };
65
-
66
- const useOverlayBranch = ({ active, registry, }) => {
67
- const nodeRef = useRef(null);
68
- const registrationRef = useRef(null);
69
- const syncRegistration = useCallback((node) => {
70
- const registration = registrationRef.current;
71
- const shouldKeepRegistration = registration &&
72
- active &&
73
- registration.node === node &&
74
- registration.registry === registry;
75
- if (shouldKeepRegistration) {
76
- return;
77
- }
78
- registration?.unregister();
79
- registrationRef.current = null;
80
- if (active && node && registry) {
81
- registrationRef.current = {
82
- node,
83
- registry,
84
- unregister: registry.register(node),
85
- };
86
- }
87
- }, [active, registry]);
88
- const setBranchRef = useCallback((node) => {
89
- nodeRef.current = node;
90
- syncRegistration(node);
91
- }, [syncRegistration]);
92
- useLayoutEffect(() => {
93
- syncRegistration(nodeRef.current);
94
- }, [syncRegistration]);
95
- useLayoutEffect(() => () => {
96
- registrationRef.current?.unregister();
97
- registrationRef.current = null;
98
- }, []);
99
- return setBranchRef;
100
- };
101
- const useOverlayBranchConsumer = (registry, listener) => {
102
- useLayoutEffect(() => {
103
- const unsubscribe = registry.subscribe(listener);
104
- for (const node of registry.getBranches()) {
105
- listener(node, true);
106
- }
107
- return () => {
108
- unsubscribe();
109
- for (const node of registry.getBranches()) {
110
- listener(node, false);
111
- }
112
- };
113
- }, [listener, registry]);
114
- };
115
-
116
- const InnerModal = forwardRef((props, ref) => {
117
- const { hideBackdrop: hideBackdropProp, children, motionProps, disableBackdropClick: disableBackdropClickProp, onBackdropClick, disableEscapeKeyDown: disableEscapeKeyDownProp, onEscapeKeyDown, onClose, onKeyDown, disableAutoFocus, disableEnforceFocus, disableRestoreFocus, classes, className, backdropProps, open, isEnabled, blocking = true, shouldUseInert: shouldUseInertProp, ...rest } = props;
118
- const parentModalContext = useModalContext();
119
- const ownOverlayBranchRegistry = useOverlayBranchRegistry();
120
- const shouldUseInert = shouldUseInertProp ?? parentModalContext?.shouldUseInert ?? false;
121
- const hideBackdrop = hideBackdropProp ?? !blocking;
122
- const disableBackdropClick = disableBackdropClickProp ?? !blocking;
123
- const disableEscapeKeyDown = disableEscapeKeyDownProp ?? !blocking;
124
- const { ariaHideOutsideRef, ariaHideEnabled, setAriaHideOutsideTarget } = useAriaHideOutside({
125
- enable: blocking && open,
126
- shouldUseInert,
127
- });
128
- useOverlayBranchConsumer(ownOverlayBranchRegistry, setAriaHideOutsideTarget);
129
- const parentOverlayBranchRegistry = parentModalContext?.overlayBranchRegistry;
130
- const overlayBranchRegistry = ariaHideEnabled
131
- ? ownOverlayBranchRegistry
132
- : parentOverlayBranchRegistry;
133
- const ariaHideEnabledForChildren = ariaHideEnabled || parentModalContext?.ariaHideEnabled === true;
134
- const overlayBranchRef = useOverlayBranch({
135
- active: !blocking && open,
136
- registry: parentOverlayBranchRegistry,
137
- });
138
- const handleRef = useForkRef(ref, ariaHideOutsideRef, overlayBranchRef);
139
- const cls = useClasses('modal', classes, className);
140
- const { onClick: externalOnClick, ...restBackdropProps } = backdropProps || {};
141
- const handleBackdropClick = useEventCallback((event) => {
142
- if (disableBackdropClick)
143
- return;
144
- if (event.target !== event.currentTarget) {
145
- return;
146
- }
147
- externalOnClick?.(event);
148
- onBackdropClick?.(event);
149
- onClose?.(event, 'backdropClick');
150
- });
151
- return (jsx(ModalContext.Provider, { value: {
152
- ariaHideEnabled: ariaHideEnabledForChildren,
153
- overlayBranchRegistry,
154
- shouldUseInert,
155
- }, children: jsxs(motion.div, { ...rest, ...motionProps, role: "presentation", className: cls('root', { 'non-blocking': !blocking }), onKeyDown: (e) => {
156
- onKeyDown?.(e);
157
- if (!disableEscapeKeyDown &&
158
- e.key === 'Escape' &&
159
- (isEnabled?.() ?? true)) {
160
- onEscapeKeyDown?.(e);
161
- onClose?.(e, 'escapeKeyDown');
162
- }
163
- }, ref: handleRef, children: [jsx(Backdrop, { ...restBackdropProps, isTransparent: hideBackdrop, onClick: handleBackdropClick }), jsx(FocusTrap, { open: open, isEnabled: isEnabled, disableAutoFocus: disableAutoFocus || !blocking, disableEnforceFocus: disableEnforceFocus || !blocking, disableRestoreFocus: disableRestoreFocus || !blocking, children: children })] }) }));
164
- });
165
- InnerModal.displayName = 'SuiInnerModal';
166
-
167
- const Modal = forwardRef((inProps, ref) => {
168
- const props = useThemeProps({ props: inProps, name: 'Modal' });
169
- const { children, open, container: containerProp, disablePortal, onExitComplete, disableBackdropAnimation, motionProps, disableScrollLock: disableScrollLockProp, blocking = true, shouldUseInert: themeFallbackShouldUseInert, ...rest } = props;
170
- const parentModalContext = useModalContext();
171
- const shouldUseInert = inProps.shouldUseInert ??
172
- parentModalContext?.shouldUseInert ??
173
- themeFallbackShouldUseInert ??
174
- false;
175
- const disableScrollLock = disableScrollLockProp ?? !blocking;
176
- const [shouldRender, setShouldRender] = useState(open);
177
- const [modalElement, setModalElement] = useState(null);
178
- const handleRef = useForkRef(setModalElement, ref);
179
- const prefersReducedMotion = usePrefersReducedMotion();
180
- const { isEnabled } = useFocusTrapStack({ open });
181
- useBodyScrollLock(open, modalElement, {
182
- disabled: disableScrollLock,
183
- });
184
- useEffect(() => {
185
- if (open) {
186
- setShouldRender(true);
187
- }
188
- else {
189
- if (disableBackdropAnimation) {
190
- setShouldRender(false);
191
- }
192
- }
193
- }, [open, disableBackdropAnimation]);
194
- const { document } = useWindowContext();
195
- const container = containerProp ?? document?.body;
196
- const { scopeProps } = useTheme();
197
- const onAnimationComplete = (e) => {
198
- motionProps?.onAnimationComplete?.(e);
199
- if (!open) {
200
- onExitComplete?.();
201
- setShouldRender(false);
202
- }
203
- };
204
- return shouldRender ? (jsx(Portal, { disablePortal: disablePortal, container: container, children: jsx("div", { ...scopeProps, children: jsx(InnerModal, { ...rest, ref: handleRef, open: open, blocking: blocking, shouldUseInert: shouldUseInert, isEnabled: isEnabled, motionProps: {
205
- ...(motionProps ?? getFade({ prefersReducedMotion, toggle: open })),
206
- onAnimationComplete,
207
- }, children: children }) }) })) : null;
208
- });
209
- Modal.displayName = 'SuiModal';
210
-
211
- export { InnerModal as I, Modal as M, ModalContext as a, useOverlayBranch as b, useModalContext as u };
package/chunks/Overlap.js DELETED
@@ -1,25 +0,0 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { forwardRef } from 'react';
3
- import { useClasses } from '@ringcentral/spring-base';
4
- import { useThemeProps } from '@ringcentral/spring-theme';
5
-
6
- function isKeyPosition(position) {
7
- return typeof position === 'string';
8
- }
9
- const Overlap = forwardRef((inProps, ref) => {
10
- const props = useThemeProps({ props: inProps, name: 'Overlap' });
11
- const { classes, floater, position, children, className, showFloaterOnHoverOnly = false, component: OverlapRoot = 'div', ...rest } = props;
12
- const cls = useClasses('overlap', classes, className);
13
- let widget = null;
14
- if (floater) {
15
- const style = !isKeyPosition(position) ? position : undefined;
16
- const classes = cls('floater', isKeyPosition(position) && position);
17
- widget = jsx("div", { style: style, className: classes, children: floater });
18
- }
19
- return (jsxs(OverlapRoot, { ...rest, ref: ref, className: cls('root', {
20
- 'show-floater-on-hover-only': showFloaterOnHoverOnly,
21
- }), children: [children, widget] }));
22
- });
23
- Overlap.displayName = 'SuiOverlap';
24
-
25
- export { Overlap as O };
@@ -1,85 +0,0 @@
1
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useState, useRef, useImperativeHandle, useMemo } from 'react';
3
- import { useId, useClasses, useForkRef, useA11yKeyEvent, useEventCallback, combineClasses } from '@ringcentral/spring-base';
4
- import { I as Icon } from './Icon.js';
5
- import { P as Popover } from './Popover.js';
6
- import { u as useHelperTextId } from './useHelperTextId.js';
7
- import { T as TextField } from './TextField.js';
8
- import { V as VisuallyHidden } from './VisuallyHidden.js';
9
-
10
- const PICKER_DISPLAY_NAME = 'SuiPickerTextField';
11
- const PickerTextField = forwardRef((props, ref) => {
12
- const { disabled, value, defaultValue, onClear, action, inputProps = {}, announcementText, PopoverProps, children, endIconSymbol, clearText, clearBtn, ClearButtonProps, onKeyDown, onClick, onClose, classes, textInputClasses, className, id: idProp, ...rest } = props;
13
- const generatedId = useId(PICKER_DISPLAY_NAME, true);
14
- const idForInput = idProp ?? inputProps.id ?? generatedId;
15
- const [open, setOpen] = useState(false);
16
- const [isPopoverExited, setIsPopoverExited] = useState(!open);
17
- const cls = useClasses('picker-text-field', classes, className);
18
- const anchorRef = useRef(null);
19
- const handleRef = useForkRef(ref, anchorRef);
20
- const idForHelperText = useHelperTextId({
21
- helperText: rest.helperText,
22
- id: idForInput,
23
- FormHelperTextProps: rest.FormHelperTextProps,
24
- });
25
- const idForInstruction = announcementText
26
- ? `${idForInput}-instruction`
27
- : undefined;
28
- const ariaDescribedBy = Array.from(new Set([inputProps['aria-describedby'], idForHelperText, idForInstruction]
29
- .filter(Boolean)
30
- .flatMap((value) => `${value}`.split(/\s+/).filter(Boolean)))).join(' ');
31
- const handleA11yKeydown = useA11yKeyEvent(() => {
32
- handleOpen(true);
33
- });
34
- const handleOpen = useEventCallback((open) => {
35
- if (disabled && open) {
36
- return;
37
- }
38
- if (open) {
39
- setIsPopoverExited(false);
40
- }
41
- setOpen(open);
42
- });
43
- useImperativeHandle(action, () => ({
44
- close: () => {
45
- handleOpen(false);
46
- },
47
- }), [handleOpen]);
48
- const toClasses = useMemo(() => combineClasses(textInputClasses, {
49
- formFieldContent: cls('form-field-content', {
50
- 'has-value': Boolean(value),
51
- }),
52
- root: cls('root', {
53
- 'has-value': Boolean(value),
54
- }),
55
- input: cls('input'),
56
- }), [cls, textInputClasses, value]);
57
- return (jsxs(Fragment, { children: [jsx(TextField, { classes: toClasses, value: value, defaultValue: defaultValue, endAdornment: endIconSymbol && (jsx(Icon, { className: cls('end-icon'), symbol: endIconSymbol })), id: idForInput, ref: handleRef, focused: open || (!open && !isPopoverExited), disabled: disabled, clearBtn: clearBtn, clearText: clearText, ClearButtonProps: ClearButtonProps, onClick: (e) => {
58
- handleOpen(true);
59
- onClick?.(e);
60
- }, onKeyDown: (e) => {
61
- if (disabled)
62
- return;
63
- handleA11yKeydown(e);
64
- onKeyDown?.(e);
65
- }, inputProps: {
66
- 'aria-haspopup': true,
67
- ...inputProps,
68
- 'aria-describedby': ariaDescribedBy || undefined,
69
- }, ...rest, readOnly: true, onClear: (e) => {
70
- onClear?.(e);
71
- e.stopPropagation();
72
- } }), jsx(Popover, { bordered: true, open: open, anchorEl: anchorRef.current, onClose: (...args) => {
73
- handleOpen(false);
74
- onClose?.(...args);
75
- }, placement: "bottom-start", transformOrigin: {
76
- vertical: 'top',
77
- horizontal: 'left',
78
- }, ...PopoverProps, onExitComplete: () => {
79
- PopoverProps?.onExitComplete?.();
80
- setIsPopoverExited(true);
81
- }, children: children }), idForInstruction && (jsx(VisuallyHidden, { id: idForInstruction, children: announcementText }))] }));
82
- });
83
- PickerTextField.displayName = PICKER_DISPLAY_NAME;
84
-
85
- export { PickerTextField as P };
package/chunks/Popover.js DELETED
@@ -1,61 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useRef } from 'react';
3
- import { size } from '@floating-ui/react-dom';
4
- import { useClasses, useForkRef, combineProps } from '@ringcentral/spring-base';
5
- import { useThemeProps } from '@ringcentral/spring-theme';
6
- import 'framer-motion';
7
- import './Icon.js';
8
- import { u as usePrefersReducedMotion } from './usePrefersReducedMotion.js';
9
- import { g as getGrow, a as getTransformOriginStringForPlacement } from './getGrow.js';
10
- import { M as Modal } from './Modal.js';
11
- import { Popper } from '../Popper.js';
12
- import { P as PopperPaper } from './PopperPaper.js';
13
-
14
- const Popover = forwardRef((inProps, ref) => {
15
- const props = useThemeProps({ props: inProps, name: 'Popover' });
16
- const { classes, className, children, PopperProps, variant = 'standard', bordered = false, shadow = true, transformOrigin, motionProps: motionPropsProp, popperRef, placement, anchorEl, actions, onAvailableHeightChange, PopperPaperProps: popperPaperPropsProp, ...rest } = props;
17
- const cls = useClasses('popover', classes, className);
18
- const paperContentRef = useRef(null);
19
- const handlePaperContentRef = useForkRef(popperPaperPropsProp?.contentRef, paperContentRef);
20
- const prefersReducedMotion = usePrefersReducedMotion();
21
- return (jsx(Modal, { ...rest, className: cls('root', 'popper'), ref: ref, motionProps: null, hideBackdrop: true, children: jsx(Popper, { arrowHeight: variant === 'standard' ? 0 : 10, arrowPadding: 12, offset: variant === 'standard' ? 2 : 4, ...combineProps({
22
- tether: false,
23
- middlewares: [
24
- size({
25
- padding: PopperProps?.padding,
26
- apply({ availableHeight, availableWidth, elements, }) {
27
- onAvailableHeightChange?.(availableHeight);
28
- const content = paperContentRef.current;
29
- if (!content) {
30
- return;
31
- }
32
- const decorationHeight = elements.floating.offsetHeight - content.offsetHeight;
33
- const decorationWidth = elements.floating.offsetWidth - content.offsetWidth;
34
- const maxHeight = Math.max(0, availableHeight - decorationHeight);
35
- content.style.maxWidth = `${Math.max(0, availableWidth - decorationWidth)}px`;
36
- content.style.maxHeight = '';
37
- content.style.maxHeight =
38
- maxHeight < content.scrollHeight ? `${maxHeight}px` : '';
39
- },
40
- }),
41
- ],
42
- }, PopperProps), className: cls('popper'), disablePortal: true, tabIndex: -1, ref: popperRef, placement: placement, anchorEl: anchorEl, actions: actions, children: ({ arrowStyle, arrowRef, placement: computedPlacement }) => {
43
- const motionProps = motionPropsProp ??
44
- getGrow({ transformOrigin, prefersReducedMotion });
45
- const popperPaperProps = {
46
- className: cls('paper', { bordered, shadow }),
47
- };
48
- if (!transformOrigin) {
49
- popperPaperProps.style = {
50
- ...popperPaperProps.style,
51
- transformOrigin: getTransformOriginStringForPlacement({
52
- placement: computedPlacement,
53
- }),
54
- };
55
- }
56
- return (jsx(PopperPaper, { arrowRef: arrowRef, arrowStyle: arrowStyle, ...combineProps(combineProps(motionProps, popperPaperProps), popperPaperPropsProp), contentRef: handlePaperContentRef, children: children }));
57
- } }) }));
58
- });
59
- Popover.displayName = 'SuiPopover';
60
-
61
- export { Popover as P };
@@ -1,15 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { forwardRef } from 'react';
3
- import { motion } from 'framer-motion';
4
- import { useClasses } from '@ringcentral/spring-base';
5
- import { useThemeProps } from '@ringcentral/spring-theme';
6
-
7
- const PopperPaper = forwardRef((inProps, ref) => {
8
- const props = useThemeProps({ props: inProps, name: 'PopperPaper' });
9
- const { classes, className, children, arrowRef, arrowStyle, contentRef, ...rest } = props;
10
- const cls = useClasses('popper-paper', classes, className);
11
- return (jsxs(motion.div, { className: cls('root'), ...rest, ref: ref, children: [jsx("div", { ref: contentRef, className: cls('content'), children: children }), jsx("div", { className: cls('arrow'), ref: arrowRef, style: arrowStyle })] }));
12
- });
13
- PopperPaper.displayName = 'SuiPopperPaper';
14
-
15
- export { PopperPaper as P };
package/chunks/Select.js DELETED
@@ -1,225 +0,0 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { forwardRef, useState, useRef, useEffect, useMemo } from 'react';
3
- import { combineProps, useControlled, useClasses, useId, useEventCallback, combineClasses, getTitle } from '@ringcentral/spring-base';
4
- import { useThemeProps } from '@ringcentral/spring-theme';
5
- import { E as ExpandCollapseCaret } from './ExpandCollapseCaret.js';
6
- import 'framer-motion';
7
- import { u as usePrefersReducedMotion } from './usePrefersReducedMotion.js';
8
- import { g as getGrow } from './getGrow.js';
9
- import './Icon.js';
10
- import { h as hasContent } from './hasContent.js';
11
- import '@mui/utils';
12
- import { u as useHelperTextId, F as FormField } from './useHelperTextId.js';
13
- import { M as Menu, a as MenuContext } from './Menu.js';
14
- import { c as useMenuItemSelect, a as MenuItemSelectContext } from './useMenuItemSelect.js';
15
- import 'tabbable';
16
- import './useListNavigation.js';
17
- import '../VirtualizedList.js';
18
- import { M as MenuList } from './MenuList.js';
19
- import { S as Squircle } from './Squircle.js';
20
- import { a as VirtualizedMenu } from './VirtualizedMenu.js';
21
-
22
- const useSelect = (props) => {
23
- const { open, handleOpen } = props;
24
- const getButtonProps = (otherHandlers = {}) => {
25
- const eventHandlers = combineProps({
26
- onClick: () => {
27
- handleOpen(!open);
28
- },
29
- onKeyDown: (e) => {
30
- if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
31
- e.preventDefault();
32
- handleOpen(true);
33
- }
34
- },
35
- }, otherHandlers);
36
- return {
37
- 'aria-expanded': open,
38
- 'aria-haspopup': 'listbox',
39
- ...eventHandlers,
40
- };
41
- };
42
- const getListboxProps = () => ({
43
- role: 'listbox',
44
- });
45
- return {
46
- getButtonProps,
47
- getListboxProps,
48
- };
49
- };
50
-
51
- const DEFAULT_PLACEMENT = 'bottom';
52
- const Select = forwardRef((inProps, ref) => {
53
- const props = useThemeProps({ props: inProps, name: 'Select' });
54
- 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;
55
- const [anchorEl, setAnchorEl] = useState(null);
56
- const [open, setOpen] = useControlled({
57
- controlled: openProp,
58
- default: defaultOpen,
59
- name: 'SuiSelect',
60
- state: 'open',
61
- });
62
- const [didMenuExit, setDidMenuExit] = useState(!open);
63
- const inputRef = useRef(null);
64
- const prefersReducedMotion = usePrefersReducedMotion();
65
- const cls = useClasses('select', classes, className);
66
- const id = useId(idProp);
67
- const helperTextId = useHelperTextId({
68
- helperText,
69
- id,
70
- FormHelperTextProps,
71
- });
72
- const formFieldContentRef = useRef(null);
73
- useEffect(() => {
74
- setAnchorEl(formFieldContentRef.current);
75
- }, []);
76
- const handleOpen = useEventCallback((newOpen) => {
77
- if (disabled && newOpen)
78
- return;
79
- if (newOpen)
80
- setDidMenuExit(false);
81
- setOpen(newOpen);
82
- if (newOpen) {
83
- onOpen?.();
84
- }
85
- else {
86
- onClose?.();
87
- }
88
- });
89
- useEffect(() => {
90
- if (disabled) {
91
- handleOpen(false);
92
- }
93
- }, [disabled, handleOpen]);
94
- const [value, setValue] = useControlled({
95
- controlled: valueProp,
96
- default: defaultValue,
97
- name: 'SuiSelect',
98
- state: 'value',
99
- });
100
- const handleInputChange = useEventCallback((e) => {
101
- onChangeProp?.(e, inputRef.current);
102
- });
103
- const handleClose = useEventCallback(() => {
104
- handleOpen(false);
105
- });
106
- const handleInitialFocus = useEventCallback(() => {
107
- if (data && value !== null) {
108
- if (getSelectedIndex)
109
- return getSelectedIndex(value);
110
- if (Array.isArray(value)) {
111
- const lastSelectedItem = value.at(-1);
112
- return lastSelectedItem ? data.indexOf(lastSelectedItem) : -1;
113
- }
114
- return data.findIndex((v) => v === value);
115
- }
116
- return true;
117
- });
118
- const handleMenuListChange = useEventCallback((newValue) => {
119
- setValue(newValue);
120
- if (inputRef.current) {
121
- Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set?.call(inputRef.current, newValue);
122
- const event = new Event('input', { bubbles: true });
123
- Object.defineProperty(event, 'target', {
124
- configurable: true,
125
- get: () => {
126
- return new Proxy(inputRef.current, {
127
- get(obj, prop) {
128
- if (prop === 'value') {
129
- return newValue;
130
- }
131
- return obj[prop];
132
- },
133
- });
134
- },
135
- });
136
- inputRef.current?.dispatchEvent(event);
137
- }
138
- });
139
- const { getButtonProps, getListboxProps } = useSelect({
140
- open,
141
- handleOpen,
142
- });
143
- const { contextValue: virtualizedContextValue } = useMenuItemSelect({
144
- value,
145
- onChange: handleMenuListChange,
146
- onClose: handleClose,
147
- selectMode,
148
- });
149
- const virtualizedMenuContextValue = useMemo(() => ({
150
- close: handleClose,
151
- autoFocus: true,
152
- }), [handleClose]);
153
- const selectorProps = getButtonProps(combineProps({
154
- onMouseDown: (event) => {
155
- if (disabled || event.button !== 0)
156
- return;
157
- event.preventDefault();
158
- event.currentTarget.focus();
159
- },
160
- }, selectorPropsProp));
161
- const selectedValue = value !== null || displayEmpty ? renderValue(value) : null;
162
- const valueId = `${id}-value`;
163
- const labelId = `${id}-label`;
164
- let menu = null;
165
- const baseMenuClasses = { paper: cls('menu') };
166
- const basePopperProps = { offset: 4, matchAnchorWidth: true };
167
- const popperProps = combineProps(basePopperProps, !virtualize
168
- ? MenuProps?.PopperProps
169
- : virtualizedMenuPropsProp?.PopperProps);
170
- const menuClasses = popperProps.matchAnchorWidth
171
- ? combineClasses(baseMenuClasses, { paper: 'min-w-0' })
172
- : baseMenuClasses;
173
- const onExitComplete = () => {
174
- setDidMenuExit(true);
175
- };
176
- const baseMenuProps = {
177
- onExitComplete,
178
- placement: DEFAULT_PLACEMENT,
179
- open,
180
- anchorEl,
181
- PopperProps: basePopperProps,
182
- classes: menuClasses,
183
- onClose: handleClose,
184
- };
185
- if (!virtualize) {
186
- menu = (jsx(Menu, { ...baseMenuProps, ...MenuProps, PopperProps: popperProps, classes: combineClasses(menuClasses, MenuProps?.classes), motionProps: getYAxisGrowMotion({
187
- placement: MenuProps?.placement,
188
- prefersReducedMotion: prefersReducedMotion,
189
- }), children: jsx(MenuList, { value: value, onChange: handleMenuListChange, nowrap: false, widget: "select", selectMode: selectMode, ...getListboxProps(), children: children }) }));
190
- }
191
- else {
192
- menu = (jsx(MenuContext.Provider, { value: virtualizedMenuContextValue, children: jsx(MenuItemSelectContext.Provider, { value: virtualizedContextValue, children: jsx(VirtualizedMenu, { ...baseMenuProps, ...virtualizedMenuPropsProp, PopperProps: popperProps, classes: combineClasses(baseMenuProps.classes, virtualizedMenuPropsProp?.classes), initialFocus: handleInitialFocus, data: data, motionProps: getYAxisGrowMotion({
193
- placement: virtualizedMenuPropsProp?.placement,
194
- prefersReducedMotion: prefersReducedMotion,
195
- }), children: children }) }) }));
196
- }
197
- return (jsxs(Fragment, { children: [jsxs(FormField, { disabled: disabled, required: required, variant: variant, error: error, focused: open || (!open && !didMenuExit), htmlFor: id, label: label, labelProps: {
198
- id: labelId,
199
- }, ref: ref, contentRef: formFieldContentRef, helperText: helperText, FormHelperTextProps: { id: helperTextId, ...FormHelperTextProps }, className: cls('root', { error }), classes: {
200
- outlined: cls('outlined'),
201
- standard: cls('standard'),
202
- contained: cls('contained'),
203
- content: cls('content'),
204
- }, size: size, ...rest, children: [jsxs("button", { className: cls('selector', `${variant}-selector`, `${variant}-selector-${size}`, {
205
- expanded: open,
206
- }), disabled: disabled, "aria-labelledby": label ? `${labelId} ${valueId}` : valueId, "aria-describedby": helperTextId, ...selectorProps, id: id, type: "button", children: [hasContent(selectedValue) ? (jsx("span", { id: valueId, "aria-live": "polite", className: cls('value'), title: getTitle(selectedValue), children: selectedValue })) : (jsx("span", { id: valueId, className: cls('placeholder'), title: getTitle(placeholder), children: placeholder })), jsx(Squircle, { className: cls('chevron'), interactive: false, children: jsx(ExpandCollapseCaret, { size: 'small', expanded: open }) })] }), jsx("input", { ref: inputRef, name: name, value: `${value}`, disabled: disabled, className: cls('native-input'), tabIndex: -1, "aria-hidden": true, "aria-invalid": error, onChange: handleInputChange, ...inputProps })] }), anchorEl && menu] }));
207
- });
208
- Select.displayName = 'SuiSelect';
209
- function getYAxisGrowMotion(params) {
210
- const { placement = DEFAULT_PLACEMENT, ...rest } = params;
211
- let verticalTransformOrigin = 'top';
212
- if (placement === 'top') {
213
- verticalTransformOrigin = 'bottom';
214
- }
215
- return getGrow({
216
- ...rest,
217
- direction: 'y',
218
- transformOrigin: {
219
- vertical: verticalTransformOrigin,
220
- horizontal: 'center',
221
- },
222
- });
223
- }
224
-
225
- export { Select as S, useSelect as u };