@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
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ # [2.0.0](https://github.com/laser-ui/laser-ui/compare/v1.6.1...v2.0.0) (2024-12-17)
6
+
7
+ ### Bug Fixes
8
+
9
+ - **components:** fix nested drawer ([7175bd1](https://github.com/laser-ui/laser-ui/commit/7175bd11c19831f1c2cc272a60440bbe3de295c9))
10
+
11
+ ### Features
12
+
13
+ - **components:** add `Transition` component ([61f28b0](https://github.com/laser-ui/laser-ui/commit/61f28b06e97235dec80982117b483f1c65b811ef))
14
+
15
+ ## [1.6.1](https://github.com/laser-ui/laser-ui/compare/v1.6.0...v1.6.1) (2024-11-17)
16
+
17
+ ### Bug Fixes
18
+
19
+ - **components:** fix select img in image preview ([f4d206a](https://github.com/laser-ui/laser-ui/commit/f4d206afa30fcc20ddae19fefae2ef4ed49771bd))
20
+
5
21
  # [1.6.0](https://github.com/laser-ui/laser-ui/compare/v1.5.1...v1.6.0) (2024-11-16)
6
22
 
7
23
  ### Features
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { AccordionItem, AccordionProps } from './types';
3
- export declare function Accordion<ID extends React.Key, T extends AccordionItem<ID>>(props: AccordionProps<ID, T>): JSX.Element | null;
3
+ export declare function Accordion<ID extends React.Key, T extends AccordionItem<ID>>(props: AccordionProps<ID, T>): React.ReactElement | null;
@@ -7,11 +7,12 @@ import { useId } from 'react';
7
7
  import { CLASSES } from './vars';
8
8
  import { useComponentProps, useControlled, useNamespace, useStyled } from '../hooks';
9
9
  import { Icon } from '../icon';
10
- import { CollapseTransition } from '../internal/transition';
10
+ import { LazyLoading } from '../internal/lazy-loading';
11
+ import { CollapseTransition } from '../transition';
11
12
  import { mergeCS } from '../utils';
12
13
  import { TTANSITION_DURING_BASE } from '../vars';
13
14
  export function Accordion(props) {
14
- const _a = useComponentProps('Accordion', props), { styleOverrides, styleProvider, list, active: activeProp, defaultActive, activeOne, arrow = 'right', onActiveChange, afterActiveChange } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "list", "active", "defaultActive", "activeOne", "arrow", "onActiveChange", "afterActiveChange"]);
15
+ const _a = useComponentProps('Accordion', props), { styleOverrides, styleProvider, list, active: activeProp, defaultActive, activeOne, arrow = 'right', lazyLoading = true, onActiveChange, afterActiveChange } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "list", "active", "defaultActive", "activeOne", "arrow", "lazyLoading", "onActiveChange", "afterActiveChange"]);
15
16
  const namespace = useNamespace();
16
17
  const styled = useStyled(CLASSES, { accordion: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.accordion }, styleOverrides);
17
18
  const uniqueId = useId();
@@ -133,30 +134,17 @@ export function Accordion(props) {
133
134
  transform: isUndefined(iconRotate) ? undefined : `rotate(${iconRotate}deg)`,
134
135
  },
135
136
  }), { children: _jsx(Icon, { children: _jsx(KeyboardArrowDownOutlined, {}) }) })))] })),
136
- _jsx(CollapseTransition, { originalSize: {
137
- height: 'auto',
138
- }, collapsedSize: {
139
- height: 0,
140
- }, enter: isActive, during: TTANSITION_DURING_BASE, styles: {
141
- enter: { opacity: 0 },
142
- entering: {
143
- transition: ['height', 'padding', 'margin', 'opacity']
144
- .map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-out`)
145
- .join(', '),
146
- },
147
- leaving: {
148
- opacity: 0,
149
- transition: ['height', 'padding', 'margin', 'opacity']
150
- .map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-in`)
151
- .join(', '),
152
- },
153
- leaved: { display: 'none' },
154
- }, afterEnter: () => {
137
+ _jsx(CollapseTransition, { height: 0, enter: isActive, name: `${namespace}-accordion`, duration: TTANSITION_DURING_BASE, onAfterEnter: () => {
155
138
  afterActiveChange === null || afterActiveChange === void 0 ? void 0 : afterActiveChange(itemId, item, true);
156
- }, afterLeave: () => {
139
+ }, onAfterLeave: () => {
157
140
  afterActiveChange === null || afterActiveChange === void 0 ? void 0 : afterActiveChange(itemId, item, false);
158
- }, children: (regionRef, collapseStyle) => (_jsx("div", Object.assign({}, mergeCS(styled('accordion__item-region'), {
159
- style: collapseStyle,
160
- }), { ref: regionRef, id: regionId, role: "region", "aria-labelledby": getButtonId(itemId), children: itemRegion }))) })));
141
+ }, children: (transitionRef, leaved) => (_jsx(LazyLoading, { hidden: leaved, disabled: !lazyLoading, children: _jsx("div", { ref: (instance) => {
142
+ transitionRef(instance);
143
+ return () => {
144
+ transitionRef(null);
145
+ };
146
+ }, children: _jsx("div", Object.assign({}, mergeCS(styled('accordion__item-region'), {
147
+ style: Object.assign({}, (leaved ? { display: 'none' } : undefined)),
148
+ }), { id: regionId, role: "region", "aria-labelledby": getButtonId(itemId), children: itemRegion })) }) })) })));
161
149
  }) })));
