@laser-ui/components 1.6.0 → 2.0.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 (297) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/accordion/Accordion.d.ts +1 -1
  3. package/accordion/Accordion.js +13 -25
  4. package/accordion/types.d.ts +1 -0
  5. package/affix/Affix.d.ts +2 -2
  6. package/affix/Affix.js +27 -32
  7. package/affix/types.d.ts +7 -2
  8. package/alert/Alert.d.ts +1 -1
  9. package/alert/Alert.js +12 -21
  10. package/anchor/Anchor.d.ts +2 -4
  11. package/anchor/Anchor.js +34 -26
  12. package/anchor/types.d.ts +1 -0
  13. package/avatar/Avatar.d.ts +1 -1
  14. package/avatar/Avatar.js +9 -3
  15. package/badge/Badge.d.ts +1 -1
  16. package/badge/Badge.js +22 -41
  17. package/badge/BadgeText.js +12 -26
  18. package/badge/internal/BadgeNumber.d.ts +2 -2
  19. package/badge/internal/BadgeNumber.js +34 -24
  20. package/base-input/BaseInput.d.ts +1 -2
  21. package/base-input/BaseInput.js +4 -4
  22. package/base-input/types.d.ts +1 -0
  23. package/breadcrumb/Breadcrumb.d.ts +1 -1
  24. package/button/Button.d.ts +1 -2
  25. package/button/Button.js +18 -22
  26. package/button/types.d.ts +1 -0
  27. package/card/Card.d.ts +1 -1
  28. package/card/CardAction.d.ts +1 -1
  29. package/card/CardAction.js +3 -4
  30. package/card/CardActions.d.ts +1 -1
  31. package/card/CardActions.js +7 -3
  32. package/card/CardContent.d.ts +1 -1
  33. package/card/CardHeader.d.ts +1 -1
  34. package/card/types.d.ts +5 -1
  35. package/cascader/Cascader.d.ts +2 -4
  36. package/cascader/Cascader.js +217 -214
  37. package/cascader/internal/CascaderPanel.d.ts +2 -2
  38. package/cascader/internal/CascaderPanel.js +21 -7
  39. package/cascader/internal/CascaderSearchPanel.d.ts +2 -2
  40. package/cascader/internal/CascaderSearchPanel.js +15 -6
  41. package/cascader/types.d.ts +3 -3
  42. package/checkbox/Checkbox.d.ts +1 -1
  43. package/checkbox/Checkbox.js +4 -5
  44. package/checkbox/CheckboxGroup.d.ts +1 -1
  45. package/checkbox/CheckboxGroup.js +8 -7
  46. package/checkbox/types.d.ts +14 -4
  47. package/{internal/circular-progress → circular-progress}/CircularProgress.d.ts +1 -1
  48. package/{internal/circular-progress → circular-progress}/CircularProgress.js +2 -2
  49. package/compose/Compose.d.ts +1 -1
  50. package/compose/ComposeItem.d.ts +1 -1
  51. package/config-provider/ConfigProvider.d.ts +1 -1
  52. package/config-provider/ConfigProvider.js +3 -3
  53. package/date-picker/DatePicker.d.ts +2 -2
  54. package/date-picker/DatePicker.js +116 -98
  55. package/date-picker/internal/DatePickerPanel.d.ts +2 -1
  56. package/date-picker/internal/DatePickerPanel.js +4 -4
  57. package/date-picker/types.d.ts +3 -3
  58. package/dialog-service.d.ts +9 -6
  59. package/dialog-service.js +50 -26
  60. package/drawer/Drawer.d.ts +1 -1
  61. package/drawer/Drawer.js +83 -92
  62. package/drawer/DrawerFooter.d.ts +1 -1
  63. package/drawer/DrawerFooter.js +12 -9
  64. package/drawer/DrawerHeader.d.ts +1 -1
  65. package/drawer/DrawerHeader.js +10 -7
  66. package/drawer/types.d.ts +9 -2
  67. package/drawer/vars.d.ts +5 -1
  68. package/drawer/vars.js +1 -1
  69. package/dropdown/Dropdown.d.ts +2 -4
  70. package/dropdown/Dropdown.js +83 -104
  71. package/dropdown/internal/DropdownGroup.d.ts +1 -1
  72. package/dropdown/internal/DropdownItem.d.ts +1 -1
  73. package/dropdown/internal/DropdownSub.d.ts +2 -1
  74. package/dropdown/internal/DropdownSub.js +26 -49
  75. package/dropdown/types.d.ts +15 -2
  76. package/empty/Empty.d.ts +1 -1
  77. package/fab/Fab.d.ts +1 -1
  78. package/fab/Fab.js +19 -14
  79. package/fab/FabBacktop.d.ts +1 -1
  80. package/fab/FabBacktop.js +24 -31
  81. package/fab/FabButton.d.ts +1 -1
  82. package/fab/FabButton.js +37 -10
  83. package/fab/types.d.ts +6 -2
  84. package/fab/vars.d.ts +14 -0
  85. package/fab/vars.js +4 -0
  86. package/form/Form.d.ts +1 -1
  87. package/form/Form.js +7 -2
  88. package/form/FormItem.d.ts +1 -1
  89. package/form/FormItem.js +35 -24
  90. package/form/internal/FormError.d.ts +3 -2
  91. package/form/internal/FormError.js +10 -19
  92. package/hooks/index.d.ts +0 -2
  93. package/hooks/index.js +0 -2
  94. package/hooks/useComponentProps.js +2 -2
  95. package/hooks/useFocusVisible.d.ts +9 -2
  96. package/hooks/useFocusVisible.js +5 -11
  97. package/hooks/useLayout.d.ts +2 -2
  98. package/hooks/useLayout.js +2 -2
  99. package/hooks/useNamespace.js +2 -2
  100. package/hooks/useNestedPopup.d.ts +1 -1
  101. package/hooks/useScopedProps.js +2 -2
  102. package/hooks/useStyled.js +2 -2
  103. package/hooks/useTranslation.js +2 -2
  104. package/icon/Icon.d.ts +1 -1
  105. package/icon/Icon.js +7 -4
  106. package/image/Image.d.ts +1 -1
  107. package/image/Image.js +6 -2
  108. package/image/ImageAction.d.ts +1 -1
  109. package/image/ImageAction.js +3 -4
  110. package/image/ImageLoader.d.ts +1 -1
  111. package/image/ImagePreview.d.ts +1 -1
  112. package/image/ImagePreview.js +95 -110
  113. package/image/types.d.ts +6 -2
  114. package/input/Input.d.ts +1 -1
  115. package/input/Input.js +12 -8
  116. package/input/InputNumber.js +49 -40
  117. package/input/types.d.ts +3 -5
  118. package/internal/lazy-loading/LazyLoading.d.ts +3 -0
  119. package/internal/lazy-loading/LazyLoading.js +9 -0
  120. package/internal/lazy-loading/index.d.ts +2 -0
  121. package/internal/lazy-loading/index.js +1 -0
  122. package/internal/lazy-loading/types.d.ts +7 -0
  123. package/internal/popup/Popup.d.ts +1 -1
  124. package/internal/popup/Popup.js +40 -68
  125. package/internal/popup/types.d.ts +13 -6
  126. package/internal/portal/Portal.d.ts +1 -1
  127. package/internal/portal/Portal.js +12 -6
  128. package/internal/portal/types.d.ts +3 -2
  129. package/mask/Mask.d.ts +3 -0
  130. package/mask/Mask.js +31 -0
  131. package/menu/Menu.d.ts +2 -4
  132. package/menu/Menu.js +37 -42
  133. package/menu/internal/MenuGroup.d.ts +1 -1
  134. package/menu/internal/MenuItem.d.ts +1 -1
  135. package/menu/internal/MenuItem.js +14 -10
  136. package/menu/internal/MenuSub.d.ts +2 -1
  137. package/menu/internal/MenuSub.js +43 -70
  138. package/menu/types.d.ts +1 -0
  139. package/modal/Modal.d.ts +1 -1
  140. package/modal/Modal.js +77 -80
  141. package/modal/ModalAlert.d.ts +1 -1
  142. package/modal/ModalFooter.d.ts +1 -1
  143. package/modal/ModalFooter.js +12 -9
  144. package/modal/ModalHeader.d.ts +1 -1
  145. package/modal/ModalHeader.js +10 -7
  146. package/modal/types.d.ts +9 -2
  147. package/modal/vars.d.ts +5 -0
  148. package/modal/vars.js +2 -0
  149. package/notification/Notification.d.ts +1 -1
  150. package/notification/Notification.js +44 -71
  151. package/notification/types.d.ts +1 -0
  152. package/package.json +2 -2
  153. package/pagination/Pagination.d.ts +1 -1
  154. package/pagination/Pagination.js +9 -6
  155. package/popover/Popover.d.ts +2 -2
  156. package/popover/Popover.js +82 -118
  157. package/popover/PopoverFooter.d.ts +1 -1
  158. package/popover/PopoverFooter.js +12 -9
  159. package/popover/PopoverHeader.d.ts +1 -1
  160. package/popover/PopoverHeader.js +10 -7
  161. package/popover/types.d.ts +18 -4
  162. package/popover/vars.d.ts +5 -0
  163. package/popover/vars.js +2 -0
  164. package/progress/Progress.d.ts +1 -1
  165. package/radio/Radio.d.ts +1 -1
  166. package/radio/Radio.js +18 -13
  167. package/radio/RadioGroup.d.ts +1 -1
  168. package/radio/RadioGroup.js +12 -7
  169. package/radio/types.d.ts +16 -4
  170. package/radio/vars.d.ts +6 -0
  171. package/radio/vars.js +2 -0
  172. package/rating/Rating.d.ts +1 -1
  173. package/rating/internal/RatingStar.d.ts +1 -1
  174. package/rating/internal/RatingStar.js +23 -21
  175. package/root/Root.d.ts +1 -1
  176. package/root/Root.js +1 -1
  177. package/select/Select.d.ts +2 -4
  178. package/select/Select.js +245 -243
  179. package/select/types.d.ts +3 -3
  180. package/separator/Separator.d.ts +1 -1
  181. package/skeleton/Skeleton.d.ts +1 -1
  182. package/slider/Slider.d.ts +1 -1
  183. package/slider/Slider.js +54 -34
  184. package/slider/types.d.ts +2 -3
  185. package/slides/Slides.d.ts +1 -1
  186. package/slides/Slides.js +8 -3
  187. package/spinner/Spinner.d.ts +1 -1
  188. package/spinner/Spinner.js +27 -29
  189. package/stepper/Stepper.d.ts +1 -1
  190. package/stepper/Stepper.js +9 -16
  191. package/switch/Switch.js +33 -24
  192. package/switch/types.d.ts +2 -3
  193. package/table/Table.d.ts +1 -1
  194. package/table/Table.js +14 -10
  195. package/table/TableEmpty.d.ts +1 -1
  196. package/table/TableEmpty.js +9 -3
  197. package/table/TableExpand.d.ts +1 -1
  198. package/table/TableFilter.d.ts +1 -1
  199. package/table/TableFilter.js +1 -1
  200. package/table/TableTd.d.ts +1 -1
  201. package/table/TableTh.d.ts +1 -1
  202. package/table/TableThAction.d.ts +1 -1
  203. package/table/TableThAction.js +3 -4
  204. package/table/internal/TableCell.d.ts +1 -1
  205. package/table/internal/TableCell.js +13 -5
  206. package/table/types.d.ts +9 -2
  207. package/tabs/Tabs.d.ts +2 -4
  208. package/tabs/Tabs.js +41 -25
  209. package/tabs/types.d.ts +1 -0
  210. package/tag/Tag.d.ts +1 -1
  211. package/textarea/Textarea.d.ts +1 -1
  212. package/textarea/Textarea.js +15 -8
  213. package/textarea/types.d.ts +1 -0
  214. package/time-picker/TimePicker.d.ts +2 -2
  215. package/time-picker/TimePicker.js +89 -75
  216. package/time-picker/internal/TimePickerPanel.d.ts +2 -1
  217. package/time-picker/internal/TimePickerPanel.js +22 -7
  218. package/time-picker/types.d.ts +3 -3
  219. package/timeline/Timeline.d.ts +1 -1
  220. package/toast/Toast.d.ts +1 -1
  221. package/toast/Toast.js +44 -72
  222. package/toast/types.d.ts +1 -0
  223. package/tooltip/Tooltip.d.ts +2 -2
  224. package/tooltip/Tooltip.js +50 -74
  225. package/tooltip/types.d.ts +10 -2
  226. package/transfer/Transfer.d.ts +1 -1
  227. package/transfer/internal/TransferPanel.d.ts +1 -1
  228. package/transfer/internal/TransferPanel.js +7 -2
  229. package/{internal/transition → transition}/CollapseTransition.d.ts +1 -1
  230. package/transition/CollapseTransition.js +65 -0
  231. package/transition/Transition.d.ts +3 -0
  232. package/transition/Transition.js +148 -0
  233. package/transition/types.d.ts +29 -0
  234. package/tree/Tree.d.ts +1 -1
  235. package/tree/Tree.js +19 -7
  236. package/tree/internal/TreePanel.d.ts +2 -2
  237. package/tree/internal/TreePanel.js +32 -26
  238. package/tree-select/TreeSelect.d.ts +2 -4
  239. package/tree-select/TreeSelect.js +216 -213
  240. package/tree-select/internal/TreeSelectSearchPanel.d.ts +2 -2
  241. package/tree-select/internal/TreeSelectSearchPanel.js +15 -6
  242. package/tree-select/types.d.ts +3 -3
  243. package/types.d.ts +1 -1
  244. package/upload/Upload.d.ts +1 -3
  245. package/upload/Upload.js +41 -50
  246. package/upload/UploadAction.d.ts +1 -1
  247. package/upload/UploadAction.js +19 -16
  248. package/upload/UploadButton.d.ts +1 -1
  249. package/upload/UploadButton.js +16 -12
  250. package/upload/UploadList.d.ts +1 -1
  251. package/upload/UploadList.js +52 -47
  252. package/upload/UploadPicture.d.ts +1 -1
  253. package/upload/UploadPicture.js +47 -53
  254. package/upload/UploadPictureList.d.ts +1 -1
  255. package/upload/UploadPictureList.js +52 -47
  256. package/upload/UploadPreviewAction.d.ts +1 -1
  257. package/upload/UploadPreviewAction.js +15 -14
  258. package/upload/hooks.d.ts +2 -0
  259. package/upload/types.d.ts +27 -6
  260. package/upload/vars.d.ts +11 -0
  261. package/upload/vars.js +3 -0
  262. package/virtual-scroll/VirtualScroll.d.ts +2 -4
  263. package/virtual-scroll/VirtualScroll.js +13 -21
  264. package/virtual-scroll/types.d.ts +2 -1
  265. package/wave/Wave.d.ts +3 -0
  266. package/{internal/wave → wave}/Wave.js +6 -6
  267. package/{internal/wave → wave}/types.d.ts +1 -0
  268. package/wave/types.js +1 -0
  269. package/hooks/useJSS.d.ts +0 -1
  270. package/hooks/useJSS.js +0 -15
  271. package/hooks/useNextTick.d.ts +0 -2
  272. package/internal/mask/Mask.d.ts +0 -3
  273. package/internal/mask/Mask.js +0 -36
  274. package/internal/transition/CollapseTransition.js +0 -101
  275. package/internal/transition/Transition.d.ts +0 -3
  276. package/internal/transition/Transition.js +0 -87
  277. package/internal/transition/types.d.ts +0 -33
  278. package/internal/wave/Wave.d.ts +0 -3
  279. /package/{internal/circular-progress → circular-progress}/index.d.ts +0 -0
  280. /package/{internal/circular-progress → circular-progress}/index.js +0 -0
  281. /package/{internal/circular-progress → circular-progress}/vars.d.ts +0 -0
  282. /package/{internal/circular-progress → circular-progress}/vars.js +0 -0
  283. /package/internal/{mask → lazy-loading}/types.js +0 -0
  284. /package/{internal/mask → mask}/index.d.ts +0 -0
  285. /package/{internal/mask → mask}/index.js +0 -0
  286. /package/{internal/mask → mask}/types.d.ts +0 -0
  287. /package/{internal/transition → mask}/types.js +0 -0
  288. /package/{internal/mask → mask}/vars.d.ts +0 -0
  289. /package/{internal/mask → mask}/vars.js +0 -0
  290. /package/{internal/transition → transition}/index.d.ts +0 -0
  291. /package/{internal/transition → transition}/index.js +0 -0
  292. /package/{internal/wave → transition}/types.js +0 -0
  293. /package/{hooks/useNextTick.js → upload/hooks.js} +0 -0
  294. /package/{internal/wave → wave}/index.d.ts +0 -0
  295. /package/{internal/wave → wave}/index.js +0 -0
  296. /package/{internal/wave → wave}/vars.d.ts +0 -0
  297. /package/{internal/wave → wave}/vars.js +0 -0
