@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/internal/popup/Popup.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useAsync, useEvent, useRefExtra, useResize } from '@laser-ui/hooks';
|
|
2
2
|
import { isUndefined } from 'lodash';
|
|
3
|
-
import {
|
|
3
|
+
import { useRef } from 'react';
|
|
4
4
|
import { useContainerScrolling, useLayout } from '../../hooks';
|
|
5
5
|
export function Popup(props) {
|
|
6
6
|
const { children, visible: visibleProp, trigger, disabled = false, mouseEnterDelay = 150, mouseLeaveDelay = 200, updatePosition, onVisibleChange, } = props;
|
|
7
7
|
const { contentResizeRef } = useLayout();
|
|
8
8
|
const windowRef = useRefExtra(() => window);
|
|
9
|
-
const
|
|
9
|
+
const clearTid = useRef(() => { });
|
|
10
|
+
const clearClickOut = useRef(() => { });
|
|
10
11
|
const async = useAsync();
|
|
11
12
|
const handleTrigger = (visible, behavior) => {
|
|
12
|
-
|
|
13
|
-
(_b = (_a = dataRef.current).clearTid) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
13
|
+
clearTid.current();
|
|
14
14
|
const changeVisible = () => {
|
|
15
15
|
if (isUndefined(visible)) {
|
|
16
16
|
onVisibleChange(!visibleProp);
|
|
@@ -23,15 +23,15 @@ export function Popup(props) {
|
|
|
23
23
|
switch (behavior) {
|
|
24
24
|
case 'hover':
|
|
25
25
|
if (visible) {
|
|
26
|
-
|
|
26
|
+
clearTid.current = async.setTimeout(() => changeVisible(), mouseEnterDelay);
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
|
|
29
|
+
clearTid.current = async.setTimeout(() => changeVisible(), mouseLeaveDelay);
|
|
30
30
|
}
|
|
31
31
|
break;
|
|
32
32
|
case 'popup-hover':
|
|
33
33
|
if (!visible) {
|
|
34
|
-
|
|
34
|
+
clearTid.current = async.setTimeout(() => changeVisible(), mouseLeaveDelay);
|
|
35
35
|
}
|
|
36
36
|
break;
|
|
37
37
|
default:
|
|
@@ -47,73 +47,45 @@ export function Popup(props) {
|
|
|
47
47
|
useResize(updatePosition.popupRef, updatePosition.fn, undefined, disabled || !visibleProp);
|
|
48
48
|
useResize(contentResizeRef, updatePosition.fn, undefined, disabled || !visibleProp);
|
|
49
49
|
useEvent(windowRef, 'click', () => {
|
|
50
|
-
|
|
50
|
+
clearClickOut.current = async.requestAnimationFrame(() => {
|
|
51
51
|
handleTrigger(false);
|
|
52
52
|
});
|
|
53
53
|
}, { capture: true }, disabled || !visibleProp || trigger !== 'click');
|
|
54
54
|
return children({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
break;
|
|
73
|
-
case 'click':
|
|
74
|
-
triggerProps.onClick = (e) => {
|
|
75
|
-
var _a, _b, _c, _d;
|
|
76
|
-
(_b = (_a = el.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
77
|
-
(_d = (_c = dataRef.current).clearClickOut) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
78
|
-
handleTrigger();
|
|
79
|
-
};
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
return cloneElement(el, triggerProps);
|
|
55
|
+
trigger: {
|
|
56
|
+
onClick: () => {
|
|
57
|
+
if (!disabled && trigger === 'click') {
|
|
58
|
+
clearClickOut.current();
|
|
59
|
+
handleTrigger();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
onMouseEnter: () => {
|
|
63
|
+
if (!disabled && trigger === 'hover') {
|
|
64
|
+
handleTrigger(true, 'hover');
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
onMouseLeave: () => {
|
|
68
|
+
if (!disabled && trigger === 'hover') {
|
|
69
|
+
handleTrigger(false, 'hover');
|
|
70
|
+
}
|
|
71
|
+
},
|
|
85
72
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const popupProps = {};
|
|
91
|
-
if (visibleProp) {
|
|
92
|
-
switch (trigger) {
|
|
93
|
-
case 'hover':
|
|
94
|
-
popupProps.onMouseEnter = (e) => {
|
|
95
|
-
var _a, _b;
|
|
96
|
-
(_b = (_a = el.props).onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
97
|
-
handleTrigger(true, 'popup-hover');
|
|
98
|
-
};
|
|
99
|
-
popupProps.onMouseLeave = (e) => {
|
|
100
|
-
var _a, _b;
|
|
101
|
-
(_b = (_a = el.props).onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
102
|
-
handleTrigger(false, 'popup-hover');
|
|
103
|
-
};
|
|
104
|
-
break;
|
|
105
|
-
case 'click':
|
|
106
|
-
popupProps.onClick = (e) => {
|
|
107
|
-
var _a, _b, _c, _d;
|
|
108
|
-
(_b = (_a = el.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
109
|
-
(_d = (_c = dataRef.current).clearClickOut) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
110
|
-
};
|
|
111
|
-
break;
|
|
112
|
-
default:
|
|
113
|
-
break;
|
|
73
|
+
popup: {
|
|
74
|
+
onClick: () => {
|
|
75
|
+
if (!disabled && visibleProp && trigger === 'click') {
|
|
76
|
+
clearClickOut.current();
|
|
114
77
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
78
|
+
},
|
|
79
|
+
onMouseEnter: () => {
|
|
80
|
+
if (!disabled && visibleProp && trigger === 'hover') {
|
|
81
|
+
handleTrigger(true, 'popup-hover');
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
onMouseLeave: () => {
|
|
85
|
+
if (!disabled && visibleProp && trigger === 'hover') {
|
|
86
|
+
handleTrigger(false, 'popup-hover');
|
|
87
|
+
}
|
|
88
|
+
},
|
|
117
89
|
},
|
|
118
90
|
});
|
|
119
91
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { CloneHTMLElement } from '../../types';
|
|
3
2
|
export {};
|
|
4
3
|
export interface PopupProps {
|
|
5
4
|
children: (props: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
trigger: {
|
|
6
|
+
onClick: React.MouseEventHandler<HTMLElement>;
|
|
7
|
+
onMouseEnter: React.MouseEventHandler<HTMLElement>;
|
|
8
|
+
onMouseLeave: React.MouseEventHandler<HTMLElement>;
|
|
9
|
+
};
|
|
10
|
+
popup: {
|
|
11
|
+
onClick: React.MouseEventHandler<HTMLElement>;
|
|
12
|
+
onMouseEnter: React.MouseEventHandler<HTMLElement>;
|
|
13
|
+
onMouseLeave: React.MouseEventHandler<HTMLElement>;
|
|
14
|
+
};
|
|
15
|
+
}) => React.ReactElement | null;
|
|
9
16
|
visible: boolean;
|
|
10
17
|
trigger: 'hover' | 'click';
|
|
11
18
|
disabled?: boolean;
|
|
@@ -13,8 +20,8 @@ export interface PopupProps {
|
|
|
13
20
|
mouseLeaveDelay?: number;
|
|
14
21
|
updatePosition: {
|
|
15
22
|
fn: () => void;
|
|
16
|
-
triggerRef: React.RefObject<HTMLElement>;
|
|
17
|
-
popupRef: React.RefObject<HTMLElement>;
|
|
23
|
+
triggerRef: React.RefObject<HTMLElement | null>;
|
|
24
|
+
popupRef: React.RefObject<HTMLElement | null>;
|
|
18
25
|
scroll?: boolean;
|
|
19
26
|
};
|
|
20
27
|
onVisibleChange: (visible: boolean) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { PortalProps } from './types';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function Portal<T extends Element = HTMLElement>(props: PortalProps<T>): React.ReactElement | null;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { useIsomorphicLayoutEffect } from '@laser-ui/hooks';
|
|
2
2
|
import { isString } from 'lodash';
|
|
3
|
-
import {
|
|
3
|
+
import { useImperativeHandle, useState } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
|
-
export
|
|
6
|
-
const { children, selector } = props;
|
|
7
|
-
const
|
|
5
|
+
export function Portal(props) {
|
|
6
|
+
const { ref, children, selector } = props;
|
|
7
|
+
const getContainer = () => (isString(selector) ? document.querySelector(selector) : selector());
|
|
8
|
+
const [container, setContainer] = useState(() => {
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
return getContainer();
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
});
|
|
8
14
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9
15
|
useIsomorphicLayoutEffect(() => {
|
|
10
|
-
setContainer(
|
|
16
|
+
setContainer(getContainer());
|
|
11
17
|
});
|
|
12
18
|
useImperativeHandle(ref, () => container, [container]);
|
|
13
19
|
return container && createPortal(children, container);
|
|
14
|
-
}
|
|
20
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export {};
|
|
3
|
-
export interface PortalProps {
|
|
3
|
+
export interface PortalProps<T extends Element = HTMLElement> {
|
|
4
|
+
ref?: React.Ref<T | null>;
|
|
4
5
|
children: React.ReactNode;
|
|
5
|
-
selector: (() =>
|
|
6
|
+
selector: (() => T | null) | string;
|
|
6
7
|
}
|
package/mask/Mask.d.ts
ADDED
package/mask/Mask.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CLASSES } from './vars';
|
|
4
|
+
import { useNamespace, useStyled } from '../hooks';
|
|
5
|
+
import { Transition } from '../transition';
|
|
6
|
+
import { mergeCS } from '../utils';
|
|
7
|
+
import { TTANSITION_DURING_FAST } from '../vars';
|
|
8
|
+
export function Mask(props) {
|
|
9
|
+
const { visible, onClose, afterVisibleChange } = props, restProps = __rest(props, ["visible", "onClose", "afterVisibleChange"]);
|
|
10
|
+
const namespace = useNamespace();
|
|
11
|
+
const styled = useStyled(CLASSES, { mask: undefined });
|
|
12
|
+
return (_jsx(Transition, { enter: visible, name: `${namespace}-fade`, duration: TTANSITION_DURING_FAST,
|
|
13
|
+
// TODO: Should it be controllable?
|
|
14
|
+
skipFirstTransition: false, onAfterEnter: () => {
|
|
15
|
+
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
|
|
16
|
+
}, onAfterLeave: () => {
|
|
17
|
+
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
18
|
+
}, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, restProps, mergeCS(styled('mask'), {
|
|
19
|
+
className: restProps.className,
|
|
20
|
+
style: Object.assign(Object.assign(Object.assign({}, restProps.style), { '--fade-duration': TTANSITION_DURING_FAST + 'ms' }), (leaved ? { display: 'none' } : undefined)),
|
|
21
|
+
}), { ref: (instance) => {
|
|
22
|
+
transitionRef(instance);
|
|
23
|
+
return () => {
|
|
24
|
+
transitionRef(null);
|
|
25
|
+
};
|
|
26
|
+
}, onClick: (e) => {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = restProps.onClick) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
29
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
30
|
+
} }))) }));
|
|
31
|
+
}
|
package/menu/Menu.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { MenuItem, MenuProps
|
|
3
|
-
declare function
|
|
4
|
-
export declare const Menu: <ID extends React.Key, T extends MenuItem<ID>>(props: MenuProps<ID, T> & React.RefAttributes<MenuRef>) => ReturnType<typeof MenuFC>;
|
|
5
|
-
export {};
|
|
2
|
+
import type { MenuItem, MenuProps } from './types';
|
|
3
|
+
export declare function Menu<ID extends React.Key, T extends MenuItem<ID>>(props: MenuProps<ID, T>): React.ReactElement | null;
|
package/menu/Menu.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEventCallback } from '@laser-ui/hooks';
|
|
3
4
|
import { findNested } from '@laser-ui/utils';
|
|
4
5
|
import { isNull, isUndefined, nth } from 'lodash';
|
|
5
|
-
import { Fragment,
|
|
6
|
+
import { Fragment, useId, useImperativeHandle, useRef, useState } from 'react';
|
|
6
7
|
import { MenuGroup } from './internal/MenuGroup';
|
|
7
8
|
import { MenuItem as MenuItemFC } from './internal/MenuItem';
|
|
8
9
|
import { MenuSub } from './internal/MenuSub';
|
|
9
10
|
import { checkEnableItem, getSameLevelEnableItems } from './utils';
|
|
10
11
|
import { CLASSES } from './vars';
|
|
11
12
|
import { useComponentProps, useContainerScrolling, useControlled, useFocusVisible, useNamespace, useNestedPopup, useStyled, } from '../hooks';
|
|
12
|
-
import { CollapseTransition } from '../
|
|
13
|
+
import { CollapseTransition } from '../transition';
|
|
13
14
|
import { mergeCS } from '../utils';
|
|
14
15
|
import { TTANSITION_DURING_BASE } from '../vars';
|
|
15
|
-
function
|
|
16
|
-
const _a = useComponentProps('Menu', props), { styleOverrides, styleProvider, list, mode = 'vertical', width = 'auto', active: activeProp, defaultActive, expands: expandsProp, defaultExpands, expandOne = false, expandTrigger, escClosable = true, onActiveChange, onExpandsChange } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "list", "mode", "width", "active", "defaultActive", "expands", "defaultExpands", "expandOne", "expandTrigger", "escClosable", "onActiveChange", "onExpandsChange"]);
|
|
16
|
+
export function Menu(props) {
|
|
17
|
+
const _a = useComponentProps('Menu', props), { ref, styleOverrides, styleProvider, list, mode = 'vertical', width = 'auto', active: activeProp, defaultActive, expands: expandsProp, defaultExpands, expandOne = false, expandTrigger, escClosable = true, onActiveChange, onExpandsChange } = _a, restProps = __rest(_a, ["ref", "styleOverrides", "styleProvider", "list", "mode", "width", "active", "defaultActive", "expands", "defaultExpands", "expandOne", "expandTrigger", "escClosable", "onActiveChange", "onExpandsChange"]);
|
|
17
18
|
const namespace = useNamespace();
|
|
18
19
|
const styled = useStyled(CLASSES, { menu: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.menu, 'menu-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['menu-popup'] }, styleOverrides);
|
|
19
20
|
const uniqueId = useId();
|
|
20
21
|
const getItemId = (id) => `${namespace}-menu-item-${id}-${uniqueId}`;
|
|
21
22
|
const menuRef = useRef(null);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
const [focusVisible, focusVisibleWrapper] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
|
|
23
|
+
const mousedown = useRef(false);
|
|
24
|
+
const updateSubPosition = useRef(new Map());
|
|
25
|
+
const [focusVisible, focusVisibleProps] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
|
|
27
26
|
const [active, changeActive] = useControlled(defaultActive !== null && defaultActive !== void 0 ? defaultActive : null, activeProp, (id) => {
|
|
28
27
|
if (onActiveChange) {
|
|
29
28
|
onActiveChange(id, findNested(list, (item) => item.id === id));
|
|
@@ -290,13 +289,13 @@ function MenuFC(props, ref) {
|
|
|
290
289
|
}
|
|
291
290
|
return (_jsx(Fragment, { children: itemType === 'item' ? (_jsx(MenuItemFC, { namespace: namespace, styled: styled, id: id, level: level, space: space, step: step, icon: itemIcon,
|
|
292
291
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
293
|
-
posinset: posinset.get(itemId), mode: mode, inNav: inNav, active: active === itemId, focus: focusVisible && isFocus, disabled: itemDisabled, onClick: handleItemClick, children: itemTitle })) : itemType === 'group' ? (_jsx(MenuGroup, { styled: styled, id: id, level: level, space: space, step: step, list: children && getNodes(children, level + 1, nextSubParents), empty: isEmpty, children: itemTitle })) : (_jsx(MenuSub, { ref: (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
292
|
+
posinset: posinset.get(itemId), mode: mode, inNav: inNav, active: active === itemId, focus: focusVisible && isFocus, disabled: itemDisabled, onClick: handleItemClick, children: itemTitle })) : itemType === 'group' ? (_jsx(MenuGroup, { styled: styled, id: id, level: level, space: space, step: step, list: children && getNodes(children, level + 1, nextSubParents), empty: isEmpty, children: itemTitle })) : (_jsx(MenuSub, { ref: (instance) => {
|
|
293
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
294
|
+
const fn = instance;
|
|
295
|
+
updateSubPosition.current.set(itemId, fn);
|
|
296
|
+
return () => {
|
|
297
|
+
updateSubPosition.current.delete(itemId);
|
|
298
|
+
};
|
|
300
299
|
}, namespace: namespace, styled: styled, id: id, level: level, space: space, step: step, icon: itemIcon, list: children && getNodes(children, mode === 'vertical' ? level + 1 : 0, nextSubParents), popupState: popupState === null || popupState === void 0 ? void 0 : popupState.visible, trigger: expandTrigger !== null && expandTrigger !== void 0 ? expandTrigger : (mode === 'vertical' ? 'click' : 'hover'),
|
|
301
300
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
302
301
|
posinset: posinset.get(itemId), mode: mode, inNav: inNav, active: (mode === 'vertical' ? !isExpand : isUndefined(popupState)) && actives.includes(itemId), includeActive: actives.includes(itemId), expand: isExpand, empty: isEmpty, focus: focusVisible && isFocus, disabled: itemDisabled, onVisibleChange: (visible) => {
|
|
@@ -325,53 +324,50 @@ function MenuFC(props, ref) {
|
|
|
325
324
|
};
|
|
326
325
|
return getNodes(list, 0, [], true);
|
|
327
326
|
})();
|
|
328
|
-
const updatePosition =
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
const updatePosition = useEventCallback(() => {
|
|
328
|
+
var _a;
|
|
329
|
+
for (const { id } of popupIds) {
|
|
330
|
+
(_a = updateSubPosition.current.get(id)) === null || _a === void 0 ? void 0 : _a();
|
|
331
331
|
}
|
|
332
|
-
}
|
|
332
|
+
});
|
|
333
333
|
useContainerScrolling(menuRef, updatePosition);
|
|
334
334
|
useImperativeHandle(ref, () => ({ updatePosition }), [updatePosition]);
|
|
335
|
-
return (_jsx(CollapseTransition, {
|
|
336
|
-
width,
|
|
337
|
-
}, collapsedSize: {
|
|
338
|
-
width: 64,
|
|
339
|
-
}, enter: mode !== 'icon', during: TTANSITION_DURING_BASE, styles: {
|
|
340
|
-
entering: {
|
|
341
|
-
transition: ['width', 'padding', 'margin'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms linear`).join(', '),
|
|
342
|
-
},
|
|
343
|
-
leaving: {
|
|
344
|
-
transition: ['width', 'padding', 'margin'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms linear`).join(', '),
|
|
345
|
-
},
|
|
346
|
-
}, children: (collapseRef, collapseStyle) => {
|
|
335
|
+
return (_jsx(CollapseTransition, { width: 64, enter: mode !== 'icon', duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => {
|
|
347
336
|
var _a;
|
|
348
337
|
const preventBlur = (e) => {
|
|
349
338
|
if (document.activeElement === e.currentTarget && e.button === 0) {
|
|
350
339
|
e.preventDefault();
|
|
351
340
|
}
|
|
352
341
|
};
|
|
353
|
-
return
|
|
342
|
+
return (
|
|
354
343
|
// eslint-disable-next-line jsx-a11y/aria-activedescendant-has-tabindex
|
|
355
344
|
_jsx("nav", Object.assign({}, restProps, mergeCS(styled('menu', { 'menu--horizontal': mode === 'horizontal' }), {
|
|
356
345
|
className: restProps.className,
|
|
357
|
-
style: Object.assign(Object.assign(Object.assign({}, restProps.style), { width }),
|
|
358
|
-
}), { ref: (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
346
|
+
style: Object.assign(Object.assign(Object.assign({}, restProps.style), { width }), (leaved ? { width: 64 } : undefined)),
|
|
347
|
+
}), { ref: (instance) => {
|
|
348
|
+
menuRef.current = instance;
|
|
349
|
+
transitionRef(instance);
|
|
350
|
+
return () => {
|
|
351
|
+
menuRef.current = null;
|
|
352
|
+
transitionRef(null);
|
|
353
|
+
};
|
|
354
|
+
}, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : 0, role: "menubar", "aria-orientation": mode === 'horizontal' ? 'horizontal' : 'vertical', "aria-activedescendant": isUndefined(focusId) ? undefined : getItemId(focusId) }, focusVisibleProps, { onFocus: (e) => {
|
|
362
355
|
var _a;
|
|
363
356
|
(_a = restProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
364
|
-
|
|
357
|
+
focusVisibleProps.onFocus(e);
|
|
358
|
+
if (!mousedown.current) {
|
|
365
359
|
initFocus();
|
|
366
360
|
}
|
|
367
|
-
|
|
361
|
+
mousedown.current = false;
|
|
368
362
|
}, onBlur: (e) => {
|
|
369
363
|
var _a;
|
|
370
364
|
(_a = restProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
365
|
+
focusVisibleProps.onBlur(e);
|
|
371
366
|
setPopupIds([]);
|
|
372
367
|
}, onKeyDown: (e) => {
|
|
373
368
|
var _a;
|
|
374
369
|
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
370
|
+
focusVisibleProps.onKeyDown(e);
|
|
375
371
|
if (popupIds.length > 0 && escClosable && e.code === 'Escape') {
|
|
376
372
|
e.stopPropagation();
|
|
377
373
|
e.preventDefault();
|
|
@@ -383,7 +379,7 @@ function MenuFC(props, ref) {
|
|
|
383
379
|
}, onMouseDown: (e) => {
|
|
384
380
|
var _a;
|
|
385
381
|
(_a = restProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
386
|
-
|
|
382
|
+
mousedown.current = true;
|
|
387
383
|
preventBlur(e);
|
|
388
384
|
}, onMouseUp: (e) => {
|
|
389
385
|
var _a;
|
|
@@ -392,4 +388,3 @@ function MenuFC(props, ref) {
|
|
|
392
388
|
}, children: nodes })));
|
|
393
389
|
} }));
|
|
394
390
|
}
|
|
395
|
-
export const Menu = forwardRef(MenuFC);
|
|
@@ -6,14 +6,18 @@ export function MenuItem(props) {
|
|
|
6
6
|
const { children, namespace, styled, id, level, space, step, icon, posinset, mode, inNav, active, focus, disabled, onClick } = props;
|
|
7
7
|
const inHorizontalNav = mode === 'horizontal' && inNav;
|
|
8
8
|
const iconMode = mode === 'icon' && inNav;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
return (_jsx(Tooltip, { title: children, placement: "right", children: (tooltipProps) => (_jsxs("li", Object.assign({}, mergeCS(styled('menu__item', 'menu__item--item', {
|
|
10
|
+
'menu__item--horizontal': inHorizontalNav,
|
|
11
|
+
'menu__item--icon': iconMode,
|
|
12
|
+
'menu__item.is-active': active,
|
|
13
|
+
'menu__item.is-disabled': disabled,
|
|
14
|
+
}), { style: { paddingLeft: space + level * step } }), (iconMode ? tooltipProps : undefined), { id: id, role: "menuitem", "aria-disabled": disabled, onClick: (e) => {
|
|
15
|
+
if (iconMode) {
|
|
16
|
+
tooltipProps.onClick(e);
|
|
17
|
+
}
|
|
18
|
+
onClick();
|
|
19
|
+
}, children: [focus && _jsx("div", { className: `${namespace}-focus-outline` }), _jsxs("div", Object.assign({}, styled('menu__indicator', {
|
|
20
|
+
'menu__indicator--first': posinset[0] === 0 && posinset[1] > 1,
|
|
21
|
+
'menu__indicator--last': posinset[0] === posinset[1] - 1 && posinset[1] > 1,
|
|
22
|
+
}), { children: [_jsx("div", Object.assign({}, styled('menu__indicator-track', { 'menu__indicator-track--hidden': level === 0 }))), _jsx("div", Object.assign({}, styled('menu__indicator-thumb')))] })), checkNodeExist(icon) && _jsx("div", Object.assign({}, styled('menu__item-icon'), { children: icon })), _jsx("div", Object.assign({}, styled('menu__item-content'), { children: children }))] }))) }));
|
|
19
23
|
}
|
|
@@ -3,6 +3,7 @@ import type { Styled } from '../../hooks/useStyled';
|
|
|
3
3
|
import type { MenuMode } from '../types';
|
|
4
4
|
import type { CLASSES } from '../vars';
|
|
5
5
|
interface MenuSubProps {
|
|
6
|
+
ref?: React.RefCallback<() => void>;
|
|
6
7
|
children: React.ReactNode;
|
|
7
8
|
namespace: string;
|
|
8
9
|
styled: Styled<typeof CLASSES>;
|
|
@@ -26,5 +27,5 @@ interface MenuSubProps {
|
|
|
26
27
|
onVisibleChange: (visible: boolean) => void;
|
|
27
28
|
onClick: React.MouseEventHandler<HTMLLIElement>;
|
|
28
29
|
}
|
|
29
|
-
export declare
|
|
30
|
+
export declare function MenuSub(props: MenuSubProps): React.ReactElement | null;
|
|
30
31
|
export {};
|