162
150
  }
@@ -15,6 +15,7 @@ export interface AccordionProps<ID extends React.Key, T extends AccordionItem<ID
15
15
  defaultActive?: ID | null | ID[];
16
16
  activeOne?: boolean;
17
17
  arrow?: 'left' | 'right' | false;
18
+ lazyLoading?: boolean;
18
19
  onActiveChange?: (id: any, origin: any) => void;
19
20
  afterActiveChange?: (id: ID, origin: T, active: boolean) => void;
20
21
  }
package/affix/Affix.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import type { AffixProps, AffixRef } from './types';
3
- export declare const Affix: import("react").ForwardRefExoticComponent<AffixProps & import("react").RefAttributes<AffixRef>>;
2
+ import type { AffixProps } from './types';
3
+ export declare function Affix(props: AffixProps): React.ReactElement | null;
package/affix/Affix.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEventCallback, useMount, useRefExtra, useResize } from '@laser-ui/hooks';
2
+ import { useEventCallback, useIsomorphicLayoutEffect, useRefExtra, useResize } from '@laser-ui/hooks';
3
3
  import { getOffsetToRoot, toPx } from '@laser-ui/utils';
4
- import { isFunction, isString, isUndefined } from 'lodash';
5
- import { cloneElement, forwardRef, useId, useImperativeHandle, useState } from 'react';
6
- import { useComponentProps, useContainerScrolling, useJSS, useLayout, useNamespace } from '../hooks';
7
- export const Affix = forwardRef((props, ref) => {
8
- const { children, top = 0, target, zIndex } = useComponentProps('Affix', props);
4
+ import { isString, isUndefined } from 'lodash';
5
+ import { useId, useImperativeHandle, useState } from 'react';
6
+ import { useComponentProps, useContainerScrolling, useLayout, useNamespace } from '../hooks';
7
+ export function Affix(props) {
8
+ const { ref, children, top = 0, target, zIndex } = useComponentProps('Affix', props);
9
9
  const namespace = useNamespace();
10
- const sheet = useJSS();
11
10
  const { pageScrollRef, contentResizeRef } = useLayout();
12
11
  const uniqueId = useId();
13
12
  const affixRef = useRefExtra(() => document.querySelector(`[data-l-affix="${uniqueId}"]`));
@@ -20,32 +19,31 @@ export const Affix = forwardRef((props, ref) => {
20
19
  const offsetRect = offsetEl.getBoundingClientRect();
21
20
  const targetTop = getOffsetToRoot(targetRef.current);
22
21
  const distance = isString(top) ? toPx(top, true) : top;
23
- const newSticky = Math.ceil(targetRef.current.scrollTop) + distance >= getOffsetToRoot(offsetEl) - targetTop;
24
- setSticky(newSticky);
25
- if (sheet.classes.position) {
26
- affixRef.current.classList.toggle(sheet.classes.position, false);
27
- }
28
- if (newSticky) {
29
- sheet.replaceRule('position', {
30
- width: offsetRect.width,
31
- height: offsetRect.height,
32
- position: 'fixed',
33
- top: (isUndefined(target) ? targetTop : targetRef.current.getBoundingClientRect().top) + distance,
34
- left: offsetRect.left,
35
- zIndex: zIndex !== null && zIndex !== void 0 ? zIndex : `var(--${namespace}-zindex-sticky)`,
36
- });
37
- affixRef.current.classList.toggle(sheet.classes.position, true);
22
+ const s = Math.ceil(targetRef.current.scrollTop) + distance >= getOffsetToRoot(offsetEl) - targetTop;
23
+ setSticky(s);
24
+ if (s) {
25
+ affixRef.current.style.position = 'fixed';
26
+ affixRef.current.style.top = (isUndefined(target) ? targetTop : targetRef.current.getBoundingClientRect().top) + distance + 'px';
27
+ affixRef.current.style.left = offsetRect.left + 'px';
28
+ affixRef.current.style.width = offsetRect.width + 'px';
29
+ affixRef.current.style.height = offsetRect.height + 'px';
30
+ affixRef.current.style.zIndex = zIndex ? String(zIndex) : `var(--${namespace}-zindex-sticky)`;
38
31
  placeholderRef.current.style.display = '';
39
32
  }
40
33
  else {
41
- sheet.deleteRule('position');
34
+ affixRef.current.style.position = '';
35
+ affixRef.current.style.top = '';
36
+ affixRef.current.style.left = '';
37
+ affixRef.current.style.width = '';
38
+ affixRef.current.style.height = '';
39
+ affixRef.current.style.zIndex = '';
42
40
  placeholderRef.current.style.display = 'none';
43
41
  }
44
42
  }
45
43
  });
46
- useMount(() => {
44
+ useIsomorphicLayoutEffect(() => {
47
45
  updatePosition();
48
- });
46
+ }, []);
49
47
  useContainerScrolling(affixRef, updatePosition);
50
48
  useResize(sticky ? placeholderRef : affixRef, updatePosition);
51
49
  useResize(contentResizeRef, updatePosition);
@@ -53,12 +51,9 @@ export const Affix = forwardRef((props, ref) => {
53
51
  sticky,
54
52
  updatePosition,
55
53
  }), [sticky, updatePosition]);
56
- const render = (el) => (_jsxs(_Fragment, { children: [cloneElement(el, {
57
- style: Object.assign(Object.assign({}, el.props.style), { visibility: 'hidden' }),
54
+ return (_jsxs(_Fragment, { children: [children({
55
+ style: { visibility: 'hidden' },
58
56
  'aria-hidden': true,
59
57
  'data-l-affix-placeholder': uniqueId,
60
- }), cloneElement(el, {
61
- 'data-l-affix': uniqueId,
62
- })] }));
63
- return isFunction(children) ? children(render) : render(children);
64
- });
58
+ }), children({ 'data-l-affix': uniqueId })] }));
59
+ }
package/affix/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import type { CloneHTMLElement } from '../types';
3
2
  import type { RefExtra } from '@laser-ui/hooks/useRefExtra';