@@ -2,39 +2,36 @@ import { __rest } from "tslib";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEventCallback, useRefExtra } from '@laser-ui/hooks';
4
4
  import { scrollIntoViewIfNeeded } from '@laser-ui/utils';
5
- import { isFunction, isNull, isNumber, isUndefined, nth } from 'lodash';
6
- import { Fragment, cloneElement, forwardRef, useId, useImperativeHandle, useRef, useState } from 'react';
5
+ import { isNumber, isUndefined, nth } from 'lodash';
6
+ import { Fragment, useId, useImperativeHandle, useRef, useState } from 'react';
7
7
  import { DropdownGroup } from './internal/DropdownGroup';
8
8
  import { DropdownItem as DropdownItemFC } from './internal/DropdownItem';
9
9
  import { DropdownSub } from './internal/DropdownSub';
10
10
  import { checkEnableItem, getSameLevelEnableItems } from './utils';
11
11
  import { CLASSES } from './vars';
12
- import { useComponentProps, useContainerScrolling, useControlled, useFocusVisible, useJSS, useMaxIndex, useNamespace, useNestedPopup, useStyled, useTranslation, } from '../hooks';
12
+ import { useComponentProps, useContainerScrolling, useControlled, useFocusVisible, useMaxIndex, useNamespace, useNestedPopup, useStyled, useTranslation, } from '../hooks';
13
13
  import { Popup } from '../internal/popup';
