@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.
Files changed (241) hide show
  1. package/Accordion.js +90 -34
  2. package/AccordionHeader.js +72 -20
  3. package/Alert.js +120 -28
  4. package/Animation.js +2 -45
  5. package/Announcement.js +46 -35
  6. package/Autocomplete.js +1011 -580
  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 +55 -11
  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 -190
  23. package/DateUtilsContext.js +43 -25
  24. package/Dialer.js +576 -250
  25. package/Dialog.js +100 -45
  26. package/Divider.js +43 -7
  27. package/DragHandle.js +32 -6
  28. package/Drawer.js +117 -19
  29. package/Dropdown.js +154 -74
  30. package/EmptyState.js +63 -11
  31. package/FabButton.js +51 -17
  32. package/FocusTrap.js +109 -12
  33. package/FormField.js +106 -8
  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 -16
  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 -15
  50. package/MenuItem.js +402 -33
  51. package/MenuItemText.js +51 -8
  52. package/MenuList.js +87 -34
  53. package/Modal.js +345 -16
  54. package/NestedMenuContext.js +183 -11
  55. package/Option.js +32 -34
  56. package/Overlap.js +54 -7
  57. package/PageHeader.js +62 -24
  58. package/PickerTextField.js +156 -33
  59. package/Popover.js +262 -21
  60. package/Popper.js +130 -77
  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 -41
  67. package/SingleFilter.js +148 -77
  68. package/Skeleton.js +68 -17
  69. package/Slider.js +168 -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 +52 -28
  75. package/SplitButton.js +124 -86
  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 +68 -25
  82. package/StepIcon.js +90 -9
  83. package/StepLabel.js +90 -14
  84. package/Stepper.js +65 -23
  85. package/SubMenu.js +203 -99
  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 -77
  98. package/TableRow.js +60 -21
  99. package/Tabs.js +593 -268
  100. package/Tag.js +51 -16
  101. package/Text.js +68 -37
  102. package/TextField.js +209 -29
  103. package/Textarea.js +51 -40
  104. package/TimePicker.js +490 -230
  105. package/Tooltip.js +48 -23
  106. package/Tray.js +237 -13
  107. package/TrayMenu.js +62 -41
  108. package/VirtualizedList.js +208 -109
  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 +2624 -2416
  127. package/index.js +245 -193
  128. package/internal/utils/index.d.ts +1 -0
  129. package/internal/utils/setRef.d.ts +2 -0
  130. package/package.json +8 -8
  131. package/src/Alert/Alert.type.d.ts +2 -1
  132. package/src/Animation/components/Fade/Fade.d.ts +4 -2
  133. package/src/Animation/components/Grow/Grow.d.ts +4 -2
  134. package/src/Animation/components/ShowHideEye/ShowHideEye.d.ts +1 -1
  135. package/src/Animation/components/SlideIn/SlideIn.d.ts +4 -2
  136. package/src/Animation/components/SlideIn/getSlideIn.d.ts +1 -1
  137. package/src/Animation/hooks/useMotionSafeTransition/useMotionSafeTransition.d.ts +2 -0
  138. package/src/Autocomplete/SuggestionList/SuggestionList.d.ts +1 -1
  139. package/src/Autocomplete/useAutocomplete.d.ts +18 -18
  140. package/src/Autocomplete/useAutocompleteTag.d.ts +18 -18
  141. package/src/Badge/Badge.d.ts +2 -1
  142. package/src/Button/Button.classes.d.ts +1 -1
  143. package/src/ComponentsProps.d.ts +111 -110
  144. package/src/DatePicker/DatePickerDataAttributes.d.ts +11 -0
  145. package/src/DatePicker/utils/DatePickerAriaLabelUtils.d.ts +2 -1
  146. package/src/DatePicker/utils/DatePickerUtils.d.ts +1 -1
  147. package/src/Dialer/DialDelete/DialDelete.d.ts +2 -2
  148. package/src/Dialer/DialPad/DialPad.d.ts +2 -2
  149. package/src/Dialer/Dialer.d.ts +4 -2
  150. package/src/Dropdown/Dropdown.type.d.ts +2 -2
  151. package/src/InlineEditable/InlineEditable.type.d.ts +2 -1
  152. package/src/ListNavigation/useListNavigation.d.ts +3 -3
  153. package/src/MenuActions/MenuActions.d.ts +2 -2
  154. package/src/MenuItem/MenuItem.type.d.ts +1 -0
  155. package/src/MenuItem/useMenuItem.d.ts +1 -1
  156. package/src/MenuItem/useVirtualizedMenuItem.d.ts +1 -1
  157. package/src/MenuList/MenuList.type.d.ts +1 -1
  158. package/src/MenuList/MenuListContext.d.ts +2 -3
  159. package/src/Modal/Modal.type.d.ts +1 -0
  160. package/src/NestedMenuContext/MenuOverlayGroupContext.d.ts +2 -2
  161. package/src/Popover/Popover.classes.d.ts +1 -1
  162. package/src/Popover/Popover.internal.d.ts +8 -0
  163. package/src/Popover/Popover.type.d.ts +1 -0
  164. package/src/Popper/Popper.type.d.ts +10 -7
  165. package/src/Rating/utils.d.ts +3 -2
  166. package/src/Select/Select.type.d.ts +7 -5
  167. package/src/Slider/Slider.d.ts +2 -2
  168. package/src/Slider/SliderThumb.d.ts +2 -1
  169. package/src/Squircle/Squircle.d.ts +1 -1
  170. package/src/StatusIndicator/StatusIndicator.d.ts +2 -1
  171. package/src/SubMenu/PopperMenu.type.d.ts +4 -1
  172. package/src/Table/Table.type.d.ts +3 -0
  173. package/src/Table/TableContext.d.ts +3 -0
  174. package/src/Table/TableRowContext.d.ts +7 -0
  175. package/src/Table/index.d.ts +1 -0
  176. package/src/TableCell/TableCell.classes.d.ts +1 -1
  177. package/src/TableFooter/TableFooter.classes.d.ts +1 -1
  178. package/src/TableFooter/TableFooter.type.d.ts +1 -0
  179. package/src/TableHead/TableHead.classes.d.ts +1 -1
  180. package/src/TableHead/TableHead.type.d.ts +1 -0
  181. package/src/TableRow/TableRow.type.d.ts +2 -0
  182. package/chunks/AccordionContext.js +0 -6
  183. package/chunks/Alert.js +0 -48
  184. package/chunks/AvatarGroup.js +0 -22
  185. package/chunks/Backdrop.js +0 -18
  186. package/chunks/Badge.js +0 -32
  187. package/chunks/BottomNavigationItem.js +0 -36
  188. package/chunks/Button.js +0 -88
  189. package/chunks/Chip.js +0 -73
  190. package/chunks/CircularProgressIndicator.js +0 -36
  191. package/chunks/Divider.js +0 -19
  192. package/chunks/DragHandle.js +0 -11
  193. package/chunks/Drawer.js +0 -32
  194. package/chunks/ExpandCollapseCaret.js +0 -24
  195. package/chunks/FormLabel.js +0 -27
  196. package/chunks/Icon.js +0 -25
  197. package/chunks/IconButtonLabel.js +0 -68
  198. package/chunks/List.js +0 -22
  199. package/chunks/ListItem.js +0 -83
  200. package/chunks/Menu.js +0 -61
  201. package/chunks/MenuDivider.js +0 -14
  202. package/chunks/MenuItemText.js +0 -17
  203. package/chunks/MenuList.js +0 -46
  204. package/chunks/Modal.js +0 -212
  205. package/chunks/Overlap.js +0 -25
  206. package/chunks/PickerTextField.js +0 -85
  207. package/chunks/Popover.js +0 -53
  208. package/chunks/PopperPaper.js +0 -15
  209. package/chunks/Select.js +0 -220
  210. package/chunks/ShowHideEye.js +0 -56
  211. package/chunks/SlideIn.js +0 -19
  212. package/chunks/SortableArrow.js +0 -73
  213. package/chunks/Squircle.js +0 -31
  214. package/chunks/StatusIndicator.js +0 -20
  215. package/chunks/StepConnector.js +0 -21
  216. package/chunks/StepIcon.js +0 -43
  217. package/chunks/StepLabel.js +0 -29
  218. package/chunks/StepperContext.js +0 -9
  219. package/chunks/TableContext.js +0 -6
  220. package/chunks/Tablelvl2Context.js +0 -6
  221. package/chunks/TabsContext.js +0 -6
  222. package/chunks/TextField.js +0 -110
  223. package/chunks/Tooltip.js +0 -217
  224. package/chunks/VirtualizedMenu.js +0 -164
  225. package/chunks/VisuallyHidden.js +0 -12
  226. package/chunks/getFade.js +0 -27
  227. package/chunks/getGrow.js +0 -70
  228. package/chunks/getSlideIn.js +0 -30
  229. package/chunks/hasContent.js +0 -3
  230. package/chunks/useAnimationFrame.js +0 -15
  231. package/chunks/useFocusTrapStack.js +0 -36
  232. package/chunks/useHelperTextId.js +0 -22
  233. package/chunks/useListNavigation.js +0 -199
  234. package/chunks/useMenuItemSelect.js +0 -273
  235. package/chunks/useMotionSafeTransition.js +0 -9
  236. package/chunks/useNestedMenuItem.js +0 -27
  237. package/chunks/useNestedParentMenu.js +0 -113
  238. package/chunks/usePrefersReducedMotion.js +0 -36
  239. package/chunks/useTooltipForceHide.js +0 -27
  240. package/chunks/useTrayNavigate.js +0 -150
  241. package/chunks/withTooltip.js +0 -15