4
3
  export {};
5
4
  export interface AffixRef {
@@ -7,7 +6,13 @@ export interface AffixRef {
7
6
  updatePosition: () => void;
8
7
  }
9
8
  export interface AffixProps {
10
- children: React.ReactElement | ((render: CloneHTMLElement) => JSX.Element | null);
9
+ ref?: React.Ref<AffixRef>;
10
+ children: (props: {
11
+ style?: React.CSSProperties;
12
+ 'aria-hidden'?: true;
13
+ 'data-l-affix-placeholder'?: string;
14
+ 'data-l-affix'?: string;
15
+ }) => React.ReactElement | null;
11
16
  top?: number | string;
12
17
  target?: RefExtra;
13
18
  zIndex?: number | string;
package/alert/Alert.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { AlertProps } from './types';
3
- export declare function Alert(props: AlertProps): JSX.Element | null;
3
+ export declare function Alert(props: AlertProps): React.ReactElement | null;
package/alert/Alert.js CHANGED
@@ -10,7 +10,7 @@ import { isUndefined } from 'lodash';
10
10
  import { CLASSES } from './vars';
11
11
  import { useComponentProps, useControlled, useStyled, useTranslation } from '../hooks';
12
12
  import { Icon } from '../icon';
13
- import { CollapseTransition } from '../internal/transition';
13
+ import { CollapseTransition } from '../transition';
14
14
  import { mergeCS } from '../utils';
15
15
  import { TTANSITION_DURING_BASE } from '../vars';
16
16
  export function Alert(props) {
@@ -22,32 +22,23 @@ export function Alert(props) {
22
22
  const closeNode = closable && (_jsx("button", Object.assign({}, styled('alert__close'), { "aria-label": t('Close'), onClick: () => {
23
23
  changeVisible(false);
24
24
  }, children: _jsx(Icon, { children: _jsx(CloseOutlined, {}) }) })));
25
- return (_jsx(CollapseTransition, { originalSize: {
26
- height: 'auto',
27
- }, collapsedSize: {
28
- height: 0,
29
- }, enter: visible, during: TTANSITION_DURING_BASE, styles: {
30
- enter: { opacity: 0 },
31
- entering: {
32
- transition: ['height', 'padding', 'margin', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-out`).join(', '),
33
- },
34
- leaving: {
35
- opacity: 0,
36
- transition: ['height', 'padding', 'margin', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-in`).join(', '),
37
- },
38
- leaved: { display: 'none' },
39
- }, destroyWhenLeaved: true, afterEnter: () => {
25
+ return (_jsx(CollapseTransition, { height: 0, enter: visible, duration: TTANSITION_DURING_BASE, onAfterEnter: () => {
40
26
  afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
41
- }, afterLeave: () => {
27
+ }, onAfterLeave: () => {
42
28
  afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
43
- }, children: (alertRef, collapseStyle) => {
29
+ }, children: (transitionRef, leaved) => {
44
30
  var _a;
45
- return (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('alert', {
31
+ return leaved ? null : (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('alert', {
46
32
  'alert--with-title': hasTitle,
47
33
  [`alert--${type}`]: type,
48
34
  }), {
49
35
  className: restProps.className,
50
- style: Object.assign(Object.assign({}, restProps.style), collapseStyle),
51
- }), { ref: alertRef, role: (_a = restProps.role) !== null && _a !== void 0 ? _a : 'alert', children: [icon !== false && (!isUndefined(type) || checkNodeExist(icon)) && (_jsx("div", Object.assign({}, styled('alert__icon'), { children: checkNodeExist(icon) ? (icon) : (_jsx(Icon, { children: type === 'success' ? (_jsx(CheckCircleOutlined, {})) : type === 'warning' ? (_jsx(WarningAmberOutlined, {})) : type === 'error' ? (_jsx(HighlightOffOutlined, {})) : (_jsx(InfoOutlined, {})) })) }))), _jsxs("div", Object.assign({}, styled('alert__content'), { children: [hasTitle && (_jsxs("div", Object.assign({}, styled('alert__header'), { children: [_jsx("div", Object.assign({}, styled('alert__title'), { children: title })), closeNode] }))), checkNodeExist(children) && _jsx("div", Object.assign({}, styled('alert__message'), { children: children })), !hasTitle && closeNode] }))] })));
36
+ style: Object.assign({}, restProps.style),
37
+ }), { ref: (instance) => {
38
+ transitionRef(instance);
39
+ return () => {
40
+ transitionRef(null);
41
+ };
42
+ }, role: (_a = restProps.role) !== null && _a !== void 0 ? _a : 'alert', children: [icon !== false && (!isUndefined(type) || checkNodeExist(icon)) && (_jsx("div", Object.assign({}, styled('alert__icon'), { children: checkNodeExist(icon) ? (icon) : (_jsx(Icon, { children: type === 'success' ? (_jsx(CheckCircleOutlined, {})) : type === 'warning' ? (_jsx(WarningAmberOutlined, {})) : type === 'error' ? (_jsx(HighlightOffOutlined, {})) : (_jsx(InfoOutlined, {})) })) }))), _jsxs("div", Object.assign({}, styled('alert__content'), { children: [hasTitle && (_jsxs("div", Object.assign({}, styled('alert__header'), { children: [_jsx("div", Object.assign({}, styled('alert__title'), { children: title })), closeNode] }))), checkNodeExist(children) && _jsx("div", Object.assign({}, styled('alert__message'), { children: children })), !hasTitle && closeNode] }))] })));
52
43
  } }));
53
44
  }
@@ -1,10 +1,8 @@
1
1
  /// <reference types="react" />
2
- import type { AnchorItem, AnchorProps, AnchorRef } from './types';
2
+ import type { AnchorItem, AnchorProps } from './types';
3
3
  import { DOT_INDICATOR, LINE_INDICATOR } from './vars';
4
- declare function AnchorFC<T extends AnchorItem>(props: AnchorProps<T>, ref: React.ForwardedRef<AnchorRef>): JSX.Element | null;
5
4
  export declare const Anchor: {
6
- <T extends AnchorItem>(props: AnchorProps<T> & React.RefAttributes<AnchorRef>): ReturnType<typeof AnchorFC>;
5
+ <T extends AnchorItem>(props: AnchorProps<T>): React.ReactElement | null;
7
6
  DOT_INDICATOR: typeof DOT_INDICATOR;
8
7
  LINE_INDICATOR: typeof LINE_INDICATOR;
9
8
  };
10
- export {};
package/anchor/Anchor.js CHANGED
@@ -1,20 +1,21 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEvent, useEventCallback, useMount, useRefExtra, useResize } from '@laser-ui/hooks';
3
+ import { useEvent, useEventCallback, useIsomorphicLayoutEffect, useRefExtra, useResize } from '@laser-ui/hooks';
4
4
  import { getOffsetToRoot, scrollTo, toPx } from '@laser-ui/utils';
5
5
  import { isArray, isString, isUndefined } from 'lodash';
6
- import { Fragment, forwardRef, useImperativeHandle, useRef, useState } from 'react';
6
+ import { Fragment, useImperativeHandle, useRef, useState } from 'react';
7
7
  import { CLASSES, DOT_INDICATOR, LINE_INDICATOR } from './vars';
8
8
  import { useComponentProps, useLayout, useStyled } from '../hooks';
9
9
  import { mergeCS } from '../utils';
10
- function AnchorFC(props, ref) {
11
- const _a = useComponentProps('Anchor', props), { styleOverrides, styleProvider, list, page, distance: distanceProp = 0, scrollBehavior = 'instant', indicator = DOT_INDICATOR, onClick } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "list", "page", "distance", "scrollBehavior", "indicator", "onClick"]);
10
+ export const Anchor = (props) => {
11
+ const _a = useComponentProps('Anchor', props), { ref, styleOverrides, styleProvider, list, page, distance: distanceProp = 0, scrollBehavior = 'instant', indicator = DOT_INDICATOR, onClick } = _a, restProps = __rest(_a, ["ref", "styleOverrides", "styleProvider", "list", "page", "distance", "scrollBehavior", "indicator", "onClick"]);
12
12
  const styled = useStyled(CLASSES, { anchor: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.anchor }, styleOverrides);
13
13
  const { pageScrollRef, contentResizeRef } = useLayout();
14
14
  const pageRef = useRefExtra(page !== null && page !== void 0 ? page : (() => pageScrollRef.current));
15
15
  const anchorRef = useRef(null);
16
16
  const indicatorRef = useRef(null);
17
- const dataRef = useRef({});
17
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
18
+ const clearTid = useRef(() => { });
18
19
  const [active, setActive] = useState(null);
19
20
  const updateAnchor = useEventCallback(() => {
20
21
  if (pageRef.current && anchorRef.current && indicatorRef.current) {
@@ -53,9 +54,9 @@ function AnchorFC(props, ref) {
53
54
  }
54
55
  }
55
56
  });
56
- useMount(() => {
57
+ useIsomorphicLayoutEffect(() => {
57
58
  updateAnchor();
58
- });
59
+ }, []);
59
60
  useEvent(pageRef, 'scroll', updateAnchor, { passive: true });
60
61
  useResize(contentResizeRef, updateAnchor);
61
62
  useImperativeHandle(ref, () => ({
@@ -63,7 +64,6 @@ function AnchorFC(props, ref) {
63
64
  updateAnchor,
64
65
  }), [active, updateAnchor]);
65
66
  const handleLinkClick = (href) => {
66
- var _a, _b;
67
67
  if (pageRef.current) {
68
68
  const pageTop = getOffsetToRoot(pageRef.current);
69
69
  const scrollTop = pageRef.current.scrollTop;
@@ -73,32 +73,40 @@ function AnchorFC(props, ref) {
73
73
  if (el) {
74
74
  const top = getOffsetToRoot(el);
75
75
  const distance = isString(distanceProp) ? toPx(distanceProp, true) : distanceProp;
76
- (_b = (_a = dataRef.current).clearTid) === null || _b === void 0 ? void 0 : _b.call(_a);
77
- dataRef.current.clearTid = scrollTo(pageRef.current, {
76
+ clearTid.current();
77
+ clearTid.current = scrollTo(pageRef.current, {
78
78
  top: top - pageTop - distance,
79
79
  behavior: scrollBehavior,
80
80
  });
81
81
  }
82
82
  }
83
83
  };
84
- const linkNodes = (() => {
85
- const getNodes = (arr, level = 0) => arr.map((link) => {
86
- const { title: linkTitle, href: linkHref, target: linkTarget, children } = link;
87
- return (_jsxs(Fragment, { children: [_jsx("li", Object.assign({}, styled('anchor__link', {
88
- 'anchor__link.is-active': linkHref === active,
89
- }), { "data-l-href": linkHref, children: _jsx("a", { style: { paddingLeft: 16 + level * 16 }, href: `#${linkHref}`, target: linkTarget, onClick: (e) => {
90
- e.preventDefault();
91
- handleLinkClick(linkHref);
92
- onClick === null || onClick === void 0 ? void 0 : onClick(linkHref, link);
93
- }, children: linkTitle !== null && linkTitle !== void 0 ? linkTitle : linkHref }) })), children && getNodes(children, level + 1)] }, `${linkHref}-${level}`));
94
- });
95
- return getNodes(list);
96
- })();
97
84
  return (_jsxs("ul", Object.assign({}, restProps, mergeCS(styled('anchor'), {
98
85
  className: restProps.className,
99
86
  style: restProps.style,
100
- }), { ref: anchorRef, children: [_jsx("div", Object.assign({}, styled('anchor__indicator-track'), { children: _jsx("div", Object.assign({}, styled('anchor__indicator-wrapper'), { ref: indicatorRef, children: indicator === DOT_INDICATOR ? (_jsx("div", Object.assign({}, styled('anchor__dot-indicator')))) : indicator === LINE_INDICATOR ? (_jsx("div", Object.assign({}, styled('anchor__line-indicator')))) : (indicator) })) })), linkNodes] })));
101
- }
102
- export const Anchor = forwardRef(AnchorFC);
87
+ }), { ref: (instance) => {
88
+ anchorRef.current = instance;
89
+ return () => {
90
+ anchorRef.current = null;
91
+ };
92
+ }, children: [_jsx("div", Object.assign({}, styled('anchor__indicator-track'), { children: _jsx("div", Object.assign({}, styled('anchor__indicator-wrapper'), { ref: (instance) => {
93
+ indicatorRef.current = instance;
94
+ return () => {
95
+ indicatorRef.current = null;
96
+ };
97
+ }, children: indicator === DOT_INDICATOR ? (_jsx("div", Object.assign({}, styled('anchor__dot-indicator')))) : indicator === LINE_INDICATOR ? (_jsx("div", Object.assign({}, styled('anchor__line-indicator')))) : (indicator) })) })), (() => {
98
+ const getNodes = (arr, level = 0) => arr.map((link) => {
99
+ const { title: linkTitle, href: linkHref, target: linkTarget, children } = link;
100
+ return (_jsxs(Fragment, { children: [_jsx("li", Object.assign({}, styled('anchor__link', {
101
+ 'anchor__link.is-active': linkHref === active,
102
+ }), { "data-l-href": linkHref, children: _jsx("a", { style: { paddingLeft: 16 + level * 16 }, href: `#${linkHref}`, target: linkTarget, onClick: (e) => {
103
+ e.preventDefault();
104
+ handleLinkClick(linkHref);
105
+ onClick === null || onClick === void 0 ? void 0 : onClick(linkHref, link);
106
+ }, children: linkTitle !== null && linkTitle !== void 0 ? linkTitle : linkHref }) })), children && getNodes(children, level + 1)] }, `${linkHref}-${level}`));
107
+ });
108
+ return getNodes(list);
109
+ })()] })));
110
+ };
103
111
  Anchor.DOT_INDICATOR = DOT_INDICATOR;