14
14
  import { Portal } from '../internal/portal';
15
- import { Transition } from '../internal/transition';
16
15
  import { Separator } from '../separator';
16
+ import { Transition } from '../transition';
17
17
  import { getVerticalSidePosition, mergeCS } from '../utils';
18
18
  import { TTANSITION_DURING_POPUP, WINDOW_SPACE } from '../vars';
19
- function DropdownFC(props, ref) {
19
+ export function Dropdown(props) {
20
20
  var _a;
21
- const _b = useComponentProps('Dropdown', props), { children, styleOverrides, styleProvider, list, visible: visibleProp, defaultVisible, trigger = 'hover', placement: placementProp = 'bottom-right', placementFixed = false, arrow = false, escClosable = true, zIndex: zIndexProp, popupRender, onVisibleChange, afterVisibleChange, onClick } = _b, restProps = __rest(_b, ["children", "styleOverrides", "styleProvider", "list", "visible", "defaultVisible", "trigger", "placement", "placementFixed", "arrow", "escClosable", "zIndex", "popupRender", "onVisibleChange", "afterVisibleChange", "onClick"]);
21
+ const _b = useComponentProps('Dropdown', props), { ref, children, styleOverrides, styleProvider, list, visible: visibleProp, defaultVisible, trigger = 'hover', placement: placementProp = 'bottom-right', placementFixed = false, arrow = false, escClosable = true, zIndex: zIndexProp, popupRender, onVisibleChange, afterVisibleChange, onClick } = _b, restProps = __rest(_b, ["ref", "children", "styleOverrides", "styleProvider", "list", "visible", "defaultVisible", "trigger", "placement", "placementFixed", "arrow", "escClosable", "zIndex", "popupRender", "onVisibleChange", "afterVisibleChange", "onClick"]);
22
22
  const namespace = useNamespace();
23
23
  const { t } = useTranslation();
24
24
  const styled = useStyled(CLASSES, { dropdown: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.dropdown, 'dropdown-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['dropdown-popup'] }, styleOverrides);
25
- const sheet = useJSS();
26
25
  const uniqueId = useId();
27
26
  const id = (_a = restProps.id) !== null && _a !== void 0 ? _a : `${namespace}-dropdown-${uniqueId}`;
28
- let triggerId;
27
+ const triggerId = `${namespace}-dropdown-trigger-${uniqueId}`;
29
28
  const getItemId = (id) => `${namespace}-dropdown-item-${id}-${uniqueId}`;
30
29
  const triggerRef = useRefExtra(() => document.getElementById(triggerId));
31
30
  const popupRef = useRef(null);
32
31
  const ulRef = useRef(null);
33
32
  const dropdownRef = useRef(null);
34
- const dataRef = useRef({
35
- updatePosition: new Map(),
36
- });
37
- const [focusVisible, focusVisibleWrapper] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
33
+ const updateSubPosition = useRef(new Map());
34
+ const [focusVisible, focusVisibleProps] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
38
35
  const [visible, changeVisible] = useControlled(defaultVisible !== null && defaultVisible !== void 0 ? defaultVisible : false, visibleProp, onVisibleChange);
39
36
  const { popupIdsRef, setPopupIds, addPopupId, removePopupId } = useNestedPopup();
40
37
  if (!visible) {
@@ -92,7 +89,6 @@ function DropdownFC(props, ref) {
92
89
  };
93
90
  const maxZIndex = useMaxIndex(visible);
94
91
  const zIndex = !isUndefined(zIndexProp) ? zIndexProp : `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
95
- const transformOrigin = useRef();
96
92
  const placement = useRef(placementProp);
97
93
  const updatePosition = useEventCallback(() => {
98
94
  if (visible && triggerRef.current && dropdownRef.current && popupRef.current) {
@@ -102,18 +98,12 @@ function DropdownFC(props, ref) {
102
98
  placementFixed,
103
99
  inWindow: WINDOW_SPACE,
104
100
  });
105
- transformOrigin.current = position.transformOrigin;
101
+ popupRef.current.style.setProperty(`--popup-down-transform-origin`, position.transformOrigin);
102
+ popupRef.current.style.top = position.top + 'px';
103
+ popupRef.current.style.left = position.left + 'px';
106
104
  dropdownRef.current.classList.toggle(`${namespace}-dropdown--${placement.current}`, false);
107
105
  placement.current = position.placement;
108
106
  dropdownRef.current.classList.toggle(`${namespace}-dropdown--${placement.current}`, true);
109
- if (sheet.classes.position) {
110
- popupRef.current.classList.toggle(sheet.classes.position, false);
111
- }
112
- sheet.replaceRule('position', {
113
- top: position.top,
114
- left: position.left,
115
- });
116
- popupRef.current.classList.toggle(sheet.classes.position, true);
117
107
  }
118
108
  });
119
109
  const preventBlur = (e) => {
@@ -227,13 +217,13 @@ function DropdownFC(props, ref) {
227
217
  }
228
218
  };
229
219
  }
230
- return (_jsxs(Fragment, { children: [itemSeparator && _jsx(Separator, { style: { margin: '2px 0' } }), itemType === 'item' ? (_jsx(DropdownItemFC, { namespace: namespace, styled: styled, id: id, level: level, icon: itemIcon, focus: focusVisible && isFocus, disabled: itemDisabled, onClick: handleItemClick, children: itemTitle })) : itemType === 'group' ? (_jsx(DropdownGroup, { styled: styled, id: id, level: level, list: children && getNodes(children, level + 1, newSubParents), empty: isEmpty, children: itemTitle })) : (_jsx(DropdownSub, { ref: (fn) => {
231
- if (isNull(fn)) {
232
- dataRef.current.updatePosition.delete(itemId);
233
- }
234
- else {
235
- dataRef.current.updatePosition.set(itemId, fn);
236
- }
220
+ return (_jsxs(Fragment, { children: [itemSeparator && _jsx(Separator, { style: { margin: '2px 0' } }), itemType === 'item' ? (_jsx(DropdownItemFC, { namespace: namespace, styled: styled, id: id, level: level, icon: itemIcon, focus: focusVisible && isFocus, disabled: itemDisabled, onClick: handleItemClick, children: itemTitle })) : itemType === 'group' ? (_jsx(DropdownGroup, { styled: styled, id: id, level: level, list: children && getNodes(children, level + 1, newSubParents), empty: isEmpty, children: itemTitle })) : (_jsx(DropdownSub, { ref: (instance) => {
221
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
222
+ const fn = instance;
223
+ updateSubPosition.current.set(itemId, fn);
224
+ return () => {
225
+ updateSubPosition.current.delete(itemId);
226
+ };
237
227
  }, namespace: namespace, styled: styled, id: id, level: level, icon: itemIcon, list: children && getNodes(children, 0, newSubParents), popupState: popupState === null || popupState === void 0 ? void 0 : popupState.visible, trigger: trigger, empty: isEmpty, focus: focusVisible && isFocus, disabled: itemDisabled, zIndex: isUndefined(zIndex)
238
228
  ? zIndex
239
229
  : isNumber(zIndex)
@@ -255,40 +245,43 @@ function DropdownFC(props, ref) {
255
245
  return getNodes(list, 0, []);
256
246
  })();
257
247
  const updateAllPosition = useEventCallback(() => {
248
+ var _a;
258
249
  updatePosition();
259
- for (const fn of dataRef.current.updatePosition.values()) {
260
- fn();
250
+ for (const { id } of popupIds) {
251
+ (_a = updateSubPosition.current.get(id)) === null || _a === void 0 ? void 0 : _a();
261
252
  }
262
253
  });
263
254
  useContainerScrolling(triggerRef, updateAllPosition, !visible);
264
- useImperativeHandle(ref, () => ({ updatePosition: updateAllPosition }), [updateAllPosition]);
255
+ useImperativeHandle(ref, () => ({ updatePosition: updateAllPosition }), []);
265
256
  return (_jsx(Popup, { visible: visible, trigger: trigger, updatePosition: {
266
257
  fn: updatePosition,
267
258
  triggerRef,
268
259
  popupRef,
269
- }, onVisibleChange: changeVisible, children: ({ renderTrigger, renderPopup }) => {
270
- const render = (el) => {
271
- var _a, _b;
272
- triggerId = (_a = el.props.id) !== null && _a !== void 0 ? _a : `${namespace}-dropdown-trigger-${uniqueId}`;
273
- return renderTrigger(focusVisibleWrapper(cloneElement(el, {
260
+ }, onVisibleChange: changeVisible, children: (popupProps) => (_jsxs(_Fragment, { children: [children({
274
261
  id: triggerId,
275
- tabIndex: (_b = el.props.tabIndex) !== null && _b !== void 0 ? _b : 0,
262
+ tabIndex: 0,
276
263
  'aria-haspopup': 'menu',
277
264
  'aria-expanded': visible,
278
265
  'aria-controls': id,
266
+ onClick: (e) => {
267
+ popupProps.trigger.onClick(e);
268
+ },
269
+ onMouseEnter: (e) => {
270
+ popupProps.trigger.onMouseEnter(e);
271
+ },
272
+ onMouseLeave: (e) => {
273
+ popupProps.trigger.onMouseLeave(e);
274
+ },
279
275
  onFocus: (e) => {
280
- var _a, _b;
281
- (_b = (_a = el.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, e);
276
+ focusVisibleProps.onFocus(e);
282
277
  focusFirst();
283
278
  },
284
279
  onBlur: (e) => {
285
- var _a, _b;
286
- (_b = (_a = el.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, e);
280
+ focusVisibleProps.onBlur(e);
287
281
  changeVisible(false);
288
282
  },
289
283
  onKeyDown: (e) => {
290
- var _a, _b;
291
- (_b = (_a = el.props).onKeyDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
284
+ focusVisibleProps.onKeyDown(e);
292
285
  if (visible) {
293
286
  if (escClosable && e.code === 'Escape') {
294
287
  e.stopPropagation();
@@ -318,64 +311,50 @@ function DropdownFC(props, ref) {
318
311
  }
319
312
  }
320
313
  },
321
- })));
322
- };
323
- return (_jsxs(_Fragment, { children: [isFunction(children) ? children(render) : render(children), _jsx(Portal, { selector: () => {
324
- let el = document.getElementById(`${namespace}-dropdown-root`);
325
- if (!el) {
326
- el = document.createElement('div');
327
- el.id = `${namespace}-dropdown-root`;
328
- document.body.appendChild(el);
329
- }
330
- return el;
331
- }, children: _jsx(Transition, { enter: visible, during: TTANSITION_DURING_POPUP, afterRender: updatePosition, afterEnter: () => {
332
- afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
333
- }, afterLeave: () => {
334
- afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
335
- }, children: (state) => {
336
- let transitionStyle = {};
337
- switch (state) {
338
- case 'enter':
339
- transitionStyle = { transform: 'scaleY(0.7)', opacity: 0 };
340
- break;
341
- case 'entering':
342
- transitionStyle = {
343
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-out`).join(', '),
344
- transformOrigin: transformOrigin.current,
345
- };
346
- break;
347
- case 'leaving':
348
- transitionStyle = {
349
- transform: 'scaleY(0.7)',
350
- opacity: 0,
351
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-in`).join(', '),
352
- transformOrigin: transformOrigin.current,
353
- };
354
- break;
355
- case 'leaved':
356
- transitionStyle = { display: 'none' };
357
- break;
358
- default:
359
- break;
360
- }
361
- return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('dropdown'), {
362
- className: restProps.className,
363
- style: restProps.style,
364
- }), { ref: dropdownRef, onMouseDown: (e) => {
365
- var _a;
366
- (_a = restProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
367
- preventBlur(e);
368
- }, onMouseUp: (e) => {
369
- var _a;
370
- (_a = restProps.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
371
- preventBlur(e);
372
- }, children: renderPopup(_jsxs("div", Object.assign({}, mergeCS(styled('dropdown-popup'), {
373
- style: Object.assign({ zIndex }, transitionStyle),
374
- }), { ref: popupRef, children: [(() => {
375
- const el = (_jsx("ul", Object.assign({}, styled('dropdown__list'), { ref: ulRef, id: id, tabIndex: -1, role: "menu", "aria-labelledby": triggerId, "aria-activedescendant": isUndefined(focusId) ? undefined : getItemId(focusId), children: list.length === 0 ? _jsx("div", Object.assign({}, styled('dropdown__empty'), { children: t('No data') })) : nodes })));
376
- return popupRender ? popupRender(el) : el;
377
- })(), arrow && _jsx("div", Object.assign({}, styled('dropdown__arrow')))] }))) })));
378
- } }) })] }));
379
- } }));
314
+ }), _jsx(Portal, { selector: () => {
315
+ let el = document.getElementById(`${namespace}-dropdown-root`);
316
+ if (!el) {
317
+ el = document.createElement('div');
318
+ el.id = `${namespace}-dropdown-root`;
319
+ document.body.appendChild(el);
320
+ }
321
+ return el;
322
+ }, children: _jsx(Transition, { enter: visible, name: `${namespace}-popup-down`, duration: TTANSITION_DURING_POPUP, onSkipEnter: updatePosition, onBeforeEnter: updatePosition, onAfterEnter: () => {
323
+ afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
324
+ }, onAfterLeave: () => {
325
+ afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
326
+ }, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, restProps, mergeCS(styled('dropdown'), {
327
+ className: restProps.className,
328
+ style: Object.assign(Object.assign({}, restProps.style), (leaved ? { display: 'none' } : undefined)),
329
+ }), { ref: (instance) => {
330
+ dropdownRef.current = instance;
331
+ return () => {
332
+ dropdownRef.current = null;
333
+ };
334
+ }, onMouseDown: (e) => {
335
+ var _a;
336
+ (_a = restProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
337
+ preventBlur(e);
338
+ }, onMouseUp: (e) => {
339
+ var _a;
340
+ (_a = restProps.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
341
+ preventBlur(e);
342
+ }, children: _jsxs("div", Object.assign({}, mergeCS(styled('dropdown-popup'), {
343
+ style: Object.assign({ zIndex }, (leaved ? { display: 'none' } : undefined)),
344
+ }), { ref: (instance) => {
345
+ popupRef.current = instance;
346
+ transitionRef(instance);
347
+ return () => {
348
+ popupRef.current = null;
349
+ transitionRef(null);
350
+ };
351
+ } }, popupProps.popup, { children: [(() => {
352
+ const el = (_jsx("ul", Object.assign({}, styled('dropdown__list'), { ref: (instance) => {
353
+ ulRef.current = instance;
354
+ return () => {
355
+ ulRef.current = null;
356
+ };
357
+ }, id: id, tabIndex: -1, role: "menu", "aria-labelledby": triggerId, "aria-activedescendant": isUndefined(focusId) ? undefined : getItemId(focusId), children: list.length === 0 ? _jsx("div", Object.assign({}, styled('dropdown__empty'), { children: t('No data') })) : nodes })));
358
+ return popupRender ? popupRender(el) : el;
359
+ })(), arrow && _jsx("div", Object.assign({}, styled('dropdown__arrow')))] })) }))) }) })] })) }));
380
360
  }
381
- export const Dropdown = forwardRef(DropdownFC);
@@ -9,5 +9,5 @@ interface DropdownGroupProps {
9
9
  list: React.ReactNode;
10
10
  empty: boolean;
11
11
  }
12
- export declare function DropdownGroup(props: DropdownGroupProps): JSX.Element | null;
12
+ export declare function DropdownGroup(props: DropdownGroupProps): React.ReactElement | null;
13
13
  export {};
@@ -12,5 +12,5 @@ interface DropdownItemProps {
12
12
  disabled: boolean;
13
13
  onClick: () => void;
14
14
  }
15
- export declare function DropdownItem(props: DropdownItemProps): JSX.Element | null;
15
+ export declare function DropdownItem(props: DropdownItemProps): React.ReactElement | null;
16
16
  export {};
@@ -2,6 +2,7 @@
2
2
  import type { Styled } from '../../hooks/useStyled';
3
3
  import type { CLASSES } from '../vars';
4
4
  interface DropdownSubProps {
5
+ ref?: React.RefCallback<() => void>;
5
6
  children: React.ReactNode;
6
7
  namespace: string;
7
8
  styled: Styled<typeof CLASSES>;
@@ -17,5 +18,5 @@ interface DropdownSubProps {
17
18
  zIndex: number | string | undefined;
18
19
  onVisibleChange: (visible: boolean) => void;
19
20
  }
20
- export declare const DropdownSub: import("react").ForwardRefExoticComponent<DropdownSubProps & import("react").RefAttributes<() => void>>;
21
+ export declare function DropdownSub(props: DropdownSubProps): React.ReactElement | null;
21
22
  export {};
@@ -3,22 +3,20 @@ import { useEventCallback } from '@laser-ui/hooks';
3
3
  import { checkNodeExist } from '@laser-ui/utils';
4
4
  import KeyboardArrowRightOutlined from '@material-design-icons/svg/outlined/keyboard_arrow_right.svg?react';
5
5
  import { isUndefined } from 'lodash';
6
- import { forwardRef, useImperativeHandle, useRef } from 'react';
7
- import { useJSS, useTranslation } from '../../hooks';
6
+ import { useImperativeHandle, useRef } from 'react';
7
+ import { useTranslation } from '../../hooks';
8
8
  import { Icon } from '../../icon';
9
9
  import { Popup } from '../../internal/popup';
10
10
  import { Portal } from '../../internal/portal';
11
- import { Transition } from '../../internal/transition';
11
+ import { Transition } from '../../transition';
12
12
  import { getHorizontalSidePosition, mergeCS } from '../../utils';
13
13
  import { TTANSITION_DURING_POPUP, WINDOW_SPACE } from '../../vars';
14
- export const DropdownSub = forwardRef((props, ref) => {
15
- const { children, namespace, styled, id, level, icon, list, popupState, trigger, empty, focus, disabled, zIndex, onVisibleChange } = props;
16
- const sheet = useJSS();
14
+ export function DropdownSub(props) {
15
+ const { ref, children, namespace, styled, id, level, icon, list, popupState, trigger, empty, focus, disabled, zIndex, onVisibleChange } = props;
17
16
  const triggerRef = useRef(null);
18
17
  const popupRef = useRef(null);
19
18
  const { t } = useTranslation();
20
19
  const visible = !isUndefined(popupState);
21
- const transformOrigin = useRef();
22
20
  const updatePosition = useEventCallback(() => {
23
21
  if (!disabled && visible && popupRef.current && triggerRef.current) {
24
22
  const [width, height] = [popupRef.current.offsetWidth, popupRef.current.offsetHeight];
@@ -26,15 +24,9 @@ export const DropdownSub = forwardRef((props, ref) => {
26
24
  placement: 'right',
27
25
  inWindow: WINDOW_SPACE,
28
26
  });
29
- transformOrigin.current = position.transformOrigin;
30
- if (sheet.classes.position) {
31
- popupRef.current.classList.toggle(sheet.classes.position, false);
32
- }
33
- sheet.replaceRule('position', {
34
- top: position.top,
35
- left: position.left,
36
- });
37
- popupRef.current.classList.toggle(sheet.classes.position, true);
27
+ popupRef.current.style.setProperty(`--popup-transform-origin`, position.transformOrigin);
28
+ popupRef.current.style.top = position.top + 'px';
29
+ popupRef.current.style.left = position.left + 'px';
38
30
  }
39
31
  });
40
32
  useImperativeHandle(ref, () => updatePosition, [updatePosition]);
@@ -43,10 +35,15 @@ export const DropdownSub = forwardRef((props, ref) => {
43
35
  triggerRef,
44
36
  popupRef,
45
37
  scroll: false,
46
- }, onVisibleChange: onVisibleChange, children: ({ renderTrigger, renderPopup }) => (_jsxs(_Fragment, { children: [renderTrigger(_jsxs("li", Object.assign({}, mergeCS(styled('dropdown__item', 'dropdown__item--sub', {
38
+ }, onVisibleChange: onVisibleChange, children: (popupProps) => (_jsxs(_Fragment, { children: [_jsxs("li", Object.assign({}, mergeCS(styled('dropdown__item', 'dropdown__item--sub', {
47
39
  'dropdown__item.is-expand': visible,
48
40
  'dropdown__item.is-disabled': disabled,
49
- }), { style: { paddingLeft: 12 + level * 16 } }), { ref: triggerRef, id: id, role: "menuitem", "aria-haspopup": true, "aria-expanded": visible, "aria-disabled": disabled, children: [focus && _jsx("div", { className: `${namespace}-focus-outline` }), checkNodeExist(icon) && _jsx("div", Object.assign({}, styled('dropdown__item-icon'), { children: icon })), _jsx("div", Object.assign({}, styled('dropdown__item-content'), { children: children })), _jsx("div", Object.assign({}, styled('dropdown__sub-arrow'), { children: _jsx(Icon, { children: _jsx(KeyboardArrowRightOutlined, {}) }) }))] }))), _jsx(Portal, { selector: () => {
41
+ }), { style: { paddingLeft: 12 + level * 16 } }), { ref: (instance) => {
42
+ triggerRef.current = instance;
43
+ return () => {
44
+ triggerRef.current = null;
45
+ };
46
+ }, id: id, role: "menuitem", "aria-haspopup": true, "aria-expanded": visible, "aria-disabled": disabled }, popupProps.trigger, { children: [focus && _jsx("div", { className: `${namespace}-focus-outline` }), checkNodeExist(icon) && _jsx("div", Object.assign({}, styled('dropdown__item-icon'), { children: icon })), _jsx("div", Object.assign({}, styled('dropdown__item-content'), { children: children })), _jsx("div", Object.assign({}, styled('dropdown__sub-arrow'), { children: _jsx(Icon, { children: _jsx(KeyboardArrowRightOutlined, {}) }) }))] })), _jsx(Portal, { selector: () => {
50
47
  let el = document.getElementById(`${namespace}-dropdown-root`);
51
48
  if (!el) {
52
49
  el = document.createElement('div');
@@ -54,34 +51,14 @@ export const DropdownSub = forwardRef((props, ref) => {
54
51
  document.body.appendChild(el);
55
52
  }
56
53
  return el;
57
- }, children: _jsx(Transition, { enter: visible, during: TTANSITION_DURING_POPUP, afterRender: updatePosition, children: (state) => {
58
- let transitionStyle = {};
59
- switch (state) {
60
- case 'enter':
61
- transitionStyle = { transform: 'scale(0)', opacity: 0 };
62
- break;
63
- case 'entering':
64
- transitionStyle = {
65
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-out`).join(', '),
66
- transformOrigin: transformOrigin.current,
67
- };
68
- break;
69
- case 'leaving':
70
- transitionStyle = {
71
- transform: 'scale(0)',
72
- opacity: 0,
73
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-in`).join(', '),
74
- transformOrigin: transformOrigin.current,
75
- };
76
- break;
77
- case 'leaved':
78
- transitionStyle = { display: 'none' };
79
- break;
80
- default:
81
- break;
82
- }
83
- return renderPopup(_jsx("div", Object.assign({}, mergeCS(styled('dropdown-popup'), {
84
- style: Object.assign({ zIndex }, transitionStyle),
85
- }), { ref: popupRef, children: _jsx("ul", Object.assign({}, styled('dropdown__list'), { role: "menu", "aria-labelledby": id, children: empty ? (_jsx("div", Object.assign({}, mergeCS(styled('dropdown__empty'), { style: { paddingLeft: 12 + level * 16 } }), { children: t('No data') }))) : (list) })) })));
86
- } }) })] })) }));
87
- });
54
+ }, children: _jsx(Transition, { enter: visible, name: `${namespace}-popup`, duration: TTANSITION_DURING_POPUP, onSkipEnter: updatePosition, onBeforeEnter: updatePosition, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, mergeCS(styled('dropdown-popup'), {
55
+ style: Object.assign({ zIndex }, (leaved ? { display: 'none' } : undefined)),
56
+ }), { ref: (instance) => {
57
+ popupRef.current = instance;
58
+ transitionRef(instance);
59
+ return () => {
60
+ popupRef.current = null;
61
+ transitionRef(null);
62
+ };
63
+ } }, popupProps.popup, { children: _jsx("ul", Object.assign({}, styled('dropdown__list'), { role: "menu", "aria-labelledby": id, children: empty ? (_jsx("div", Object.assign({}, mergeCS(styled('dropdown__empty'), { style: { paddingLeft: 12 + level * 16 } }), { children: t('No data') }))) : (list) })) }))) }) })] })) }));
64
+ }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { CLASSES } from './vars';
3
- import type { BaseProps, CloneHTMLElement, VerticalSidePlacement } from '../types';
3
+ import type { BaseProps, VerticalSidePlacement } from '../types';
4
4
  export {};
5
5
  export interface DropdownRef {
6
6
  updatePosition: () => void;
@@ -15,7 +15,20 @@ export interface DropdownItem<ID extends React.Key> {
15
15
  children?: DropdownItem<ID>[];
16
16
  }
17
17
  export interface DropdownProps<ID extends React.Key, T extends DropdownItem<ID>> extends BaseProps<'dropdown' | 'dropdown-popup', typeof CLASSES>, Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'onClick'> {
18
- children: React.ReactElement | ((render: CloneHTMLElement) => React.ReactNode);
18
+ ref?: React.Ref<DropdownRef>;
19
+ children: (props: {
20
+ id: string;
21
+ tabIndex: number;
22
+ 'aria-haspopup': 'menu';
23
+ 'aria-expanded': boolean;
24
+ 'aria-controls': string;
25
+ onClick: React.MouseEventHandler<HTMLElement>;
26
+ onMouseEnter: React.MouseEventHandler<HTMLElement>;
27
+ onMouseLeave: React.MouseEventHandler<HTMLElement>;
28
+ onFocus: React.FocusEventHandler<HTMLElement>;
29
+ onBlur: React.FocusEventHandler<HTMLElement>;
30
+ onKeyDown: React.KeyboardEventHandler<HTMLElement>;
31
+ }) => React.ReactNode;
19
32
  list: T[];
20
33
  visible?: boolean;
21
34
  defaultVisible?: boolean;
package/empty/Empty.d.ts CHANGED
@@ -2,6 +2,6 @@
2
2
  import type { EmptyProps } from './types';
3
3
  import { SIMPLE_IMG } from './vars';
4
4
  export declare const Empty: {
5
- (props: EmptyProps): JSX.Element | null;
5
+ (props: EmptyProps): React.ReactElement | null;
6
6
  SIMPLE_IMG: typeof SIMPLE_IMG;
7
7
  };
package/fab/Fab.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { FabProps } from './types';
3
3
  import { FabBacktop } from './FabBacktop';
4
4
  import { FabButton } from './FabButton';
5
5
  export declare const Fab: {
6
- (props: FabProps): JSX.Element | null;
6
+ (props: FabProps): React.ReactElement | null;
7
7
  Button: typeof FabButton;
8
8
  Backtop: typeof FabBacktop;
9
9
  };
package/fab/Fab.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Children, cloneElement } from 'react';
3
+ import { has } from 'lodash';
4
4
  import { FabBacktop } from './FabBacktop';
5
5
  import { FabButton } from './FabButton';
6
- import { CLASSES } from './vars';
6
+ import { CLASSES, FabContext, FabListContext } from './vars';
7
7
  import { useComponentProps, useControlled, useStyled } from '../hooks';
8
8
  import { mergeCS } from '../utils';
9
9
  export const Fab = (props) => {
@@ -13,19 +13,24 @@ export const Fab = (props) => {
13
13
  return (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('fab'), {
14
14
  className: restProps.className,
15
15
  style: restProps.style,
16
- }), { children: [cloneElement(children, Object.assign({ _expand: expand }, { onClick: (e) => {
17
- var _a, _b;
18
- (_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
19
- if (list) {
20
- changeExpand((draft) => !draft);
21
- }
22
- } })), expand &&
16
+ }), { children: [_jsx(FabContext, { value: {
17
+ expand,
18
+ onClick: () => {
19
+ if (list) {
20
+ changeExpand((prev) => !prev);
21
+ }
22
+ },
23
+ }, children: children }), expand &&
23
24
  list &&
24
- list.map(({ placement, actions }, key) => (_jsx("div", Object.assign({}, styled('fab__actions', `fab__actions--${placement}`), { children: Children.map(actions, (action, index) => cloneElement(action, Object.assign({ _action: true }, { style: Object.assign(Object.assign({}, action.props.style), { animationDelay: `${index * 33}ms` }), onClick: (e) => {
25
- var _a, _b;
26
- (_b = (_a = action.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
27
- changeExpand(false);
28
- } }))) }), key)))] })));
25
+ list.map(({ placement, actions }) => (_jsx("div", Object.assign({}, styled('fab__actions', `fab__actions--${placement}`), { children: actions.map((node, index) => {
26
+ const { id, action } = (has(node, ['id', 'action']) ? node : { id: index, action: node });
27
+ return (_jsx(FabListContext, { value: {
28
+ index,
29
+ onClick: () => {
30
+ changeExpand(false);
31
+ },
32
+ }, children: action }, id));
33
+ }) }), placement)))] })));
29
34
  };
30
35
  Fab.Button = FabButton;
31
36
  Fab.Backtop = FabBacktop;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { FabBacktopProps } from './types';
3
- export declare function FabBacktop(props: FabBacktopProps): JSX.Element | null;
3
+ export declare function FabBacktop(props: FabBacktopProps): React.ReactElement | null;
package/fab/FabBacktop.js CHANGED
@@ -1,32 +1,24 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useEvent, useIsomorphicLayoutEffect, useRefExtra, useResize } from '@laser-ui/hooks';
3
+ import { useEvent, useIsomorphicLayoutEffect, useRefExtra, useResize, useUnmount } from '@laser-ui/hooks';
4
4
  import { scrollTo, toPx } from '@laser-ui/utils';
5
5
  import VerticalAlignTopOutlined from '@material-design-icons/svg/outlined/vertical_align_top.svg?react';
6
6
  import { isString } from 'lodash';
7
- import { cloneElement, useRef, useState } from 'react';
7
+ import { useRef, useState } from 'react';
8
8
  import { FabButton } from './FabButton';
9
- import { useComponentProps, useLayout } from '../hooks';
9
+ import { FabBacktopContext } from './vars';
10
+ import { useComponentProps, useLayout, useNamespace } from '../hooks';
10
11
  import { Icon } from '../icon';
11
- import { Transition } from '../internal/transition';
12
+ import { Transition } from '../transition';
12
13
  import { TTANSITION_DURING_BASE } from '../vars';
13
14
  export function FabBacktop(props) {
14
15
  const _a = useComponentProps('FabBacktop', props), { children, page, distance: distanceProp = 400, scrollBehavior = 'instant' } = _a, restProps = __rest(_a, ["children", "page", "distance", "scrollBehavior"]);
16
+ const namespace = useNamespace();
15
17
  const { pageScrollRef, contentResizeRef } = useLayout();
16
18
  const pageRef = useRefExtra(page !== null && page !== void 0 ? page : (() => pageScrollRef.current));
17
- const dataRef = useRef({});
19
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
20
+ const clearTid = useRef(() => { });
18
21
  const [visible, setVisible] = useState(false);
19
- const transitionStyles = {
20
- enter: { opacity: 0 },
21
- entering: {
22
- transition: ['opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms linear`).join(', '),
23
- },
24
- leaving: {
25
- opacity: 0,
26
- transition: ['opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms linear`).join(', '),
27
- },
28
- leaved: { display: 'none' },
29
- };
30
22
  const updateBackTop = () => {
31
23
  if (pageRef.current) {
32
24
  const distance = isString(distanceProp) ? toPx(distanceProp, true) : distanceProp;
@@ -39,19 +31,20 @@ export function FabBacktop(props) {
39
31
  }, []);
40
32
  useEvent(pageRef, 'scroll', updateBackTop, { passive: true });
41
33
  useResize(contentResizeRef, updateBackTop);
42
- const node = (_jsx(FabButton, Object.assign({}, restProps, { children: children !== null && children !== void 0 ? children : (_jsx(Icon, { children: _jsx(VerticalAlignTopOutlined, {}) })) })));
43
- return (_jsx(Transition, { enter: visible, during: TTANSITION_DURING_BASE, children: (state) => cloneElement(node, {
44
- style: Object.assign(Object.assign({}, node.props.style), transitionStyles[state]),
45
- onClick: (e) => {
46
- var _a, _b, _c, _d;
47
- (_b = (_a = node.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
48
- if (pageRef.current) {
49
- (_d = (_c = dataRef.current).clearTid) === null || _d === void 0 ? void 0 : _d.call(_c);
50
- dataRef.current.clearTid = scrollTo(pageRef.current, {
51
- top: 0,
52
- behavior: scrollBehavior,
53
- });
54
- }
55
- },
56
- }) }));
34
+ useUnmount(() => {
35
+ clearTid.current();
36
+ });
37
+ return (_jsx(Transition, { enter: visible, name: `${namespace}-fade`, duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => (_jsx(FabBacktopContext, { value: {
38
+ ref: transitionRef,
39
+ leaved,
40
+ onClick: () => {
41
+ if (pageRef.current) {
42
+ clearTid.current();
43
+ clearTid.current = scrollTo(pageRef.current, {
44
+ top: 0,
45
+ behavior: scrollBehavior,
46
+ });
47
+ }
48
+ },
49
+ }, children: _jsx(FabButton, Object.assign({}, restProps, { children: children !== null && children !== void 0 ? children : (_jsx(Icon, { children: _jsx(VerticalAlignTopOutlined, {}) })) })) })) }));
57
50
  }
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { FabButtonProps } from './types';
3
- export declare const FabButton: import("react").ForwardRefExoticComponent<FabButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
3
+ export declare function FabButton(props: FabButtonProps): React.ReactElement | null;