@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
|
@@ -12,23 +12,25 @@ import { useId, useRef } from 'react';
|
|
|
12
12
|
import { CLASSES, TTANSITION_DURING } from './vars';
|
|
13
13
|
import { useComponentProps, useNamespace, useStyled, useTranslation } from '../hooks';
|
|
14
14
|
import { Icon } from '../icon';
|
|
15
|
+
import { LazyLoading } from '../internal/lazy-loading';
|
|
15
16
|
import { Portal } from '../internal/portal';
|
|
16
|
-
import {
|
|
17
|
+
import { CollapseTransition } from '../transition';
|
|
17
18
|
import { mergeCS } from '../utils';
|
|
18
19
|
export function Notification(props) {
|
|
19
|
-
const _a = useComponentProps('Notification', props), { children, styleOverrides, styleProvider, visible, title, type, placement = 'right-top', duration = 9.6, icon, closable = true, escClosable = true, skipFirstTransition = true, destroyAfterClose = true, onClose, afterVisibleChange } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "visible", "title", "type", "placement", "duration", "icon", "closable", "escClosable", "skipFirstTransition", "destroyAfterClose", "onClose", "afterVisibleChange"]);
|
|
20
|
+
const _a = useComponentProps('Notification', props), { children, styleOverrides, styleProvider, visible, title, type, placement = 'right-top', duration = 9.6, icon, closable = true, escClosable = true, skipFirstTransition = true, destroyAfterClose = false, lazyLoading = true, onClose, afterVisibleChange } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "visible", "title", "type", "placement", "duration", "icon", "closable", "escClosable", "skipFirstTransition", "destroyAfterClose", "lazyLoading", "onClose", "afterVisibleChange"]);
|
|
20
21
|
const namespace = useNamespace();
|
|
21
22
|
const styled = useStyled(CLASSES, { notification: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.notification }, styleOverrides);
|
|
22
23
|
const { t } = useTranslation();
|
|
23
24
|
const async = useAsync();
|
|
24
25
|
const notificationRef = useRef(null);
|
|
25
|
-
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
27
|
+
const clearTid = useRef(() => { });
|
|
26
28
|
const uniqueId = useId();
|
|
27
29
|
const titleId = `${namespace}-notification-title-${uniqueId}`;
|
|
28
30
|
const descriptionId = `${namespace}-notification-content-${uniqueId}`;
|
|
29
31
|
useMount(() => {
|
|
30
32
|
if (duration > 0) {
|
|
31
|
-
|
|
33
|
+
clearTid.current = async.setTimeout(() => {
|
|
32
34
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
33
35
|
}, duration * 1000);
|
|
34
36
|
}
|
|
@@ -54,76 +56,47 @@ export function Notification(props) {
|
|
|
54
56
|
root.appendChild(el);
|
|
55
57
|
}
|
|
56
58
|
return el;
|
|
57
|
-
}, children: _jsx(
|
|
59
|
+
}, children: _jsx(CollapseTransition, { height: 0, enter: visible, name: `${namespace}-notification`, duration: TTANSITION_DURING, skipFirstTransition: skipFirstTransition, onAfterEnter: () => {
|
|
58
60
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
|
|
59
|
-
},
|
|
61
|
+
}, onAfterLeave: () => {
|
|
60
62
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
61
|
-
}, children: (
|
|
63
|
+
}, children: (transitionRef, leaved) => {
|
|
62
64
|
var _a, _b;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
transitionStyle = { display: 'none' };
|
|
97
|
-
break;
|
|
98
|
-
default:
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
return (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('notification', {
|
|
102
|
-
[`notification--${type}`]: type,
|
|
103
|
-
}), {
|
|
104
|
-
className: restProps.className,
|
|
105
|
-
style: Object.assign(Object.assign({}, restProps.style), transitionStyle),
|
|
106
|
-
}), { ref: notificationRef, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : -1, role: (_b = restProps.role) !== null && _b !== void 0 ? _b : 'alert', "aria-labelledby": titleId, "aria-describedby": descriptionId, onMouseEnter: (e) => {
|
|
107
|
-
var _a, _b, _c;
|
|
108
|
-
(_a = restProps.onMouseEnter) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
109
|
-
(_c = (_b = dataRef.current).clearTid) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
110
|
-
}, onMouseLeave: (e) => {
|
|
111
|
-
var _a;
|
|
112
|
-
(_a = restProps.onMouseLeave) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
113
|
-
if (duration > 0) {
|
|
114
|
-
dataRef.current.clearTid = async.setTimeout(() => {
|
|
65
|
+
return (_jsx(LazyLoading, { hidden: leaved, disabled: !lazyLoading, children: leaved && destroyAfterClose ? null : (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('notification', {
|
|
66
|
+
[`notification--${type}`]: type,
|
|
67
|
+
}), {
|
|
68
|
+
className: restProps.className,
|
|
69
|
+
style: Object.assign(Object.assign(Object.assign({}, restProps.style), {
|
|
70
|
+
'--notification-transform': placement === 'left-top' || placement === 'left-bottom' ? 'translate(-100%, 0)' : 'translate(100%, 0)',
|
|
71
|
+
}), (leaved ? { display: 'none' } : undefined)),
|
|
72
|
+
}), { ref: (instance) => {
|
|
73
|
+
notificationRef.current = instance;
|
|
74
|
+
transitionRef(instance);
|
|
75
|
+
return () => {
|
|
76
|
+
notificationRef.current = null;
|
|
77
|
+
transitionRef(null);
|
|
78
|
+
};
|
|
79
|
+
}, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : -1, role: (_b = restProps.role) !== null && _b !== void 0 ? _b : 'alert', "aria-labelledby": titleId, "aria-describedby": descriptionId, onMouseEnter: (e) => {
|
|
80
|
+
var _a;
|
|
81
|
+
(_a = restProps.onMouseEnter) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
82
|
+
clearTid.current();
|
|
83
|
+
}, onMouseLeave: (e) => {
|
|
84
|
+
var _a;
|
|
85
|
+
(_a = restProps.onMouseLeave) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
86
|
+
if (duration > 0) {
|
|
87
|
+
clearTid.current = async.setTimeout(() => {
|
|
88
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
89
|
+
}, duration * 1000);
|
|
90
|
+
}
|
|
91
|
+
}, onKeyDown: (e) => {
|
|
92
|
+
var _a;
|
|
93
|
+
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
94
|
+
if (visible && escClosable && e.code === 'Escape') {
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
clearTid.current();
|
|
115
98
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}, onKeyDown: (e) => {
|
|
119
|
-
var _a, _b, _c;
|
|
120
|
-
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
121
|
-
if (visible && escClosable && e.code === 'Escape') {
|
|
122
|
-
e.stopPropagation();
|
|
123
|
-
e.preventDefault();
|
|
124
|
-
(_c = (_b = dataRef.current).clearTid) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
125
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
126
|
-
}
|
|
127
|
-
}, children: [icon !== false && (!isUndefined(type) || checkNodeExist(icon)) && (_jsx("div", Object.assign({}, styled('notification__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('notification__content'), { children: [_jsxs("div", Object.assign({}, styled('notification__header'), { children: [_jsx("div", Object.assign({}, styled('notification__title'), { id: titleId, children: title })), closable && (_jsx("button", Object.assign({}, styled('notification__close'), { "aria-label": t('Close'), onClick: onClose, children: _jsx(Icon, { children: _jsx(CloseOutlined, {}) }) })))] })), checkNodeExist(children) && (_jsx("div", Object.assign({}, styled('notification__description'), { id: descriptionId, children: children })))] }))] })));
|
|
99
|
+
}
|
|
100
|
+
}, children: [icon !== false && (!isUndefined(type) || checkNodeExist(icon)) && (_jsx("div", Object.assign({}, styled('notification__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('notification__content'), { children: [_jsxs("div", Object.assign({}, styled('notification__header'), { children: [_jsx("div", Object.assign({}, styled('notification__title'), { id: titleId, children: title })), closable && (_jsx("button", Object.assign({}, styled('notification__close'), { "aria-label": t('Close'), onClick: onClose, children: _jsx(Icon, { children: _jsx(CloseOutlined, {}) }) })))] })), checkNodeExist(children) && (_jsx("div", Object.assign({}, styled('notification__description'), { id: descriptionId, children: children })))] }))] }))) }));
|
|
128
101
|
} }) }));
|
|
129
102
|
}
|
package/notification/types.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface NotificationProps extends BaseProps<'notification', typeof CLAS
|
|
|
13
13
|
escClosable?: boolean;
|
|
14
14
|
skipFirstTransition?: boolean;
|
|
15
15
|
destroyAfterClose?: boolean;
|
|
16
|
+
lazyLoading?: boolean;
|
|
16
17
|
onClose?: () => void;
|
|
17
18
|
afterVisibleChange?: (visible: boolean) => void;
|
|
18
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laser-ui/components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"access": "public",
|
|
41
41
|
"directory": "../../dist/libs/components"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "abfcf4f3c2ed5f3046a50f8baa372ce9f7fa26b3"
|
|
44
44
|
}
|
package/pagination/Pagination.js
CHANGED
|
@@ -6,7 +6,7 @@ import KeyboardDoubleArrowLeftOutlined from '@material-design-icons/svg/outlined
|
|
|
6
6
|
import KeyboardDoubleArrowRightOutlined from '@material-design-icons/svg/outlined/keyboard_double_arrow_right.svg?react';
|
|
7
7
|
import MoreHorizOutlined from '@material-design-icons/svg/outlined/more_horiz.svg?react';
|
|
8
8
|
import { isNull, isNumber } from 'lodash';
|
|
9
|
-
import { Fragment,
|
|
9
|
+
import { Fragment, useRef, useState } from 'react';
|
|
10
10
|
import { buttonProps } from './utils';
|
|
11
11
|
import { CLASSES } from './vars';
|
|
12
12
|
import { useComponentProps, useControlled, useStyled, useTranslation } from '../hooks';
|
|
@@ -44,7 +44,12 @@ export function Pagination(props) {
|
|
|
44
44
|
}), {
|
|
45
45
|
className: restProps.className,
|
|
46
46
|
style: restProps.style,
|
|
47
|
-
}), { ref:
|
|
47
|
+
}), { ref: (instance) => {
|
|
48
|
+
navRef.current = instance;
|
|
49
|
+
return () => {
|
|
50
|
+
navRef.current = null;
|
|
51
|
+
};
|
|
52
|
+
}, role: "navigation", "aria-label": (_a = restProps['aria-label']) !== null && _a !== void 0 ? _a : 'Pagination Navigation', children: _jsx("div", Object.assign({}, styled('pagination__row'), { children: compose.map((item, index) => {
|
|
48
53
|
const gap = index === compose.length - 1 ? undefined : mini ? 2 : 6;
|
|
49
54
|
if (item === 'total') {
|
|
50
55
|
const totalNode = (() => {
|
|
@@ -165,10 +170,8 @@ export function Pagination(props) {
|
|
|
165
170
|
}
|
|
166
171
|
if (item === 'jump') {
|
|
167
172
|
const jumpNode = (() => {
|
|
168
|
-
const jumpInput = (_jsx(Input.Number, { style: { width: mini ? 48 : 72 }, model: jumpValue, max: lastPage, min: 1, step: 1, size: mini ? 'small' : undefined, numberButton: !mini,
|
|
173
|
+
const jumpInput = (_jsx(Input.Number, { style: { width: mini ? 48 : 72 }, model: jumpValue, max: lastPage, min: 1, step: 1, size: mini ? 'small' : undefined, numberButton: !mini, inputProps: {
|
|
169
174
|
onKeyDown: (e) => {
|
|
170
|
-
var _a, _b;
|
|
171
|
-
(_b = (_a = el.props).onKeyDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
172
175
|
if (e.code === 'Enter') {
|
|
173
176
|
e.preventDefault();
|
|
174
177
|
if (isNumber(jumpValue)) {
|
|
@@ -176,7 +179,7 @@ export function Pagination(props) {
|
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
},
|
|
179
|
-
}
|
|
182
|
+
}, onModelChange: setJumpValue }));
|
|
180
183
|
if (customRender && customRender.jump) {
|
|
181
184
|
return customRender.jump(jumpInput);
|
|
182
185
|
}
|
package/popover/Popover.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { PopoverProps
|
|
2
|
+
import type { PopoverProps } from './types';
|
|
3
3
|
import { PopoverFooter } from './PopoverFooter';
|
|
4
4
|
import { PopoverHeader } from './PopoverHeader';
|
|
5
5
|
export declare const Popover: {
|
|
6
|
-
(props: PopoverProps
|
|
6
|
+
(props: PopoverProps): React.ReactElement | null;
|
|
7
7
|
Header: typeof PopoverHeader;
|
|
8
8
|
Footer: typeof PopoverFooter;
|
|
9
9
|
};
|
package/popover/Popover.js
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
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
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { isString, isUndefined } from 'lodash';
|
|
5
|
+
import { useId, useImperativeHandle, useRef } from 'react';
|
|
6
6
|
import { PopoverFooter } from './PopoverFooter';
|
|
7
7
|
import { PopoverHeader } from './PopoverHeader';
|
|
8
|
-
import { CLASSES, TTANSITION_DURING } from './vars';
|
|
9
|
-
import { useComponentProps, useControlled,
|
|
8
|
+
import { CLASSES, PopoverContext, TTANSITION_DURING } from './vars';
|
|
9
|
+
import { useComponentProps, useControlled, useLockScroll, useMaxIndex, useNamespace, useStyled } from '../hooks';
|
|
10
|
+
import { LazyLoading } from '../internal/lazy-loading';
|
|
10
11
|
import { Popup } from '../internal/popup';
|
|
11
12
|
import { Portal } from '../internal/portal';
|
|
12
|
-
import { Transition } from '../
|
|
13
|
+
import { Transition } from '../transition';
|
|
13
14
|
import { getPopupPosition, handleModalKeyDown, mergeCS } from '../utils';
|
|
14
|
-
|
|
15
|
-
const _a = useComponentProps('Popover', props), { children, styleOverrides, styleProvider, content, header: headerProp, footer, visible: visibleProp, defaultVisible, trigger: triggerProp = 'hover', placement: placementProp = 'top', placementFixed = false, arrow = true, escClosable = true, gap = 10, inWindow = false, mouseEnterDelay = 150, mouseLeaveDelay = 200, modal = false, skipFirstTransition = true, destroyAfterClose = true, zIndex: zIndexProp, onVisibleChange, afterVisibleChange } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "content", "header", "footer", "visible", "defaultVisible", "trigger", "placement", "placementFixed", "arrow", "escClosable", "gap", "inWindow", "mouseEnterDelay", "mouseLeaveDelay", "modal", "skipFirstTransition", "destroyAfterClose", "zIndex", "onVisibleChange", "afterVisibleChange"]);
|
|
15
|
+
export const Popover = (props) => {
|
|
16
|
+
const _a = useComponentProps('Popover', props), { ref, children, styleOverrides, styleProvider, content, header: headerProp, footer, visible: visibleProp, defaultVisible, trigger: triggerProp = 'hover', placement: placementProp = 'top', placementFixed = false, arrow = true, escClosable = true, gap = 10, inWindow = false, mouseEnterDelay = 150, mouseLeaveDelay = 200, modal = false, skipFirstTransition = true, destroyAfterClose = false, lazyLoading = true, zIndex: zIndexProp, onVisibleChange, afterVisibleChange } = _a, restProps = __rest(_a, ["ref", "children", "styleOverrides", "styleProvider", "content", "header", "footer", "visible", "defaultVisible", "trigger", "placement", "placementFixed", "arrow", "escClosable", "gap", "inWindow", "mouseEnterDelay", "mouseLeaveDelay", "modal", "skipFirstTransition", "destroyAfterClose", "lazyLoading", "zIndex", "onVisibleChange", "afterVisibleChange"]);
|
|
16
17
|
const trigger = modal ? 'click' : triggerProp;
|
|
17
18
|
const namespace = useNamespace();
|
|
18
19
|
const styled = useStyled(CLASSES, { popover: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.popover }, styleOverrides);
|
|
19
|
-
const sheet = useJSS();
|
|
20
20
|
const uniqueId = useId();
|
|
21
|
-
|
|
21
|
+
const triggerId = `${namespace}-popover-trigger-${uniqueId}`;
|
|
22
22
|
const titleId = `${namespace}-popover-title-${uniqueId}`;
|
|
23
23
|
const bodyId = `${namespace}-popover-content-${uniqueId}`;
|
|
24
24
|
const triggerRef = useRefExtra(() => document.getElementById(triggerId));
|
|
25
25
|
const popoverRef = useRef(null);
|
|
26
26
|
const popupRef = useRef(null);
|
|
27
|
-
const
|
|
28
|
-
prevActiveEl: null,
|
|
29
|
-
});
|
|
27
|
+
const prevActiveEl = useRef(null);
|
|
30
28
|
const [visible, changeVisible] = useControlled(defaultVisible !== null && defaultVisible !== void 0 ? defaultVisible : false, visibleProp, onVisibleChange);
|
|
31
29
|
const maxZIndex = useMaxIndex(visible);
|
|
32
30
|
const zIndex = !isUndefined(zIndexProp) ? zIndexProp : `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
33
|
-
const transformOrigin = useRef();
|
|
34
31
|
const placement = useRef(placementProp);
|
|
35
32
|
const updatePosition = useEventCallback(() => {
|
|
36
33
|
if (visible && triggerRef.current && popoverRef.current && popupRef.current) {
|
|
@@ -41,48 +38,23 @@ function PopoverFC(props, ref) {
|
|
|
41
38
|
gap,
|
|
42
39
|
inWindow,
|
|
43
40
|
});
|
|
44
|
-
transformOrigin.current = position.transformOrigin;
|
|
45
41
|
popoverRef.current.classList.toggle(`${namespace}-popover--${placement.current}`, false);
|
|
46
42
|
placement.current = position.placement;
|
|
47
43
|
popoverRef.current.classList.toggle(`${namespace}-popover--${placement.current}`, true);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
sheet.replaceRule('position', {
|
|
52
|
-
top: position.top,
|
|
53
|
-
left: position.left,
|
|
54
|
-
});
|
|
55
|
-
popupRef.current.classList.toggle(sheet.classes.position, true);
|
|
44
|
+
popupRef.current.style.setProperty(`--popup-transform-origin`, position.transformOrigin);
|
|
45
|
+
popupRef.current.style.top = position.top + 'px';
|
|
46
|
+
popupRef.current.style.left = position.left + 'px';
|
|
56
47
|
}
|
|
57
48
|
});
|
|
58
49
|
useLockScroll(modal && visible);
|
|
59
50
|
useImperativeHandle(ref, () => ({
|
|
60
51
|
updatePosition,
|
|
61
52
|
}), [updatePosition]);
|
|
62
|
-
const headerNode = (() => {
|
|
63
|
-
if (headerProp) {
|
|
64
|
-
const node = isString(headerProp) ? _jsx(PopoverHeader, { children: headerProp }) : headerProp;
|
|
65
|
-
return cloneElement(node, {
|
|
66
|
-
_id: titleId,
|
|
67
|
-
_onClose: () => {
|
|
68
|
-
changeVisible(false);
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
})();
|
|
73
53
|
return (_jsx(Popup, { visible: visible, trigger: trigger, mouseEnterDelay: mouseEnterDelay, mouseLeaveDelay: mouseLeaveDelay, updatePosition: {
|
|
74
54
|
fn: updatePosition,
|
|
75
55
|
triggerRef,
|
|
76
56
|
popupRef,
|
|
77
|
-
}, onVisibleChange: changeVisible, children: (
|
|
78
|
-
const render = (el) => {
|
|
79
|
-
var _a;
|
|
80
|
-
triggerId = (_a = el.props.id) !== null && _a !== void 0 ? _a : `${namespace}-popover-trigger-${uniqueId}`;
|
|
81
|
-
return renderTrigger(cloneElement(el, {
|
|
82
|
-
id: triggerId,
|
|
83
|
-
onKeyDown: (e) => {
|
|
84
|
-
var _a, _b;
|
|
85
|
-
(_b = (_a = el.props).onKeyDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
57
|
+
}, onVisibleChange: changeVisible, children: (popupProps) => (_jsxs(_Fragment, { children: [children(Object.assign(Object.assign({ id: triggerId }, popupProps.trigger), { onKeyDown: (e) => {
|
|
86
58
|
if (visible) {
|
|
87
59
|
if (escClosable && e.code === 'Escape') {
|
|
88
60
|
e.stopPropagation();
|
|
@@ -90,85 +62,77 @@ function PopoverFC(props, ref) {
|
|
|
90
62
|
changeVisible(false);
|
|
91
63
|
}
|
|
92
64
|
}
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
65
|
+
} })), _jsx(Portal, { selector: () => {
|
|
66
|
+
let el = document.getElementById(`${namespace}-popover-root`);
|
|
67
|
+
if (!el) {
|
|
68
|
+
el = document.createElement('div');
|
|
69
|
+
el.id = `${namespace}-popover-root`;
|
|
70
|
+
document.body.appendChild(el);
|
|
71
|
+
}
|
|
72
|
+
return el;
|
|
73
|
+
}, children: _jsx(Transition, { enter: visible, name: `${namespace}-popup`, duration: TTANSITION_DURING, skipFirstTransition: skipFirstTransition, onSkipEnter: updatePosition, onBeforeEnter: (el) => {
|
|
74
|
+
updatePosition();
|
|
75
|
+
if (el) {
|
|
76
|
+
el.style.setProperty(`--popup-duration`, TTANSITION_DURING.enter + 'ms');
|
|
102
77
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
popoverRef.current.focus({ preventScroll: true });
|
|
110
|
-
}
|
|
78
|
+
}, onAfterEnter: () => {
|
|
79
|
+
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
|
|
80
|
+
if (modal) {
|
|
81
|
+
prevActiveEl.current = document.activeElement;
|
|
82
|
+
if (popoverRef.current) {
|
|
83
|
+
popoverRef.current.focus({ preventScroll: true });
|
|
111
84
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
switch (state) {
|
|
123
|
-
case 'enter':
|
|
124
|
-
transitionStyle = { transform: 'scale(0.3)', opacity: 0 };
|
|
125
|
-
break;
|
|
126
|
-
case 'entering':
|
|
127
|
-
transitionStyle = {
|
|
128
|
-
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING.enter}ms ease-out`).join(', '),
|
|
129
|
-
transformOrigin: transformOrigin.current,
|
|
130
|
-
};
|
|
131
|
-
break;
|
|
132
|
-
case 'leaving':
|
|
133
|
-
transitionStyle = {
|
|
134
|
-
transform: 'scale(0.3)',
|
|
135
|
-
opacity: 0,
|
|
136
|
-
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING.leave}ms ease-in`).join(', '),
|
|
137
|
-
transformOrigin: transformOrigin.current,
|
|
138
|
-
};
|
|
139
|
-
break;
|
|
140
|
-
default:
|
|
141
|
-
break;
|
|
85
|
+
}
|
|
86
|
+
}, onBeforeLeave: (el) => {
|
|
87
|
+
if (el) {
|
|
88
|
+
el.style.setProperty(`--popup-duration`, TTANSITION_DURING.leave + 'ms');
|
|
89
|
+
}
|
|
90
|
+
}, onAfterLeave: () => {
|
|
91
|
+
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
92
|
+
if (modal) {
|
|
93
|
+
if (prevActiveEl.current) {
|
|
94
|
+
prevActiveEl.current.focus({ preventScroll: true });
|
|
142
95
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
96
|
+
}
|
|
97
|
+
}, children: (transitionRef, leaved) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return (_jsx(LazyLoading, { hidden: leaved, disabled: !lazyLoading, children: leaved && destroyAfterClose ? null : (_jsx(PopoverContext, { value: {
|
|
100
|
+
id: titleId,
|
|
101
|
+
onClose: () => {
|
|
102
|
+
changeVisible(false);
|
|
103
|
+
},
|
|
104
|
+
}, children: _jsxs("div", Object.assign({}, restProps, mergeCS(styled('popover'), {
|
|
105
|
+
className: restProps.className,
|
|
106
|
+
style: Object.assign(Object.assign(Object.assign(Object.assign({}, restProps.style), { '--popup-scale': 0.3 }), { zIndex }), (leaved ? { display: 'none' } : undefined)),
|
|
107
|
+
}), { ref: (instance) => {
|
|
108
|
+
popoverRef.current = instance;
|
|
109
|
+
return () => {
|
|
110
|
+
popoverRef.current = null;
|
|
111
|
+
};
|
|
112
|
+
}, tabIndex: -1, role: ((_a = restProps.role) !== null && _a !== void 0 ? _a : modal) ? 'alertdialog' : 'dialog', "aria-modal": modal, "aria-labelledby": headerProp ? titleId : undefined, "aria-describedby": bodyId, onKeyDown: (e) => {
|
|
113
|
+
var _a;
|
|
114
|
+
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
115
|
+
if (visible) {
|
|
116
|
+
if (escClosable && e.code === 'Escape') {
|
|
117
|
+
e.stopPropagation();
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
changeVisible(false);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (modal) {
|
|
123
|
+
handleModalKeyDown(e);
|
|
154
124
|
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
})] })))] })));
|
|
169
|
-
} }) })] }));
|
|
170
|
-
} }));
|
|
171
|
-
}
|
|
172
|
-
export const Popover = forwardRef(PopoverFC);
|
|
125
|
+
}, children: [modal && (_jsx("div", Object.assign({}, styled('popover__mask'), { onClick: () => {
|
|
126
|
+
changeVisible(false);
|
|
127
|
+
} }))), _jsxs("div", Object.assign({}, styled('popover__content'), { ref: (instance) => {
|
|
128
|
+
popupRef.current = instance;
|
|
129
|
+
transitionRef(instance);
|
|
130
|
+
return () => {
|
|
131
|
+
popupRef.current = null;
|
|
132
|
+
transitionRef(null);
|
|
133
|
+
};
|
|
134
|
+
} }, popupProps.popup, { children: [arrow && _jsx("div", Object.assign({}, styled('popover__arrow'))), isString(headerProp) ? _jsx(PopoverHeader, { children: headerProp }) : headerProp, _jsx("div", Object.assign({}, styled('popover__body'), { id: bodyId, children: content })), footer] }))] })) })) }));
|
|
135
|
+
} }) })] })) }));
|
|
136
|
+
};
|
|
173
137
|
Popover.Header = PopoverHeader;
|
|
174
138
|
Popover.Footer = PopoverFooter;
|
package/popover/PopoverFooter.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { has } from 'lodash';
|
|
4
|
+
import { Fragment, use } from 'react';
|
|
5
|
+
import { CLASSES, PopoverContext } from './vars';
|
|
5
6
|
import { Button } from '../button';
|
|
6
7
|
import { useComponentProps, useControlled, useStyled, useTranslation } from '../hooks';
|
|
7
8
|
import { mergeCS } from '../utils';
|
|
8
9
|
export function PopoverFooter(props) {
|
|
9
|
-
const _a = useComponentProps('PopoverFooter', props), { styleOverrides, styleProvider, align = 'right', actions = ['cancel', 'ok'], cancelProps: cancelPropsProp, okProps: okPropsProp, onCancelClick, onOkClick
|
|
10
|
+
const _a = useComponentProps('PopoverFooter', props), { styleOverrides, styleProvider, align = 'right', actions = ['cancel', 'ok'], cancelProps: cancelPropsProp, okProps: okPropsProp, onCancelClick, onOkClick } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "align", "actions", "cancelProps", "okProps", "onCancelClick", "onOkClick"]);
|
|
10
11
|
const styled = useStyled(CLASSES, { popover: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.popover }, styleOverrides);
|
|
11
12
|
const { t } = useTranslation();
|
|
13
|
+
const popoverContext = use(PopoverContext);
|
|
12
14
|
const [cancelLoading, changeCancelLoading] = useControlled(false, cancelPropsProp === null || cancelPropsProp === void 0 ? void 0 : cancelPropsProp.loading);
|
|
13
15
|
const [okLoading, changeOkLoading] = useControlled(false, okPropsProp === null || okPropsProp === void 0 ? void 0 : okPropsProp.loading);
|
|
14
16
|
const cancelProps = Object.assign(Object.assign({}, cancelPropsProp), { loading: cancelLoading, onClick: () => {
|
|
@@ -18,12 +20,12 @@ export function PopoverFooter(props) {
|
|
|
18
20
|
shouldClose.then((val) => {
|
|
19
21
|
changeCancelLoading(false);
|
|
20
22
|
if (val !== false) {
|
|
21
|
-
|
|
23
|
+
popoverContext === null || popoverContext === void 0 ? void 0 : popoverContext.onClose();
|
|
22
24
|
}
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
else if (shouldClose !== false) {
|
|
26
|
-
|
|
28
|
+
popoverContext === null || popoverContext === void 0 ? void 0 : popoverContext.onClose();
|
|
27
29
|
}
|
|
28
30
|
} });
|
|
29
31
|
const okProps = Object.assign(Object.assign({}, okPropsProp), { loading: okLoading, onClick: () => {
|
|
@@ -33,19 +35,20 @@ export function PopoverFooter(props) {
|
|
|
33
35
|
shouldClose.then((val) => {
|
|
34
36
|
changeOkLoading(false);
|
|
35
37
|
if (val !== false) {
|
|
36
|
-
|
|
38
|
+
popoverContext === null || popoverContext === void 0 ? void 0 : popoverContext.onClose();
|
|
37
39
|
}
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
else if (shouldClose !== false) {
|
|
41
|
-
|
|
43
|
+
popoverContext === null || popoverContext === void 0 ? void 0 : popoverContext.onClose();
|
|
42
44
|
}
|
|
43
45
|
} });
|
|
44
46
|
return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('popover__footer', `popover__footer--${align}`), {
|
|
45
47
|
className: restProps.className,
|
|
46
48
|
style: restProps.style,
|
|
47
|
-
}), { children:
|
|
49
|
+
}), { children: actions.map((node, index) => {
|
|
48
50
|
var _a, _b, _c;
|
|
49
|
-
|
|
51
|
+
const { id, action } = (has(node, ['id', 'action']) ? node : { id: index, action: node });
|
|
52
|
+
return (_jsx(Fragment, { children: action === 'cancel' ? (_jsx(Button, Object.assign({}, cancelProps, { pattern: (_a = cancelProps.pattern) !== null && _a !== void 0 ? _a : 'secondary', children: (_b = cancelProps.children) !== null && _b !== void 0 ? _b : t('Footer', 'Cancel') }))) : action === 'ok' ? (_jsx(Button, Object.assign({}, okProps, { children: (_c = okProps.children) !== null && _c !== void 0 ? _c : t('Footer', 'OK') }))) : (action) }, id));
|
|
50
53
|
}) })));
|
|
51
54
|
}
|