104
112
  Anchor.LINE_INDICATOR = LINE_INDICATOR;
package/anchor/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface AnchorItem {
14
14
  children?: AnchorItem[];
15
15
  }
16
16
  export interface AnchorProps<T extends AnchorItem> extends BaseProps<'anchor', typeof CLASSES>, Omit<React.HTMLAttributes<HTMLUListElement>, 'children' | 'onClick'> {
17
+ ref?: React.Ref<AnchorRef>;
17
18
  list: T[];
18
19
  page?: RefExtra;
19
20
  distance?: number | string;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { AvatarProps } from './types';
3
- export declare function Avatar(props: AvatarProps): JSX.Element | null;
3
+ export declare function Avatar(props: AvatarProps): React.ReactElement | null;
package/avatar/Avatar.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useIsomorphicLayoutEffect } from '@laser-ui/hooks';
3
4
  import { toPx } from '@laser-ui/utils';
4
5
  import { isNumber } from 'lodash';
5
- import { useEffect, useRef, useState } from 'react';
6
+ import { useRef, useState } from 'react';
6
7
  import { CLASSES } from './vars';
7
8
  import { useComponentProps, useStyled } from '../hooks';
8
9
  import { mergeCS } from '../utils';
@@ -12,7 +13,7 @@ export function Avatar(props) {
12
13
  const textRef = useRef(null);
13
14
  const [imgError, setImgError] = useState(false);
14
15
  const type = img && !imgError ? 'img' : icon ? 'icon' : text ? 'text' : 'img';
15
- useEffect(() => {
16
+ useIsomorphicLayoutEffect(() => {
16
17
  if (textRef.current) {
17
18
  const maxWidth = Math.sqrt(Math.pow((isNumber(size) ? size : toPx(size, true)) / 2, 2) - Math.pow(textRef.current.scrollHeight / 2, 2)) * 2;
18
19
  if (textRef.current.scrollWidth > maxWidth) {
@@ -39,5 +40,10 @@ export function Avatar(props) {
39
40
  var _a;
40
41
  (_a = img === null || img === void 0 ? void 0 : img.onError) === null || _a === void 0 ? void 0 : _a.call(img, e);
41
42
  setImgError(true);
42
- } }))) : type === 'icon' ? (icon) : (_jsx("div", { ref: textRef, children: text })) })));
43
+ } }))) : type === 'icon' ? (icon) : (_jsx("div", { ref: (instance) => {
44
+ textRef.current = instance;
45
+ return () => {
46
+ textRef.current = null;
47
+ };
48
+ }, children: text })) })));
43
49
  }
