@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.
- package/CHANGELOG.md +16 -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 +95 -110
- 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/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/dropdown/Dropdown.js
CHANGED
|
@@ -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 {
|
|
6
|
-
import { Fragment,
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|
35
|
-
|
|
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
|
-
|
|
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: (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
|
260
|
-
|
|
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 }), [
|
|
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: (
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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):
|
|
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):
|
|
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
|
|
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 {
|
|
7
|
-
import {
|
|
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 '../../
|
|
11
|
+
import { Transition } from '../../transition';
|
|
12
12
|
import { getHorizontalSidePosition, mergeCS } from '../../utils';
|
|
13
13
|
import { TTANSITION_DURING_POPUP, WINDOW_SPACE } from '../../vars';
|
|
14
|
-
export
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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: (
|
|
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:
|
|
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,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|
package/dropdown/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { CLASSES } from './vars';
|
|
3
|
-
import type { BaseProps,
|
|
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
|
-
|
|
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
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):
|
|
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 {
|
|
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: [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 }
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
package/fab/FabBacktop.d.ts
CHANGED
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 {
|
|
7
|
+
import { useRef, useState } from 'react';
|
|
8
8
|
import { FabButton } from './FabButton';
|
|
9
|
-
import {
|
|
9
|
+
import { FabBacktopContext } from './vars';
|
|
10
|
+
import { useComponentProps, useLayout, useNamespace } from '../hooks';
|
|
10
11
|
import { Icon } from '../icon';
|
|
11
|
-
import { Transition } from '../
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
}
|
package/fab/FabButton.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { FabButtonProps } from './types';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function FabButton(props: FabButtonProps): React.ReactElement | null;
|