@@ -1,273 +0,0 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { createContext, useContext, forwardRef, useRef, useLayoutEffect, useCallback, useMemo } from 'react';
3
- import { useFocusVisible, useActive, useForkRef, useId, useHover, useEventCallback } from '@ringcentral/spring-base';
4
- import { CheckBoldMd } from '@ringcentral/spring-icon';
5
- import { useThemeProps, useClassesWithMode } from '@ringcentral/spring-theme';
6
- import { I as Icon } from './Icon.js';
7
- import { u as useAnimationFrame } from './useAnimationFrame.js';
8
- import './useNestedParentMenu.js';
9
- import { u as useNestedMenuItem } from './useNestedMenuItem.js';
10
- import { useVirtualizedItemPropsContext } from '../VirtualizedList.js';
11
- import { useItemNavigation } from '../ListNavigation.js';
12
- import { u as useMenuContext } from './Menu.js';
13
-
14
- const MenuListContext = createContext({
15
- nowrap: true,
16
- });
17
- const useMenuListContext = () => useContext(MenuListContext);
18
-
19
- const SubMenuTriggerNestedIdContext = createContext(null);
20
-
21
- const MenuItemSelectContext = createContext(null);
22
- const useMenuItemSelectContext = () => useContext(MenuItemSelectContext);
23
-
24
- const composeEventHandlers = (externalEventHandler, internalEventHandler, options = {}) => (event, ...args) => {
25
- const { checkForDefaultPrevented = true } = options;
26
- externalEventHandler?.(event, ...args);
27
- if (checkForDefaultPrevented && event.defaultPrevented) {
28
- return;
29
- }
30
- internalEventHandler?.(event, ...args);
31
- };
32
-
33
- const useMenuItem = (props) => {
34
- const { onBlur, onFocus, onKeyDown, onKeyUp, onClick, ref, disabled, autoClose, } = props;
35
- const { keyboardNavHandlers, itemRef } = useItemNavigation() ?? {};
36
- const { focusVisible, focusVisibleRef, focusVisibleHandlers } = useFocusVisible({
37
- onFocus: (e) => {
38
- keyboardNavHandlers?.onFocus(e);
39
- onFocus?.(e);
40
- },
41
- onBlur: (e) => {
42
- keyboardNavHandlers?.onBlur(e);
43
- onBlur?.(e);
44
- },
45
- });
46
- const { close: closeMenu } = useMenuContext() ?? {};
47
- const handleClick = disabled
48
- ? undefined
49
- : composeEventHandlers(onClick, () => {
50
- if (autoClose)
51
- closeMenu?.();
52
- });
53
- const { active, activeHandlers } = useActive({
54
- disabled,
55
- onKeyDown: (e) => {
56
- onKeyDown?.(e);
57
- keyboardNavHandlers?.onKeyDown(e);
58
- },
59
- onKeyUp,
60
- onClick: handleClick,
61
- });
62
- const handleItemRef = useForkRef(ref, focusVisibleRef, itemRef);
63
- const getRootProps = (otherProps) => {
64
- return {
65
- role: 'menuitem',
66
- tabIndex: '-1',
67
- disabled,
68
- ...otherProps,
69
- ...focusVisibleHandlers,
70
- ...activeHandlers,
71
- ref: handleItemRef,
72
- };
73
- };
74
- return { getRootProps, focusVisible, active };
75
- };
76
-
77
- const useVirtualizedMenuItem = (props) => {
78
- const { onBlur, onFocus, onKeyDown, onKeyUp, onClick, disabled, autoClose, ref, } = props;
79
- const { keyboardNavHandlers, itemRef } = useItemNavigation() ?? {};
80
- const vlItemProps = useVirtualizedItemPropsContext();
81
- const { focusVisible, focusVisibleRef, focusVisibleHandlers } = useFocusVisible({
82
- onFocus: (e) => {
83
- keyboardNavHandlers?.onFocus(e);
84
- onFocus?.(e);
85
- },
86
- onBlur: (e) => {
87
- keyboardNavHandlers?.onBlur(e);
88
- onBlur?.(e);
89
- },
90
- });
91
- const { close: closeMenu } = useMenuContext() ?? {};
92
- const handleClick = disabled
93
- ? undefined
94
- : composeEventHandlers(onClick, () => {
95
- if (autoClose)
96
- closeMenu?.();
97
- });
98
- const { active, activeHandlers } = useActive({
99
- disabled,
100
- onKeyDown: (e) => {
101
- onKeyDown?.(e);
102
- keyboardNavHandlers?.onKeyDown(e);
103
- },
104
- onKeyUp,
105
- onClick: handleClick,
106
- });
107
- const handleItemRef = useForkRef(ref, focusVisibleRef, itemRef);
108
- const getRootProps = (otherProps) => {
109
- return {
110
- role: 'menuitem',
111
- tabIndex: -1,
112
- ...otherProps,
113
- ...focusVisibleHandlers,
114
- ...activeHandlers,
115
- ...vlItemProps,
116
- ref: handleItemRef,
117
- };
118
- };
119
- return { getRootProps, focusVisible, active };
120
- };
121
-
122
- const MenuItem = forwardRef((inProps, ref) => {
123
- const props = useThemeProps({ props: inProps, name: 'MenuItem' });
124
- const { classes, className, children, selected, disabled, onMouseEnter, onMouseLeave, onPointerMove, highlighted = false, focused = false, autoClose = true, autoFocus, ...rest } = props;
125
- const cls = useClassesWithMode('menu-item', classes, className);
126
- const vlItemProps = useVirtualizedItemPropsContext();
127
- const isInVlRef = useRef(Boolean(vlItemProps));
128
- const { requestAnimationFrame } = useAnimationFrame();
129
- const useMenuItemHook = (() => {
130
- if (isInVlRef.current) {
131
- return useVirtualizedMenuItem;
132
- }
133
- else {
134
- return useMenuItem;
135
- }
136
- })();
137
- const itemRef = useRef(null);
138
- const handleRef = useForkRef(itemRef, ref);
139
- const { getRootProps, focusVisible, active } = useMenuItemHook({
140
- ...props,
141
- autoClose,
142
- ref: handleRef,
143
- });
144
- const selectable = !(selected === undefined);
145
- const selectContextValue = useMenuItemSelectContext();
146
- const menuListContextValue = useMenuListContext();
147
- const selectMode = selectContextValue
148
- ? selectContextValue.selectMode
149
- : 'single';
150
- const subMenuTriggerNestedId = useContext(SubMenuTriggerNestedIdContext);
151
- const generatedId = useId();
152
- const id = subMenuTriggerNestedId ?? generatedId;
153
- const isSubMenuTrigger = Boolean(subMenuTriggerNestedId);
154
- const { requestItemHover } = useNestedMenuItem({ id });
155
- const { hoverHandlers } = useHover({
156
- onMouseEnter,
157
- onMouseLeave,
158
- });
159
- const handlePointerMove = (event) => {
160
- if (event.pointerType === 'mouse' &&
161
- !requestItemHover(event, {
162
- closeOpenedSubMenu: !isSubMenuTrigger,
163
- })) {
164
- event.preventDefault();
165
- }
166
- onPointerMove?.(event);
167
- };
168
- useLayoutEffect(() => {
169
- if (autoFocus) {
170
- itemRef.current?.focus();
171
- requestAnimationFrame(() => {
172
- if (process.env.NODE_ENV === 'test' &&
173
- typeof itemRef.current?.scrollIntoView !== 'function') {
174
- return;
175
- }
176
- itemRef.current?.scrollIntoView({
177
- block: 'nearest',
178
- inline: 'nearest',
179
- });
180
- });
181
- }
182
- }, [autoFocus, requestAnimationFrame]);
183
- return (jsx("div", { className: cls('root', {
184
- selectable,
185
- selected,
186
- focusVisible,
187
- disabled,
188
- active,
189
- highlighted,
190
- focused,
191
- nowrap: menuListContextValue.nowrap,
192
- }), ...getRootProps(rest), ...hoverHandlers, onPointerMove: handlePointerMove, children: jsxs("div", { className: cls('container'), children: [selectable && (jsx("div", { className: cls('select-indicator'), children: selectMode === 'single' ? (jsx("span", { className: cls('select-dot') })) : (jsx(Icon, { symbol: CheckBoldMd, size: "small" })) })), children] }) }));
193
- });
194
- MenuItem.displayName = 'SuiMenuItem';
195
-
196
- var Action;
197
- (function (Action) {
198
- Action["SELECT"] = "select";
199
- Action["DESELECT"] = "deselect";
200
- })(Action || (Action = {}));
201
- const useMenuItemSelect = (props) => {
202
- const { widget = 'menu', selectMode = 'single', value: valueProp = selectMode === 'single' ? null : [], onChange, onClose, autoFocus: autoFocusProp = true, } = props;
203
- const isSingleMode = selectMode === 'single';
204
- if (process.env.NODE_ENV !== 'production' &&
205
- !isSingleMode &&
206
- !Array.isArray(valueProp)) {
207
- throw Error('SPRING [useMenuItemSelect]: value must be an array if selectMode is multiple');
208
- }
209
- const value = valueProp;
210
- const getMenuItemProps = useCallback((itemValue) => {
211
- let selected;
212
- let autoFocus;
213
- if (isSingleMode) {
214
- selected = value === itemValue;
215
- autoFocus = selected;
216
- }
217
- else {
218
- selected = value.includes(itemValue);
219
- autoFocus = value[0] === itemValue;
220
- }
221
- const menuItemRole = selectMode === 'single' ? 'menuitemradio' : 'menuitemcheckbox';
222
- const ariaProps = widget === 'menu'
223
- ? { 'aria-checked': selected }
224
- : { 'aria-selected': selected };
225
- return {
226
- role: widget === 'menu' ? menuItemRole : 'option',
227
- ...ariaProps,
228
- selected,
229
- autoFocus: autoFocusProp && autoFocus,
230
- };
231
- }, [isSingleMode, selectMode, widget, autoFocusProp, value]);
232
- const handleSelect = useEventCallback((itemValue) => {
233
- let action = Action.SELECT;
234
- if (isSingleMode) {
235
- if (value === itemValue) {
236
- onClose?.();
237
- }
238
- else {
239
- onChange?.(itemValue);
240
- }
241
- }
242
- else {
243
- const index = value.indexOf(itemValue);
244
- let newValue;
245
- if (index >= 0) {
246
- action = Action.DESELECT;
247
- newValue = [
248
- ...value.slice(0, index),
249
- ...value.slice(index + 1),
250
- ];
251
- }
252
- else {
253
- newValue = [...value, itemValue];
254
- }
255
- onChange?.(newValue, {
256
- value: itemValue,
257
- action,
258
- });
259
- }
260
- });
261
- const contextValue = useMemo(() => ({
262
- selectMode,
263
- value,
264
- handleSelect,
265
- getMenuItemProps,
266
- }), [getMenuItemProps, handleSelect, selectMode, value]);
267
- return {
268
- value,
269
- contextValue,
270
- };
271
- };
272
-
273
- export { Action as A, MenuItem as M, SubMenuTriggerNestedIdContext as S, MenuItemSelectContext as a, useMenuItem as b, useMenuItemSelect as c, useVirtualizedMenuItem as d, MenuListContext as e, useMenuListContext as f, composeEventHandlers as g, useMenuItemSelectContext as u };
@@ -1,9 +0,0 @@
1
- import { motionTransition } from '@ringcentral/spring-theme';
2
- import { u as usePrefersReducedMotion } from './usePrefersReducedMotion.js';
3
-
4
- const useMotionSafeTransition = (transition) => {
5
- const prefersReducedMotion = usePrefersReducedMotion();
6
- return prefersReducedMotion ? motionTransition.instant : transition;
7
- };
8
-
9
- export { useMotionSafeTransition as u };
@@ -1,27 +0,0 @@
1
- import { useCallback, useEffect } from 'react';
2
- import { u as useNestedMenuContext } from './useNestedParentMenu.js';
3
-
4
- const useNestedMenuItem = (props) => {
5
- const context = useNestedMenuContext();
6
- const { hovered, id } = props;
7
- const { isPointerMovingToSubMenu: isPointerMovingToSubMenuContext, onPointerGraceIntentChange, registHoveredItem, } = context ?? {};
8
- const requestItemHover = useCallback((event, options) => {
9
- const canApplyHover = registHoveredItem?.(id, event, options);
10
- return canApplyHover ?? true;
11
- }, [id, registHoveredItem]);
12
- useEffect(() => {
13
- if (hovered) {
14
- requestItemHover();
15
- }
16
- }, [hovered, requestItemHover]);
17
- const isPointerMovingToSubMenu = useCallback((event, intent) => {
18
- return isPointerMovingToSubMenuContext?.(event, intent) ?? false;
19
- }, [isPointerMovingToSubMenuContext]);
20
- return {
21
- isPointerMovingToSubMenu,
22
- onPointerGraceIntentChange,
23
- requestItemHover,
24
- };
25
- };
26
-
27
- export { useNestedMenuItem as u };
@@ -1,113 +0,0 @@
1
- import { createContext, useContext, useRef, useCallback, useMemo, useLayoutEffect } from 'react';
2
-
3
- const NestedMenuContext = createContext(null);
4
- const useNestedMenuContext = () => {
5
- return useContext(NestedMenuContext);
6
- };
7
-
8
- const getPointFromPointerEvent = (event) => ({
9
- x: event.clientX,
10
- y: event.clientY,
11
- });
12
- const isPointInPolygon = (point, polygon) => {
13
- let inside = false;
14
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
15
- const pointI = polygon[i];
16
- const pointJ = polygon[j];
17
- const intersects = pointI.y > point.y !== pointJ.y > point.y &&
18
- point.x <
19
- ((pointJ.x - pointI.x) * (point.y - pointI.y)) / (pointJ.y - pointI.y) +
20
- pointI.x;
21
- if (intersects) {
22
- inside = !inside;
23
- }
24
- }
25
- return inside;
26
- };
27
- const isPointerInGraceArea = (event, area) => {
28
- if (!area)
29
- return false;
30
- return isPointInPolygon(getPointFromPointerEvent(event), area);
31
- };
32
-
33
- const useNestedParentMenu = (props) => {
34
- const openedSubMenuSymbolRef = useRef(null);
35
- const pointerGraceIntentRef = useRef(null);
36
- const pointerDirRef = useRef('right');
37
- const lastPointerXRef = useRef(0);
38
- const { open } = props;
39
- const onPointerGraceIntentChange = useCallback((intent) => {
40
- pointerGraceIntentRef.current = intent;
41
- }, []);
42
- const isPointerMovingToSubMenu = useCallback((event, intentArg) => {
43
- const intent = intentArg === undefined ? pointerGraceIntentRef.current : intentArg;
44
- const isMovingTowards = pointerDirRef.current === intent?.side;
45
- return isMovingTowards && isPointerInGraceArea(event, intent?.area);
46
- }, []);
47
- const onContentPointerMove = useCallback((event) => {
48
- const pointerXHasChanged = lastPointerXRef.current !== event.clientX;
49
- if (pointerXHasChanged) {
50
- pointerDirRef.current =
51
- event.clientX > lastPointerXRef.current ? 'right' : 'left';
52
- lastPointerXRef.current = event.clientX;
53
- }
54
- }, []);
55
- const onContentClickCapture = useCallback((event) => {
56
- const target = event.target;
57
- const openedSubMenu = openedSubMenuSymbolRef.current;
58
- if (!target || !event.currentTarget.contains(target)) {
59
- return;
60
- }
61
- if (openedSubMenu?.getAnchorElement?.()?.contains(target)) {
62
- return;
63
- }
64
- openedSubMenu?.closeSubMenu();
65
- }, []);
66
- const contextValue = useMemo(() => {
67
- return {
68
- registHoveredItem: (id, event, options) => {
69
- const symbol = openedSubMenuSymbolRef.current;
70
- if (!symbol || id === symbol.anchorId) {
71
- return true;
72
- }
73
- if (event && isPointerMovingToSubMenu(event)) {
74
- return false;
75
- }
76
- if (options?.closeOpenedSubMenu ?? true) {
77
- symbol.closeSubMenu();
78
- }
79
- return true;
80
- },
81
- registOpenedSubMenu: (menuItemSymbol) => {
82
- openedSubMenuSymbolRef.current?.closeSubMenu();
83
- openedSubMenuSymbolRef.current = menuItemSymbol;
84
- return () => {
85
- if (openedSubMenuSymbolRef.current === menuItemSymbol) {
86
- openedSubMenuSymbolRef.current = null;
87
- }
88
- };
89
- },
90
- isPointerMovingToSubMenu,
91
- onPointerGraceIntentChange,
92
- };
93
- }, [isPointerMovingToSubMenu, onPointerGraceIntentChange]);
94
- useLayoutEffect(() => {
95
- if (!open) {
96
- openedSubMenuSymbolRef.current?.closeSubMenu();
97
- openedSubMenuSymbolRef.current = null;
98
- onPointerGraceIntentChange(null);
99
- }
100
- }, [onPointerGraceIntentChange, open]);
101
- return {
102
- contentClickHandlers: {
103
- onClickCapture: onContentClickCapture,
104
- },
105
- contentPointerHandlers: {
106
- onPointerMove: onContentPointerMove,
107
- },
108
- contextValue,
109
- getHaveOpenedSubMenu: () => Boolean(openedSubMenuSymbolRef.current),
110
- };
111
- };
112
-
113
- export { NestedMenuContext as N, useNestedParentMenu as a, useNestedMenuContext as u };
@@ -1,36 +0,0 @@
1
- import { useGlobalListener } from '@ringcentral/spring-base';
2
- import { MotionConfigContext } from 'framer-motion';
3
- import { useState, useContext } from 'react';
4
-
5
- let instance;
6
- const getPrefersReducedMotionMediaQuery = () => {
7
- if (!instance ||
8
- process.env.NODE_ENV === 'test') {
9
- instance = window?.matchMedia?.('(prefers-reduced-motion)');
10
- }
11
- return instance;
12
- };
13
- const usePrefersReducedMotion = () => {
14
- const mediaQuery = getPrefersReducedMotionMediaQuery();
15
- const [shouldReduceMotion, setShouldReduceMotion] = useState(mediaQuery?.matches || false);
16
- const context = useContext(MotionConfigContext);
17
- useGlobalListener('change', ((event) => {
18
- setShouldReduceMotion(event.matches);
19
- }), {
20
- target: mediaQuery,
21
- customKey: 'prefers-reduced-motion',
22
- });
23
- if (context.reducedMotion === 'user') {
24
- return shouldReduceMotion;
25
- }
26
- if (context.reducedMotion === 'always' ||
27
- process.env.NODE_ENV === 'test') {
28
- return true;
29
- }
30
- if (context.reducedMotion === 'never') {
31
- return false;
32
- }
33
- return shouldReduceMotion;
34
- };
35
-
36
- export { usePrefersReducedMotion as u };
@@ -1,27 +0,0 @@
1
- import { useState, useRef, useCallback, useEffect } from 'react';
2
-
3
- const useTooltipForceHide = (forceHide) => {
4
- const [open, setOpen] = useState(false);
5
- const openStateStore = useRef();
6
- const onOpenStateChange = useCallback((event, isOpen) => {
7
- if (openStateStore.current !== undefined) {
8
- openStateStore.current = isOpen;
9
- }
10
- else {
11
- setOpen(isOpen);
12
- }
13
- }, []);
14
- useEffect(() => {
15
- if (open && forceHide) {
16
- setOpen(false);
17
- openStateStore.current = open;
18
- }
19
- if (!forceHide && openStateStore.current !== undefined) {
20
- setOpen(openStateStore.current);
21
- openStateStore.current = undefined;
22
- }
23
- }, [open, forceHide]);
24
- return { open, onOpenStateChange };
25
- };
26
-
27
- export { useTooltipForceHide as u };
@@ -1,150 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useState, useMemo, createContext, useContext, forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
3
- import { useControlled, useEventCallback, logInDev, useClasses, useForkRef } from '@ringcentral/spring-base';
4
- import { useThemeProps, motionTransition } from '@ringcentral/spring-theme';
5
- import { AnimatePresence, motion } from 'framer-motion';
6
- import './Icon.js';
7
- import { u as useMotionSafeTransition } from './useMotionSafeTransition.js';
8
-
9
- const useTray = (parameters) => {
10
- const { value: valueProp, defaultValue, onChange, containerRef } = parameters;
11
- const [value, setValue] = useControlled({
12
- controlled: valueProp,
13
- default: defaultValue,
14
- name: 'useTray',
15
- state: 'value',
16
- });
17
- if (value === undefined) {
18
- throw new Error('Should set default TrayPanel using defaultValue (not controlled) or value (controlled)');
19
- }
20
- const [stack, setStack] = useState([value]);
21
- const [direction, setDirection] = useState('right');
22
- const updateValue = (e, newValue) => {
23
- setValue(newValue);
24
- onChange?.(e, newValue);
25
- if (stack.includes(newValue)) {
26
- setStack(stack.slice(0, stack.indexOf(newValue) + 1));
27
- setDirection('left');
28
- }
29
- else {
30
- setStack([...stack, newValue]);
31
- setDirection('right');
32
- }
33
- };
34
- const navigateTo = useEventCallback((newValue, event = null) => {
35
- let handledValue = newValue;
36
- if (handledValue === null && stack.length === 1) {
37
- if (process.env.NODE_ENV !== 'production') {
38
- logInDev({
39
- scope: 'useTray',
40
- message: 'No TrayPanel left to return to',
41
- });
42
- }
43
- return;
44
- }
45
- if (handledValue === null) {
46
- handledValue = stack[stack.length - 2];
47
- }
48
- containerRef.current?.focus();
49
- updateValue(event, handledValue);
50
- });
51
- const trayContextValue = useMemo(() => {
52
- return {
53
- value,
54
- navigateTo,
55
- direction,
56
- containerRef,
57
- };
58
- }, [value, navigateTo, direction, containerRef]);
59
- return {
60
- trayContextValue,
61
- };
62
- };
63
-
64
- const TrayContext = createContext(null);
65
- const useTrayContext = () => useContext(TrayContext);
66
-
67
- const Tray = forwardRef((inProps, ref) => {
68
- const props = useThemeProps({ props: inProps, name: 'Tray' });
69
- const { classes, children, value, defaultValue, onChange, actions, className, ...rest } = props;
70
- const cls = useClasses('tray', classes, className);
71
- const rootRef = useRef(null);
72
- const handleRootRef = useForkRef(ref, rootRef);
73
- const { trayContextValue } = useTray({
74
- value,
75
- defaultValue,
76
- onChange,
77
- containerRef: rootRef,
78
- });
79
- const { navigateTo } = trayContextValue;
80
- useImperativeHandle(actions, () => ({
81
- navigateTo,
82
- }), [navigateTo]);
83
- return (jsx("div", { className: cls('root'), ref: handleRootRef, ...rest, tabIndex: -1, children: jsx(TrayContext.Provider, { value: trayContextValue, children: children }) }));
84
- });
85
- Tray.displayName = 'SuiTray';
86
-
87
- const useTrayPanel = (parameters) => {
88
- const { value } = parameters;
89
- const context = useTrayContext();
90
- if (context === null) {
91
- throw new Error('No TrayContext provided, must be used within a Tray');
92
- }
93
- const activated = value === context.value;
94
- return {
95
- activated,
96
- containerRef: context.containerRef,
97
- direction: context.direction,
98
- };
99
- };
100
-
101
- const TrayPanel = forwardRef((inProps, ref) => {
102
- const props = useThemeProps({ props: inProps, name: 'TrayPanel' });
103
- const { children, classes, className } = props;
104
- const { activated, containerRef, direction } = useTrayPanel(props);
105
- const [display, setDisplay] = useState(activated);
106
- useEffect(() => {
107
- if (activated) {
108
- setDisplay(true);
109
- }
110
- }, [activated]);
111
- const cls = useClasses('tray-panel', classes, className);
112
- const transition = useMotionSafeTransition(motionTransition['spring-01-fast']);
113
- return (jsx(AnimatePresence, { initial: false, children: display && (jsx(motion.div, { ref: ref, className: cls('root', { activated }), "data-activated": activated, transition: transition, initial: 'enter', animate: activated ? 'center' : 'exit', onAnimationComplete: () => {
114
- !activated && setDisplay(false);
115
- }, variants: {
116
- enter: {
117
- height: containerRef.current?.querySelector('[data-activated="false"]')?.offsetHeight,
118
- transform: direction === 'right'
119
- ? 'translateX(100%)'
120
- : 'translateX(-100%)',
121
- },
122
- center: {
123
- height: 'auto',
124
- transform: 'translateX(0%)',
125
- },
126
- exit: {
127
- transform: direction === 'right'
128
- ? 'translateX(-100%)'
129
- : 'translateX(100%)',
130
- },
131
- }, children: children })) }));
132
- });
133
- TrayPanel.displayName = 'SuiTrayPanel';
134
-
135
- const useTrayNavigate = () => {
136
- const context = useTrayContext();
137
- if (context === null) {
138
- throw new Error('No TrayContext provided, must be used within a Tray');
139
- }
140
- const { navigateTo } = context;
141
- const back = (event = null) => {
142
- context.navigateTo(null, event);
143
- };
144
- return {
145
- navigateTo,
146
- back,
147
- };
148
- };
149
-
150
- export { Tray as T, TrayContext as a, TrayPanel as b, useTray as c, useTrayNavigate as d, useTrayPanel as e, useTrayContext as u };
@@ -1,15 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { forwardRef } from 'react';
3
- import { T as Tooltip } from './Tooltip.js';
4
-
5
- function withTooltip(Component) {
6
- return forwardRef((props, ref) => {
7
- const { TooltipProps, ...rest } = props;
8
- const content = jsx(Component, { ...rest, ref: ref });
9
- if (!TooltipProps)
10
- return content;
11
- return jsx(Tooltip, { ...TooltipProps, children: content });
12
- });
13
- }
14
-
15
- export { withTooltip as w };