package/badge/Badge.d.ts CHANGED
@@ -2,6 +2,6 @@
2
2
  import type { BadgeProps } from './types';
3
3
  import { BadgeText } from './BadgeText';
4
4
  export declare const Badge: {
5
- (props: BadgeProps): JSX.Element | null;
5
+ (props: BadgeProps): React.ReactElement | null;
6
6
  Text: typeof BadgeText;
7
7
  };
package/badge/Badge.js CHANGED
@@ -1,61 +1,42 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useRef } from 'react';
3
+ import { useEffect, useRef } from 'react';
4
4
  import { BadgeText } from './BadgeText';
5
5
  import { BadgeNumber } from './internal/BadgeNumber';
6
6
  import { CLASSES } from './vars';
7
- import { useComponentProps, useStyled } from '../hooks';
8
- import { Transition } from '../internal/transition';
7
+ import { useComponentProps, useNamespace, useStyled } from '../hooks';
8
+ import { Transition } from '../transition';
9
9
  import { mergeCS } from '../utils';
10
10
  import { TTANSITION_DURING_BASE } from '../vars';
11
11
  export const Badge = (props) => {
12
12
  var _a;
13
13
  const _b = useComponentProps('Badge', props), { styleOverrides, styleProvider, value: valueProp, theme = 'danger', max = Infinity, dot = false, showZero = false, offset = [0, '100%'], alone = false } = _b, restProps = __rest(_b, ["styleOverrides", "styleProvider", "value", "theme", "max", "dot", "showZero", "offset", "alone"]);
14
+ const namespace = useNamespace();
14
15
  const styled = useStyled(CLASSES, { badge: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.badge }, styleOverrides);
15
- const dataRef = useRef({
16
- prevValue: valueProp,
17
- valueDown: false,
18
- });
16
+ const valueSaved = useRef(undefined);
19
17
  const show = showZero || valueProp > 0;
20
- const value = show ? valueProp : ((_a = dataRef.current.saveValue) !== null && _a !== void 0 ? _a : 0);
21
- dataRef.current.saveValue = value;
22
- const nums = (value > max ? max : value)
23
- .toString()
24
- .split('')
25
- .map((n) => Number(n));
26
- if (value !== dataRef.current.prevValue) {
27
- dataRef.current.valueDown = value < dataRef.current.prevValue;
28
- dataRef.current.prevValue = value;
29
- }
30
- return (_jsx(Transition, { enter: show, during: TTANSITION_DURING_BASE, children: (state) => {
18
+ const value = show ? valueProp : ((_a = valueSaved.current) !== null && _a !== void 0 ? _a : 0);
19
+ const num = value > max ? max : value;
20
+ useEffect(() => {
21
+ valueSaved.current = value;
22
+ });
23
+ return (_jsx(Transition, { enter: show, name: `${namespace}-badge`, duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => {
31
24
  var _a;
32
- let transitionStyle = {};
33
- switch (state) {
34
- case 'enter':
35
- transitionStyle = { transform: 'scale(0)', opacity: 0 };
36
- break;
37
- case 'entering':
38
- transitionStyle = {
39
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-out`).join(', '),
40
- };
41
- break;
42
- case 'leaving':
43
- transitionStyle = {
44
- transform: 'scale(0)',
45
- opacity: 0,
46
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-in`).join(', '),
47
- };
48
- break;
49
- default:
50
- break;
51
- }
52
- return state === 'leaved' ? null : (_jsx("div", Object.assign({}, restProps, mergeCS(styled('badge', `badge.t-${theme}`, {
25
+ return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('badge', `badge.t-${theme}`, {
53
26
  'badge--dot': dot,
54
27
  'badge--alone': alone,
55
28
  }), {
56
29
  className: restProps.className,
57
- style: Object.assign(Object.assign({}, restProps.style), (alone ? undefined : { top: offset[0], left: offset[1] })),
58
- }), { title: (_a = restProps.title) !== null && _a !== void 0 ? _a : (dot ? undefined : valueProp.toString()), children: _jsx("div", Object.assign({}, mergeCS(styled('badge__wrapper'), { style: transitionStyle }), { children: dot ? null : (_jsxs(_Fragment, { children: [nums.map((n, i) => (_jsx(BadgeNumber, { styled: styled, value: n, valueDown: dataRef.current.valueDown }, nums.length - i))), value > max ? '+' : ''] })) })) })));
30
+ style: Object.assign(Object.assign(Object.assign({}, restProps.style), (alone ? undefined : { top: offset[0], left: offset[1] })), (leaved ? { display: 'none' } : undefined)),
31
+ }), { title: (_a = restProps.title) !== null && _a !== void 0 ? _a : (dot ? undefined : valueProp.toString()), children: _jsx("div", Object.assign({}, styled('badge__wrapper'), { ref: (instance) => {
32
+ transitionRef(instance);
33
+ return () => {
34
+ transitionRef(null);
35
+ };
36
+ }, children: dot ? null : (_jsxs(_Fragment, { children: [num
37
+ .toString()
38
+ .split('')
39
+ .map((n, i, arr) => (_jsx(BadgeNumber, { styled: styled, value: Number(n), num: num }, arr.length - i))), value > max ? '+' : ''] })) })) })));
59
40
  } }));
60
41
  };
