@laser-ui/components 1.6.1 → 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.
- package/CHANGELOG.md +10 -0
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +13 -25
- package/accordion/types.d.ts +1 -0
- package/affix/Affix.d.ts +2 -2
- package/affix/Affix.js +27 -32
- package/affix/types.d.ts +7 -2
- package/alert/Alert.d.ts +1 -1
- package/alert/Alert.js +12 -21
- package/anchor/Anchor.d.ts +2 -4
- package/anchor/Anchor.js +34 -26
- package/anchor/types.d.ts +1 -0
- package/avatar/Avatar.d.ts +1 -1
- package/avatar/Avatar.js +9 -3
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +22 -41
- package/badge/BadgeText.js +12 -26
- package/badge/internal/BadgeNumber.d.ts +2 -2
- package/badge/internal/BadgeNumber.js +34 -24
- package/base-input/BaseInput.d.ts +1 -2
- package/base-input/BaseInput.js +4 -4
- package/base-input/types.d.ts +1 -0
- package/breadcrumb/Breadcrumb.d.ts +1 -1
- package/button/Button.d.ts +1 -2
- package/button/Button.js +18 -22
- package/button/types.d.ts +1 -0
- package/card/Card.d.ts +1 -1
- package/card/CardAction.d.ts +1 -1
- package/card/CardAction.js +3 -4
- package/card/CardActions.d.ts +1 -1
- package/card/CardActions.js +7 -3
- package/card/CardContent.d.ts +1 -1
- package/card/CardHeader.d.ts +1 -1
- package/card/types.d.ts +5 -1
- package/cascader/Cascader.d.ts +2 -4
- package/cascader/Cascader.js +217 -214
- package/cascader/internal/CascaderPanel.d.ts +2 -2
- package/cascader/internal/CascaderPanel.js +21 -7
- package/cascader/internal/CascaderSearchPanel.d.ts +2 -2
- package/cascader/internal/CascaderSearchPanel.js +15 -6
- package/cascader/types.d.ts +3 -3
- package/checkbox/Checkbox.d.ts +1 -1
- package/checkbox/Checkbox.js +4 -5
- package/checkbox/CheckboxGroup.d.ts +1 -1
- package/checkbox/CheckboxGroup.js +8 -7
- package/checkbox/types.d.ts +14 -4
- package/{internal/circular-progress → circular-progress}/CircularProgress.d.ts +1 -1
- package/{internal/circular-progress → circular-progress}/CircularProgress.js +2 -2
- package/compose/Compose.d.ts +1 -1
- package/compose/ComposeItem.d.ts +1 -1
- package/config-provider/ConfigProvider.d.ts +1 -1
- package/config-provider/ConfigProvider.js +3 -3
- package/date-picker/DatePicker.d.ts +2 -2
- package/date-picker/DatePicker.js +116 -98
- package/date-picker/internal/DatePickerPanel.d.ts +2 -1
- package/date-picker/internal/DatePickerPanel.js +4 -4
- package/date-picker/types.d.ts +3 -3
- package/dialog-service.d.ts +9 -6
- package/dialog-service.js +50 -26
- package/drawer/Drawer.d.ts +1 -1
- package/drawer/Drawer.js +83 -92
- package/drawer/DrawerFooter.d.ts +1 -1
- package/drawer/DrawerFooter.js +12 -9
- package/drawer/DrawerHeader.d.ts +1 -1
- package/drawer/DrawerHeader.js +10 -7
- package/drawer/types.d.ts +9 -2
- package/drawer/vars.d.ts +5 -1
- package/drawer/vars.js +1 -1
- package/dropdown/Dropdown.d.ts +2 -4
- package/dropdown/Dropdown.js +83 -104
- package/dropdown/internal/DropdownGroup.d.ts +1 -1
- package/dropdown/internal/DropdownItem.d.ts +1 -1
- package/dropdown/internal/DropdownSub.d.ts +2 -1
- package/dropdown/internal/DropdownSub.js +26 -49
- package/dropdown/types.d.ts +15 -2
- package/empty/Empty.d.ts +1 -1
- package/fab/Fab.d.ts +1 -1
- package/fab/Fab.js +19 -14
- package/fab/FabBacktop.d.ts +1 -1
- package/fab/FabBacktop.js +24 -31
- package/fab/FabButton.d.ts +1 -1
- package/fab/FabButton.js +37 -10
- package/fab/types.d.ts +6 -2
- package/fab/vars.d.ts +14 -0
- package/fab/vars.js +4 -0
- package/form/Form.d.ts +1 -1
- package/form/Form.js +7 -2
- package/form/FormItem.d.ts +1 -1
- package/form/FormItem.js +35 -24
- package/form/internal/FormError.d.ts +3 -2
- package/form/internal/FormError.js +10 -19
- package/hooks/index.d.ts +0 -2
- package/hooks/index.js +0 -2
- package/hooks/useComponentProps.js +2 -2
- package/hooks/useFocusVisible.d.ts +9 -2
- package/hooks/useFocusVisible.js +5 -11
- package/hooks/useLayout.d.ts +2 -2
- package/hooks/useLayout.js +2 -2
- package/hooks/useNamespace.js +2 -2
- package/hooks/useNestedPopup.d.ts +1 -1
- package/hooks/useScopedProps.js +2 -2
- package/hooks/useStyled.js +2 -2
- package/hooks/useTranslation.js +2 -2
- package/icon/Icon.d.ts +1 -1
- package/icon/Icon.js +7 -4
- package/image/Image.d.ts +1 -1
- package/image/Image.js +6 -2
- package/image/ImageAction.d.ts +1 -1
- package/image/ImageAction.js +3 -4
- package/image/ImageLoader.d.ts +1 -1
- package/image/ImagePreview.d.ts +1 -1
- package/image/ImagePreview.js +94 -109
- package/image/types.d.ts +6 -2
- package/input/Input.d.ts +1 -1
- package/input/Input.js +12 -8
- package/input/InputNumber.js +49 -40
- package/input/types.d.ts +3 -5
- package/internal/lazy-loading/LazyLoading.d.ts +3 -0
- package/internal/lazy-loading/LazyLoading.js +9 -0
- package/internal/lazy-loading/index.d.ts +2 -0
- package/internal/lazy-loading/index.js +1 -0
- package/internal/lazy-loading/types.d.ts +7 -0
- package/internal/popup/Popup.d.ts +1 -1
- package/internal/popup/Popup.js +40 -68
- package/internal/popup/types.d.ts +13 -6
- package/internal/portal/Portal.d.ts +1 -1
- package/internal/portal/Portal.js +12 -6
- package/internal/portal/types.d.ts +3 -2
- package/mask/Mask.d.ts +3 -0
- package/mask/Mask.js +31 -0
- package/menu/Menu.d.ts +2 -4
- package/menu/Menu.js +37 -42
- package/menu/internal/MenuGroup.d.ts +1 -1
- package/menu/internal/MenuItem.d.ts +1 -1
- package/menu/internal/MenuItem.js +14 -10
- package/menu/internal/MenuSub.d.ts +2 -1
- package/menu/internal/MenuSub.js +43 -70
- package/menu/types.d.ts +1 -0
- package/modal/Modal.d.ts +1 -1
- package/modal/Modal.js +77 -80
- package/modal/ModalAlert.d.ts +1 -1
- package/modal/ModalFooter.d.ts +1 -1
- package/modal/ModalFooter.js +12 -9
- package/modal/ModalHeader.d.ts +1 -1
- package/modal/ModalHeader.js +10 -7
- package/modal/types.d.ts +9 -2
- package/modal/vars.d.ts +5 -0
- package/modal/vars.js +2 -0
- package/notification/Notification.d.ts +1 -1
- package/notification/Notification.js +44 -71
- package/notification/types.d.ts +1 -0
- package/package.json +2 -2
- package/pagination/Pagination.d.ts +1 -1
- package/pagination/Pagination.js +9 -6
- package/popover/Popover.d.ts +2 -2
- package/popover/Popover.js +82 -118
- package/popover/PopoverFooter.d.ts +1 -1
- package/popover/PopoverFooter.js +12 -9
- package/popover/PopoverHeader.d.ts +1 -1
- package/popover/PopoverHeader.js +10 -7
- package/popover/types.d.ts +18 -4
- package/popover/vars.d.ts +5 -0
- package/popover/vars.js +2 -0
- package/progress/Progress.d.ts +1 -1
- package/radio/Radio.d.ts +1 -1
- package/radio/Radio.js +18 -13
- package/radio/RadioGroup.d.ts +1 -1
- package/radio/RadioGroup.js +12 -7
- package/radio/types.d.ts +16 -4
- package/radio/vars.d.ts +6 -0
- package/radio/vars.js +2 -0
- package/rating/Rating.d.ts +1 -1
- package/rating/internal/RatingStar.d.ts +1 -1
- package/rating/internal/RatingStar.js +23 -21
- package/root/Root.d.ts +1 -1
- package/root/Root.js +1 -1
- package/select/Select.d.ts +2 -4
- package/select/Select.js +245 -243
- package/select/types.d.ts +3 -3
- package/separator/Separator.d.ts +1 -1
- package/skeleton/Skeleton.d.ts +1 -1
- package/slider/Slider.d.ts +1 -1
- package/slider/Slider.js +54 -34
- package/slider/types.d.ts +2 -3
- package/slides/Slides.d.ts +1 -1
- package/slides/Slides.js +8 -3
- package/spinner/Spinner.d.ts +1 -1
- package/spinner/Spinner.js +27 -29
- package/stepper/Stepper.d.ts +1 -1
- package/stepper/Stepper.js +9 -16
- package/switch/Switch.js +33 -24
- package/switch/types.d.ts +2 -3
- package/table/Table.d.ts +1 -1
- package/table/Table.js +14 -10
- package/table/TableEmpty.d.ts +1 -1
- package/table/TableEmpty.js +9 -3
- package/table/TableExpand.d.ts +1 -1
- package/table/TableFilter.d.ts +1 -1
- package/table/TableFilter.js +1 -1
- package/table/TableTd.d.ts +1 -1
- package/table/TableTh.d.ts +1 -1
- package/table/TableThAction.d.ts +1 -1
- package/table/TableThAction.js +3 -4
- package/table/internal/TableCell.d.ts +1 -1
- package/table/internal/TableCell.js +13 -5
- package/table/types.d.ts +9 -2
- package/tabs/Tabs.d.ts +2 -4
- package/tabs/Tabs.js +41 -25
- package/tabs/types.d.ts +1 -0
- package/tag/Tag.d.ts +1 -1
- package/textarea/Textarea.d.ts +1 -1
- package/textarea/Textarea.js +15 -8
- package/textarea/types.d.ts +1 -0
- package/time-picker/TimePicker.d.ts +2 -2
- package/time-picker/TimePicker.js +89 -75
- package/time-picker/internal/TimePickerPanel.d.ts +2 -1
- package/time-picker/internal/TimePickerPanel.js +22 -7
- package/time-picker/types.d.ts +3 -3
- package/timeline/Timeline.d.ts +1 -1
- package/toast/Toast.d.ts +1 -1
- package/toast/Toast.js +44 -72
- package/toast/types.d.ts +1 -0
- package/tooltip/Tooltip.d.ts +2 -2
- package/tooltip/Tooltip.js +50 -74
- package/tooltip/types.d.ts +10 -2
- package/transfer/Transfer.d.ts +1 -1
- package/transfer/internal/TransferPanel.d.ts +1 -1
- package/transfer/internal/TransferPanel.js +7 -2
- package/{internal/transition → transition}/CollapseTransition.d.ts +1 -1
- package/transition/CollapseTransition.js +65 -0
- package/transition/Transition.d.ts +3 -0
- package/transition/Transition.js +148 -0
- package/transition/types.d.ts +29 -0
- package/tree/Tree.d.ts +1 -1
- package/tree/Tree.js +19 -7
- package/tree/internal/TreePanel.d.ts +2 -2
- package/tree/internal/TreePanel.js +32 -26
- package/tree-select/TreeSelect.d.ts +2 -4
- package/tree-select/TreeSelect.js +216 -213
- package/tree-select/internal/TreeSelectSearchPanel.d.ts +2 -2
- package/tree-select/internal/TreeSelectSearchPanel.js +15 -6
- package/tree-select/types.d.ts +3 -3
- package/types.d.ts +1 -1
- package/upload/Upload.d.ts +1 -3
- package/upload/Upload.js +41 -50
- package/upload/UploadAction.d.ts +1 -1
- package/upload/UploadAction.js +19 -16
- package/upload/UploadButton.d.ts +1 -1
- package/upload/UploadButton.js +16 -12
- package/upload/UploadList.d.ts +1 -1
- package/upload/UploadList.js +52 -47
- package/upload/UploadPicture.d.ts +1 -1
- package/upload/UploadPicture.js +47 -53
- package/upload/UploadPictureList.d.ts +1 -1
- package/upload/UploadPictureList.js +52 -47
- package/upload/UploadPreviewAction.d.ts +1 -1
- package/upload/UploadPreviewAction.js +15 -14
- package/upload/hooks.d.ts +2 -0
- package/upload/types.d.ts +27 -6
- package/upload/vars.d.ts +11 -0
- package/upload/vars.js +3 -0
- package/virtual-scroll/VirtualScroll.d.ts +2 -4
- package/virtual-scroll/VirtualScroll.js +13 -21
- package/virtual-scroll/types.d.ts +2 -1
- package/wave/Wave.d.ts +3 -0
- package/{internal/wave → wave}/Wave.js +6 -6
- package/{internal/wave → wave}/types.d.ts +1 -0
- package/wave/types.js +1 -0
- package/LICENSE +0 -21
- package/hooks/useJSS.d.ts +0 -1
- package/hooks/useJSS.js +0 -15
- package/hooks/useNextTick.d.ts +0 -2
- package/internal/mask/Mask.d.ts +0 -3
- package/internal/mask/Mask.js +0 -36
- package/internal/transition/CollapseTransition.js +0 -101
- package/internal/transition/Transition.d.ts +0 -3
- package/internal/transition/Transition.js +0 -87
- package/internal/transition/types.d.ts +0 -33
- package/internal/wave/Wave.d.ts +0 -3
- /package/{internal/circular-progress → circular-progress}/index.d.ts +0 -0
- /package/{internal/circular-progress → circular-progress}/index.js +0 -0
- /package/{internal/circular-progress → circular-progress}/vars.d.ts +0 -0
- /package/{internal/circular-progress → circular-progress}/vars.js +0 -0
- /package/internal/{mask → lazy-loading}/types.js +0 -0
- /package/{internal/mask → mask}/index.d.ts +0 -0
- /package/{internal/mask → mask}/index.js +0 -0
- /package/{internal/mask → mask}/types.d.ts +0 -0
- /package/{internal/transition → mask}/types.js +0 -0
- /package/{internal/mask → mask}/vars.d.ts +0 -0
- /package/{internal/mask → mask}/vars.js +0 -0
- /package/{internal/transition → transition}/index.d.ts +0 -0
- /package/{internal/transition → transition}/index.js +0 -0
- /package/{internal/wave → transition}/types.js +0 -0
- /package/{hooks/useNextTick.js → upload/hooks.js} +0 -0
- /package/{internal/wave → wave}/index.d.ts +0 -0
- /package/{internal/wave → wave}/index.js +0 -0
- /package/{internal/wave → wave}/vars.d.ts +0 -0
- /package/{internal/wave → wave}/vars.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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
|
+
|
|
5
15
|
## [1.6.1](https://github.com/laser-ui/laser-ui/compare/v1.6.0...v1.6.1) (2024-11-17)
|
|
6
16
|
|
|
7
17
|
### Bug Fixes
|
package/accordion/Accordion.d.ts
CHANGED
|
@@ -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>):
|
|
3
|
+
export declare function Accordion<ID extends React.Key, T extends AccordionItem<ID>>(props: AccordionProps<ID, T>): React.ReactElement | null;
|
package/accordion/Accordion.js
CHANGED
|
@@ -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 {
|
|
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, {
|
|
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
|
-
},
|
|
139
|
+
}, onAfterLeave: () => {
|
|
157
140
|
afterActiveChange === null || afterActiveChange === void 0 ? void 0 : afterActiveChange(itemId, item, false);
|
|
158
|
-
}, children: (
|
|
159
|
-
|
|
160
|
-
|
|
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
|
}
|
package/accordion/types.d.ts
CHANGED
|
@@ -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
|
|
3
|
-
export declare
|
|
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,
|
|
2
|
+
import { useEventCallback, useIsomorphicLayoutEffect, useRefExtra, useResize } from '@laser-ui/hooks';
|
|
3
3
|
import { getOffsetToRoot, toPx } from '@laser-ui/utils';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { useComponentProps, useContainerScrolling,
|
|
7
|
-
export
|
|
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
|
|
24
|
-
setSticky(
|
|
25
|
-
if (
|
|
26
|
-
affixRef.current.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
style:
|
|
54
|
+
return (_jsxs(_Fragment, { children: [children({
|
|
55
|
+
style: { visibility: 'hidden' },
|
|
58
56
|
'aria-hidden': true,
|
|
59
57
|
'data-l-affix-placeholder': uniqueId,
|
|
60
|
-
}),
|
|
61
|
-
|
|
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
|
-
|
|
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
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 '../
|
|
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, {
|
|
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
|
-
},
|
|
27
|
+
}, onAfterLeave: () => {
|
|
42
28
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
43
|
-
}, children: (
|
|
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(
|
|
51
|
-
}), { ref:
|
|
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
|
}
|
package/anchor/Anchor.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { AnchorItem, AnchorProps
|
|
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>
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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:
|
|
101
|
-
|
|
102
|
-
|
|
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;
|
package/avatar/Avatar.d.ts
CHANGED
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 {
|
|
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
|
-
|
|
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:
|
|
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
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 '../
|
|
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
|
|
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 =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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({},
|
|
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;
|
package/badge/BadgeText.js
CHANGED
|
@@ -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 '../
|
|
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,
|
|
12
|
+
return (_jsx(Transition, { enter: text.length > 0, name: `${namespace}-badge`, duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => {
|
|
12
13
|
var _a;
|
|
13
|
-
|
|
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({},
|
|
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
|
-
|
|
7
|
+
num: number;
|
|
8
8
|
}
|
|
9
|
-
export declare function BadgeNumber(props: BadgeNumberProps):
|
|
9
|
+
export declare function BadgeNumber(props: BadgeNumberProps): React.ReactElement | null;
|
|
10
10
|
export {};
|