61
42
  Badge.Text = BadgeText;
@@ -1,40 +1,26 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { CLASSES } from './vars';
4
- import { useComponentProps, useStyled } from '../hooks';
5
- import { Transition } from '../internal/transition';
4
+ import { useComponentProps, useNamespace, useStyled } from '../hooks';
5
+ import { Transition } from '../transition';
6
6
  import { mergeCS } from '../utils';
7
7
  import { TTANSITION_DURING_BASE } from '../vars';
8
8
  export function BadgeText(props) {
9
9
  const _a = useComponentProps('BadgeText', props), { styleOverrides, styleProvider, text, theme = 'danger', offset = [0, '100%'], alone = false } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "text", "theme", "offset", "alone"]);
10
+ const namespace = useNamespace();
10
11
  const styled = useStyled(CLASSES, { badge: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.badge }, styleOverrides);
11
- return (_jsx(Transition, { enter: text.length > 0, during: TTANSITION_DURING_BASE, children: (state) => {
12
+ return (_jsx(Transition, { enter: text.length > 0, name: `${namespace}-badge`, duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => {
12
13
  var _a;
13
- let transitionStyle = {};
14
- switch (state) {
15
- case 'enter':
16
- transitionStyle = { transform: 'scale(0)', opacity: 0 };
17
- break;
18
- case 'entering':
19
- transitionStyle = {
20
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-out`).join(', '),
21
- };
22
- break;
23
- case 'leaving':
24
- transitionStyle = {
25
- transform: 'scale(0)',
26
- opacity: 0,
27
- transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-in`).join(', '),
28
- };
29
- break;
30
- default:
31
- break;
32
- }
33
- return state === 'leaved' ? null : (_jsx("div", Object.assign({}, restProps, mergeCS(styled('badge', `badge.t-${theme}`, {
14
+ return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('badge', `badge.t-${theme}`, {
34
15
  'badge--alone': alone,
35
16
  }), {
36
17
  className: restProps.className,
37
- style: Object.assign(Object.assign({}, restProps.style), (alone ? undefined : { top: offset[0], left: offset[1] })),
38
- }), { title: (_a = restProps.title) !== null && _a !== void 0 ? _a : text, children: _jsx("div", Object.assign({}, mergeCS(styled('badge__wrapper'), { style: transitionStyle }), { children: text })) })));
18
+ style: Object.assign(Object.assign(Object.assign({}, restProps.style), (alone ? undefined : { top: offset[0], left: offset[1] })), (leaved ? { display: 'none' } : undefined)),
19
+ }), { title: (_a = restProps.title) !== null && _a !== void 0 ? _a : text, children: _jsx("div", Object.assign({}, styled('badge__wrapper'), { ref: (instance) => {
20
+ transitionRef(instance);
21
+ return () => {
22
+ transitionRef(null);
23
+ };
24
+ }, children: text })) })));
39
25
  } }));
40
26
  }
@@ -4,7 +4,7 @@ import type { CLASSES } from '../vars';
4
4
  interface BadgeNumberProps {
5
5
  styled: Styled<typeof CLASSES>;
6
6
  value: number;
7
- valueDown: boolean;
7
+ num: number;
8
8
  }
9
- export declare function BadgeNumber(props: BadgeNumberProps): JSX.Element | null;
9
+ export declare function BadgeNumber(props: BadgeNumberProps): React.ReactElement | null;
10
10
  export {};