@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/menu/internal/MenuSub.js
CHANGED
|
@@ -2,24 +2,22 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { useEventCallback } from '@laser-ui/hooks';
|
|
3
3
|
import { checkNodeExist } from '@laser-ui/utils';
|
|
4
4
|
import { isUndefined } from 'lodash';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { useImperativeHandle, useRef } from 'react';
|
|
6
|
+
import { useMaxIndex, useTranslation } from '../../hooks';
|
|
7
7
|
import { Popup } from '../../internal/popup';
|
|
8
8
|
import { Portal } from '../../internal/portal';
|
|
9
|
-
import { CollapseTransition, Transition } from '../../
|
|
9
|
+
import { CollapseTransition, Transition } from '../../transition';
|
|
10
10
|
import { getHorizontalSidePosition, getVerticalSidePosition, mergeCS } from '../../utils';
|
|
11
11
|
import { TTANSITION_DURING_BASE, TTANSITION_DURING_POPUP, WINDOW_SPACE } from '../../vars';
|
|
12
|
-
export
|
|
13
|
-
const { children, namespace, styled, id, level, space, step, icon, list, popupState, trigger, posinset, mode, inNav, active, includeActive, expand, empty, focus, disabled, onVisibleChange, onClick, } = props;
|
|
14
|
-
const sheet = useJSS();
|
|
12
|
+
export function MenuSub(props) {
|
|
13
|
+
const { ref, children, namespace, styled, id, level, space, step, icon, list, popupState, trigger, posinset, mode, inNav, active, includeActive, expand, empty, focus, disabled, onVisibleChange, onClick, } = props;
|
|
15
14
|
const triggerRef = useRef(null);
|
|
16
15
|
const popupRef = useRef(null);
|
|
17
|
-
const
|
|
16
|
+
const nodeSaved = useRef(null);
|
|
18
17
|
const { t } = useTranslation();
|
|
19
18
|
const visible = !isUndefined(popupState);
|
|
20
19
|
const inHorizontalNav = mode === 'horizontal' && inNav;
|
|
21
20
|
const iconMode = mode === 'icon' && inNav;
|
|
22
|
-
const transformOrigin = useRef();
|
|
23
21
|
const updatePosition = useEventCallback(() => {
|
|
24
22
|
if (!(disabled || mode === 'vertical') && visible && popupRef.current && triggerRef.current) {
|
|
25
23
|
const height = popupRef.current.offsetHeight;
|
|
@@ -38,16 +36,10 @@ export const MenuSub = forwardRef((props, ref) => {
|
|
|
38
36
|
gap: inNav ? 10 : 14,
|
|
39
37
|
inWindow: WINDOW_SPACE,
|
|
40
38
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
sheet.replaceRule('position', {
|
|
46
|
-
top: position.top,
|
|
47
|
-
left: position.left,
|
|
48
|
-
width: inHorizontalNav ? width : undefined,
|
|
49
|
-
});
|
|
50
|
-
popupRef.current.classList.toggle(sheet.classes.position, true);
|
|
39
|
+
popupRef.current.style.setProperty(`--popup-down-transform-origin`, position.transformOrigin);
|
|
40
|
+
popupRef.current.style.top = position.top + 'px';
|
|
41
|
+
popupRef.current.style.left = position.left + 'px';
|
|
42
|
+
popupRef.current.style.width = inHorizontalNav ? width + 'px' : '';
|
|
51
43
|
}
|
|
52
44
|
});
|
|
53
45
|
const maxZIndex = useMaxIndex(visible);
|
|
@@ -57,13 +49,19 @@ export const MenuSub = forwardRef((props, ref) => {
|
|
|
57
49
|
triggerRef,
|
|
58
50
|
popupRef,
|
|
59
51
|
scroll: false,
|
|
60
|
-
}, onVisibleChange: onVisibleChange, children: (
|
|
52
|
+
}, onVisibleChange: onVisibleChange, children: (popupProps) => (_jsxs(_Fragment, { children: [_jsxs("li", Object.assign({}, mergeCS(styled('menu__item', 'menu__item--sub', {
|
|
61
53
|
'menu__item--horizontal': inHorizontalNav,
|
|
62
54
|
'menu__item--icon': iconMode,
|
|
63
55
|
'menu__item.is-active': active,
|
|
64
56
|
'menu__item.is-expand': mode === 'vertical' ? expand && includeActive : visible,
|
|
65
57
|
'menu__item.is-disabled': disabled,
|
|
66
|
-
}), { style: { paddingLeft: space + level * step } }), { ref:
|
|
58
|
+
}), { style: { paddingLeft: space + level * step } }), { ref: (instance) => {
|
|
59
|
+
triggerRef.current = instance;
|
|
60
|
+
return () => {
|
|
61
|
+
triggerRef.current = null;
|
|
62
|
+
};
|
|
63
|
+
}, id: id, role: "menuitem", "aria-haspopup": true, "aria-expanded": mode === 'vertical' ? expand : visible, "aria-disabled": disabled }, popupProps.trigger, { onClick: (e) => {
|
|
64
|
+
popupProps.trigger.onClick(e);
|
|
67
65
|
onClick(e);
|
|
68
66
|
}, children: [focus && _jsx("div", { className: `${namespace}-focus-outline` }), _jsxs("div", Object.assign({}, styled('menu__indicator', {
|
|
69
67
|
'menu__indicator--first': posinset[0] === 0 && posinset[1] > 1,
|
|
@@ -71,7 +69,7 @@ export const MenuSub = forwardRef((props, ref) => {
|
|
|
71
69
|
}), { 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 })), !inHorizontalNav && (_jsxs("div", Object.assign({}, styled('menu__sub-arrow', {
|
|
72
70
|
'menu__sub-arrow--horizontal': mode !== 'vertical' && !inHorizontalNav,
|
|
73
71
|
'menu__sub-arrow.is-expand': mode === 'vertical' && expand,
|
|
74
|
-
}), { "aria-hidden": true, children: [_jsx("div", {}), _jsx("div", {})] })))] }))
|
|
72
|
+
}), { "aria-hidden": true, children: [_jsx("div", {}), _jsx("div", {})] })))] })), mode !== 'vertical' && (_jsx(Portal, { selector: () => {
|
|
75
73
|
let el = document.getElementById(`${namespace}-menu-root`);
|
|
76
74
|
if (!el) {
|
|
77
75
|
el = document.createElement('div');
|
|
@@ -79,60 +77,35 @@ export const MenuSub = forwardRef((props, ref) => {
|
|
|
79
77
|
document.body.appendChild(el);
|
|
80
78
|
}
|
|
81
79
|
return el;
|
|
82
|
-
}, children: _jsx(Transition, { enter: visible,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
break;
|
|
94
|
-
case 'leaving':
|
|
95
|
-
transitionStyle = {
|
|
96
|
-
transform: inHorizontalNav ? 'scaleY(0.7)' : 'scale(0)',
|
|
97
|
-
opacity: 0,
|
|
98
|
-
transition: ['transform', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_POPUP}ms ease-in`).join(', '),
|
|
99
|
-
transformOrigin: transformOrigin.current,
|
|
100
|
-
};
|
|
101
|
-
break;
|
|
102
|
-
case 'leaved':
|
|
103
|
-
transitionStyle = { display: 'none' };
|
|
104
|
-
break;
|
|
105
|
-
default:
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
return renderPopup(_jsx("div", Object.assign({}, mergeCS(styled('menu-popup'), {
|
|
109
|
-
style: Object.assign({ minWidth: inHorizontalNav ? undefined : 160, zIndex: `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})` }, transitionStyle),
|
|
110
|
-
}), { ref: popupRef, children: _jsx("ul", Object.assign({}, styled('menu__sub-list'), { role: "menu", "aria-labelledby": id, children: empty ? (_jsx("div", Object.assign({}, mergeCS(styled('menu__empty'), { style: { paddingLeft: space + level * step } }), { children: t('No data') }))) : (list) })) })));
|
|
111
|
-
} }) }))] })) }), _jsx(CollapseTransition, { originalSize: {
|
|
112
|
-
height: 'auto',
|
|
113
|
-
}, collapsedSize: {
|
|
114
|
-
height: 0,
|
|
115
|
-
}, enter: mode === 'vertical' ? expand : inNav ? false : (prev) => prev, defaultEnter: expand, during: TTANSITION_DURING_BASE, styles: {
|
|
116
|
-
entering: {
|
|
117
|
-
transition: ['height', 'padding', 'margin'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-out`).join(', '),
|
|
118
|
-
},
|
|
119
|
-
leaving: {
|
|
120
|
-
transition: ['height', 'padding', 'margin'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms ease-in`).join(', '),
|
|
121
|
-
},
|
|
122
|
-
leaved: { display: 'none' },
|
|
123
|
-
}, children: (listRef, collapseStyle, state) => {
|
|
80
|
+
}, children: _jsx(Transition, { enter: visible, name: `${namespace}-popup-down`, duration: TTANSITION_DURING_POPUP, onSkipEnter: updatePosition, onBeforeEnter: updatePosition, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, mergeCS(styled('menu-popup'), {
|
|
81
|
+
style: Object.assign(Object.assign({ zIndex: `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})` }, (inHorizontalNav ? undefined : { '--popup-down-scale': 0.01, minWidth: 160 })), (leaved ? { display: 'none' } : undefined)),
|
|
82
|
+
}), { ref: (instance) => {
|
|
83
|
+
popupRef.current = instance;
|
|
84
|
+
transitionRef(instance);
|
|
85
|
+
return () => {
|
|
86
|
+
popupRef.current = null;
|
|
87
|
+
transitionRef(null);
|
|
88
|
+
};
|
|
89
|
+
} }, popupProps.popup, { children: _jsx("ul", Object.assign({}, styled('menu__sub-list'), { role: "menu", "aria-labelledby": id, children: empty ? (_jsx("div", Object.assign({}, mergeCS(styled('menu__empty'), { style: { paddingLeft: space + level * step } }), { children: t('No data') }))) : (list) })) }))) }) }))] })) }), _jsx(CollapseTransition, { height: 0, enter: mode === 'vertical' ? expand : false, duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => {
|
|
124
90
|
if (mode !== 'vertical') {
|
|
125
|
-
if (inNav &&
|
|
126
|
-
return
|
|
127
|
-
style: Object.assign(Object.assign({}, dataRef.current.nodeCache.props.style), collapseStyle),
|
|
128
|
-
});
|
|
91
|
+
if (inNav && !leaved && nodeSaved.current) {
|
|
92
|
+
return nodeSaved.current;
|
|
129
93
|
}
|
|
130
94
|
return null;
|
|
131
95
|
}
|
|
132
|
-
const node = (_jsx("ul", Object.assign({}, mergeCS(styled('menu__sub-list'), {
|
|
96
|
+
const node = (_jsx("ul", Object.assign({}, mergeCS(styled('menu__sub-list'), {
|
|
97
|
+
style: Object.assign({}, (leaved ? { display: 'none' } : undefined)),
|
|
98
|
+
}), { ref: (instance) => {
|
|
99
|
+
if (mode === 'vertical' || inNav) {
|
|
100
|
+
transitionRef(instance);
|
|
101
|
+
return () => {
|
|
102
|
+
transitionRef(null);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}, role: "menu", "aria-labelledby": id, children: empty ? (_jsx("div", Object.assign({}, mergeCS(styled('menu__empty'), { style: { paddingLeft: space + (level + 1) * step } }), { children: t('No data') }))) : (list) })));
|
|
133
106
|
if (mode === 'vertical' && inNav) {
|
|
134
|
-
|
|
107
|
+
nodeSaved.current = node;
|
|
135
108
|
}
|
|
136
109
|
return node;
|
|
137
110
|
} })] }));
|
|
138
|
-
}
|
|
111
|
+
}
|
package/menu/types.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface MenuItem<ID extends React.Key> {
|
|
|
15
15
|
children?: MenuItem<ID>[];
|
|
16
16
|
}
|
|
17
17
|
export interface MenuProps<ID extends React.Key, T extends MenuItem<ID>> extends BaseProps<'menu' | 'menu-popup', typeof CLASSES>, Omit<React.HTMLAttributes<HTMLElement>, 'children'> {
|
|
18
|
+
ref?: React.Ref<MenuRef>;
|
|
18
19
|
list: T[];
|
|
19
20
|
mode?: MenuMode;
|
|
20
21
|
width?: string | number;
|
package/modal/Modal.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ModalAlert } from './ModalAlert';
|
|
|
4
4
|
import { ModalFooter } from './ModalFooter';
|
|
5
5
|
import { ModalHeader } from './ModalHeader';
|
|
6
6
|
export declare const Modal: {
|
|
7
|
-
(props: ModalProps):
|
|
7
|
+
(props: ModalProps): React.ReactElement | null;
|
|
8
8
|
Header: typeof ModalHeader;
|
|
9
9
|
Footer: typeof ModalFooter;
|
|
10
10
|
Alert: typeof ModalAlert;
|
package/modal/Modal.js
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { isNumber, isString, isUndefined } from 'lodash';
|
|
4
|
-
import {
|
|
4
|
+
import { useId, useRef } from 'react';
|
|
5
5
|
import { ModalAlert } from './ModalAlert';
|
|
6
6
|
import { ModalFooter } from './ModalFooter';
|
|
7
7
|
import { ModalHeader } from './ModalHeader';
|
|
8
|
-
import { CLASSES } from './vars';
|
|
8
|
+
import { CLASSES, ModalContext } from './vars';
|
|
9
9
|
import { useComponentProps, useLockScroll, useMaxIndex, useNamespace, useStyled } from '../hooks';
|
|
10
|
-
import {
|
|
10
|
+
import { LazyLoading } from '../internal/lazy-loading';
|
|
11
11
|
import { Portal } from '../internal/portal';
|
|
12
|
-
import {
|
|
12
|
+
import { Mask } from '../mask';
|
|
13
13
|
import { ROOT_DATA } from '../root/vars';
|
|
14
|
+
import { Transition } from '../transition';
|
|
14
15
|
import { handleModalKeyDown, mergeCS } from '../utils';
|
|
15
16
|
import { TTANSITION_DURING_BASE } from '../vars';
|
|
16
17
|
export const Modal = (props) => {
|
|
17
|
-
const _a = useComponentProps('Modal', props), { children, styleOverrides, styleProvider, visible, header: headerProp, footer, alert, width = 520, top: topProp = 100, mask = true, maskClosable = true, escClosable = true, skipFirstTransition = true, destroyAfterClose = true, zIndex: zIndexProp, onClose, afterVisibleChange } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "visible", "header", "footer", "alert", "width", "top", "mask", "maskClosable", "escClosable", "skipFirstTransition", "destroyAfterClose", "zIndex", "onClose", "afterVisibleChange"]);
|
|
18
|
+
const _a = useComponentProps('Modal', props), { children, styleOverrides, styleProvider, visible, header: headerProp, footer, alert, width = 520, top: topProp = 100, mask = true, maskClosable = true, escClosable = true, skipFirstTransition = true, destroyAfterClose = false, lazyLoading = true, zIndex: zIndexProp, onClose, afterVisibleChange } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "visible", "header", "footer", "alert", "width", "top", "mask", "maskClosable", "escClosable", "skipFirstTransition", "destroyAfterClose", "lazyLoading", "zIndex", "onClose", "afterVisibleChange"]);
|
|
18
19
|
const namespace = useNamespace();
|
|
19
20
|
const styled = useStyled(CLASSES, { modal: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.modal }, styleOverrides);
|
|
20
21
|
const modalRef = useRef(null);
|
|
21
22
|
const modalContentRef = useRef(null);
|
|
22
|
-
const
|
|
23
|
-
prevActiveEl: null,
|
|
24
|
-
});
|
|
23
|
+
const prevActiveEl = useRef(null);
|
|
25
24
|
const uniqueId = useId();
|
|
26
25
|
const titleId = `${namespace}-modal-title-${uniqueId}`;
|
|
27
26
|
const bodyId = `${namespace}-modal-content-${uniqueId}`;
|
|
28
27
|
const maxZIndex = useMaxIndex(visible);
|
|
29
28
|
const zIndex = !isUndefined(zIndexProp) ? zIndexProp : `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
30
29
|
useLockScroll(visible);
|
|
31
|
-
const headerNode = (() => {
|
|
32
|
-
if (headerProp) {
|
|
33
|
-
const node = isString(headerProp) ? _jsx(ModalHeader, { children: headerProp }) : headerProp;
|
|
34
|
-
return cloneElement(node, {
|
|
35
|
-
_id: titleId,
|
|
36
|
-
_onClose: () => {
|
|
37
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
})();
|
|
42
30
|
return (_jsx(Portal, { selector: () => {
|
|
43
31
|
let el = document.getElementById(`${namespace}-modal-root`);
|
|
44
32
|
if (!el) {
|
|
@@ -47,79 +35,88 @@ export const Modal = (props) => {
|
|
|
47
35
|
document.body.appendChild(el);
|
|
48
36
|
}
|
|
49
37
|
return el;
|
|
50
|
-
}, children: _jsx(Transition, { enter: visible,
|
|
51
|
-
if (
|
|
52
|
-
|
|
38
|
+
}, children: _jsx(Transition, { enter: visible, name: `${namespace}-modal`, duration: TTANSITION_DURING_BASE, skipFirstTransition: skipFirstTransition, onSkipEnter: (el) => {
|
|
39
|
+
if (el) {
|
|
40
|
+
if (isUndefined(ROOT_DATA.clickEvent) || performance.now() - ROOT_DATA.clickEvent.time > 100) {
|
|
41
|
+
el.style.setProperty(`--modal-transform-origin`, 'unset');
|
|
42
|
+
}
|
|
43
|
+
else if (modalContentRef.current) {
|
|
44
|
+
const left = `${(ROOT_DATA.windowSize.width - modalContentRef.current.offsetWidth) / 2}px`;
|
|
45
|
+
const top = topProp === 'center'
|
|
46
|
+
? `${(ROOT_DATA.windowSize.height - modalContentRef.current.offsetHeight) / 2}px`
|
|
47
|
+
: `${topProp}${isNumber(topProp) ? 'px' : ''}`;
|
|
48
|
+
el.style.setProperty(`--modal-transform-origin`, `calc(${ROOT_DATA.clickEvent.x}px - ${left}) calc(${ROOT_DATA.clickEvent.y}px - ${top})`);
|
|
49
|
+
}
|
|
53
50
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
}, onBeforeEnter: (el) => {
|
|
52
|
+
if (el) {
|
|
53
|
+
if (isUndefined(ROOT_DATA.clickEvent) || performance.now() - ROOT_DATA.clickEvent.time > 100) {
|
|
54
|
+
el.style.setProperty(`--modal-transform-origin`, 'unset');
|
|
55
|
+
}
|
|
56
|
+
else if (modalContentRef.current) {
|
|
57
|
+
const left = `${(ROOT_DATA.windowSize.width - modalContentRef.current.offsetWidth) / 2}px`;
|
|
58
|
+
const top = topProp === 'center'
|
|
59
|
+
? `${(ROOT_DATA.windowSize.height - modalContentRef.current.offsetHeight) / 2}px`
|
|
60
|
+
: `${topProp}${isNumber(topProp) ? 'px' : ''}`;
|
|
61
|
+
el.style.setProperty(`--modal-transform-origin`, `calc(${ROOT_DATA.clickEvent.x}px - ${left}) calc(${ROOT_DATA.clickEvent.y}px - ${top})`);
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
|
-
},
|
|
64
|
+
}, onAfterEnter: () => {
|
|
62
65
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
|
|
63
|
-
|
|
66
|
+
prevActiveEl.current = document.activeElement;
|
|
64
67
|
if (modalRef.current) {
|
|
65
68
|
modalRef.current.focus({ preventScroll: true });
|
|
66
69
|
}
|
|
67
|
-
},
|
|
70
|
+
}, onAfterLeave: () => {
|
|
68
71
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
69
|
-
if (
|
|
70
|
-
|
|
72
|
+
if (prevActiveEl.current) {
|
|
73
|
+
prevActiveEl.current.focus({ preventScroll: true });
|
|
71
74
|
}
|
|
72
|
-
}, children: (
|
|
75
|
+
}, children: (transitionRef, leaved) => {
|
|
73
76
|
var _a;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('modal', {
|
|
97
|
-
'modal--center': topProp === 'center',
|
|
98
|
-
'modal--alert': alert,
|
|
99
|
-
}), {
|
|
100
|
-
className: restProps.className,
|
|
101
|
-
style: Object.assign(Object.assign({}, restProps.style), { display: state === 'leaved' ? 'none' : undefined, zIndex }),
|
|
102
|
-
}), { ref: modalRef, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : -1, role: "dialog", "aria-modal": true, "aria-labelledby": headerNode ? titleId : undefined, "aria-describedby": bodyId, onKeyDown: (e) => {
|
|
103
|
-
var _a;
|
|
104
|
-
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
105
|
-
if (visible && escClosable && e.code === 'Escape') {
|
|
106
|
-
e.stopPropagation();
|
|
107
|
-
e.preventDefault();
|
|
108
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
109
|
-
}
|
|
110
|
-
handleModalKeyDown(e);
|
|
111
|
-
}, children: [mask && (_jsx(Mask, { visible: visible, onClose: () => {
|
|
112
|
-
if (maskClosable) {
|
|
77
|
+
return (_jsx(LazyLoading, { hidden: leaved, disabled: !lazyLoading, children: leaved && destroyAfterClose ? null : (_jsx(ModalContext, { value: {
|
|
78
|
+
id: titleId,
|
|
79
|
+
onClose: () => {
|
|
80
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
81
|
+
},
|
|
82
|
+
}, children: _jsxs("div", Object.assign({}, restProps, mergeCS(styled('modal', {
|
|
83
|
+
'modal--center': topProp === 'center',
|
|
84
|
+
'modal--alert': alert,
|
|
85
|
+
}), {
|
|
86
|
+
className: restProps.className,
|
|
87
|
+
style: Object.assign(Object.assign(Object.assign({}, restProps.style), { zIndex }), (leaved ? { display: 'none' } : undefined)),
|
|
88
|
+
}), { ref: (instance) => {
|
|
89
|
+
modalRef.current = instance;
|
|
90
|
+
return () => {
|
|
91
|
+
modalRef.current = null;
|
|
92
|
+
};
|
|
93
|
+
}, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : -1, role: "dialog", "aria-modal": true, "aria-labelledby": headerProp ? titleId : undefined, "aria-describedby": bodyId, onKeyDown: (e) => {
|
|
94
|
+
var _a;
|
|
95
|
+
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
96
|
+
if (visible && escClosable && e.code === 'Escape') {
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
e.preventDefault();
|
|
113
99
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
114
100
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
cloneElement(footer, {
|
|
119
|
-
_onClose: () => {
|
|
101
|
+
handleModalKeyDown(e);
|
|
102
|
+
}, children: [mask && (_jsx(Mask, { visible: visible, onClose: () => {
|
|
103
|
+
if (maskClosable) {
|
|
120
104
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
105
|
+
}
|
|
106
|
+
} })), _jsxs("div", Object.assign({}, mergeCS(styled('modal__content'), {
|
|
107
|
+
style: {
|
|
108
|
+
width,
|
|
109
|
+
top: topProp === 'center' ? undefined : topProp,
|
|
110
|
+
maxHeight: topProp === 'center' ? undefined : `calc(100% - ${topProp}${isNumber(topProp) ? 'px' : ''} - 20px)`,
|
|
111
|
+
},
|
|
112
|
+
}), { ref: (instance) => {
|
|
113
|
+
modalContentRef.current = instance;
|
|
114
|
+
transitionRef(instance);
|
|
115
|
+
return () => {
|
|
116
|
+
modalContentRef.current = null;
|
|
117
|
+
transitionRef(null);
|
|
118
|
+
};
|
|
119
|
+
}, children: [isString(headerProp) ? _jsx(ModalHeader, { children: headerProp }) : headerProp, _jsx("div", Object.assign({}, styled('modal__body'), { id: bodyId, children: alert !== null && alert !== void 0 ? alert : children })), footer] }))] })) })) }));
|
|
123
120
|
} }) }));
|
|
124
121
|
};
|
|
125
122
|
Modal.Header = ModalHeader;
|
package/modal/ModalAlert.d.ts
CHANGED
package/modal/ModalFooter.d.ts
CHANGED
package/modal/ModalFooter.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, ModalContext } 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 ModalFooter(props) {
|
|
9
|
-
const _a = useComponentProps('ModalFooter', props), { styleOverrides, styleProvider, align = 'right', actions = ['cancel', 'ok'], cancelProps: cancelPropsProp, okProps: okPropsProp, onCancelClick, onOkClick
|
|
10
|
+
const _a = useComponentProps('ModalFooter', 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, { modal: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.modal }, styleOverrides);
|
|
11
12
|
const { t } = useTranslation();
|
|
13
|
+
const modalContext = use(ModalContext);
|
|
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 ModalFooter(props) {
|
|
|
18
20
|
shouldClose.then((val) => {
|
|
19
21
|
changeCancelLoading(false);
|
|
20
22
|
if (val !== false) {
|
|
21
|
-
|
|
23
|
+
modalContext === null || modalContext === void 0 ? void 0 : modalContext.onClose();
|
|
22
24
|
}
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
else if (shouldClose !== false) {
|
|
26
|
-
|
|
28
|
+
modalContext === null || modalContext === void 0 ? void 0 : modalContext.onClose();
|
|
27
29
|
}
|
|
28
30
|
} });
|
|
29
31
|
const okProps = Object.assign(Object.assign({}, okPropsProp), { loading: okLoading, onClick: () => {
|
|
@@ -33,19 +35,20 @@ export function ModalFooter(props) {
|
|
|
33
35
|
shouldClose.then((val) => {
|
|
34
36
|
changeOkLoading(false);
|
|
35
37
|
if (val !== false) {
|
|
36
|
-
|
|
38
|
+
modalContext === null || modalContext === void 0 ? void 0 : modalContext.onClose();
|
|
37
39
|
}
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
else if (shouldClose !== false) {
|
|
41
|
-
|
|
43
|
+
modalContext === null || modalContext === void 0 ? void 0 : modalContext.onClose();
|
|
42
44
|
}
|
|
43
45
|
} });
|
|
44
46
|
return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('modal__footer', `modal__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
|
}
|
package/modal/ModalHeader.d.ts
CHANGED
package/modal/ModalHeader.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import CloseOutlined from '@material-design-icons/svg/outlined/close.svg?react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { has } from 'lodash';
|
|
5
|
+
import { Fragment, use } from 'react';
|
|
6
|
+
import { CLASSES, ModalContext } from './vars';
|
|
6
7
|
import { Button } from '../button';
|
|
7
8
|
import { useComponentProps, useControlled, useStyled, useTranslation } from '../hooks';
|
|
8
9
|
import { Icon } from '../icon';
|
|
9
10
|
import { mergeCS } from '../utils';
|
|
10
11
|
export function ModalHeader(props) {
|
|
11
|
-
const _a = useComponentProps('ModalHeader', props), { styleOverrides, styleProvider, children, actions = ['close'], closeProps: closePropsProp, onCloseClick
|
|
12
|
+
const _a = useComponentProps('ModalHeader', props), { styleOverrides, styleProvider, children, actions = ['close'], closeProps: closePropsProp, onCloseClick } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "children", "actions", "closeProps", "onCloseClick"]);
|
|
12
13
|
const styled = useStyled(CLASSES, { modal: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.modal }, styleOverrides);
|
|
13
14
|
const { t } = useTranslation();
|
|
15
|
+
const modalContext = use(ModalContext);
|
|
14
16
|
const [closeLoading, changeCloseLoading] = useControlled(false, closePropsProp === null || closePropsProp === void 0 ? void 0 : closePropsProp.loading);
|
|
15
17
|
const closeProps = Object.assign(Object.assign({}, closePropsProp), { loading: closeLoading, onClick: () => {
|
|
16
18
|
const shouldClose = onCloseClick === null || onCloseClick === void 0 ? void 0 : onCloseClick();
|
|
@@ -19,19 +21,20 @@ export function ModalHeader(props) {
|
|
|
19
21
|
shouldClose.then((val) => {
|
|
20
22
|
changeCloseLoading(false);
|
|
21
23
|
if (val !== false) {
|
|
22
|
-
|
|
24
|
+
modalContext === null || modalContext === void 0 ? void 0 : modalContext.onClose();
|
|
23
25
|
}
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
else if (shouldClose !== false) {
|
|
27
|
-
|
|
29
|
+
modalContext === null || modalContext === void 0 ? void 0 : modalContext.onClose();
|
|
28
30
|
}
|
|
29
31
|
} });
|
|
30
32
|
return (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('modal__header'), {
|
|
31
33
|
className: restProps.className,
|
|
32
34
|
style: restProps.style,
|
|
33
|
-
}), { children: [_jsx("div", Object.assign({}, styled('modal__header-title'), { id:
|
|
35
|
+
}), { children: [_jsx("div", Object.assign({}, styled('modal__header-title'), { id: modalContext === null || modalContext === void 0 ? void 0 : modalContext.id, children: children })), _jsx("div", Object.assign({}, styled('modal__header-actions'), { children: actions.map((node, index) => {
|
|
34
36
|
var _a, _b, _c;
|
|
35
|
-
|
|
37
|
+
const { id, action } = (has(node, ['id', 'action']) ? node : { id: index, action: node });
|
|
38
|
+
return (_jsx(Fragment, { children: action === 'close' ? (_jsx(Button, Object.assign({}, closeProps, { "aria-label": (_a = closeProps['aria-label']) !== null && _a !== void 0 ? _a : t('Close'), pattern: (_b = closeProps.pattern) !== null && _b !== void 0 ? _b : 'text', icon: (_c = closeProps.icon) !== null && _c !== void 0 ? _c : (_jsx(Icon, { children: _jsx(CloseOutlined, {}) })) }))) : (action) }, id));
|
|
36
39
|
}) }))] })));
|
|
37
40
|
}
|
package/modal/types.d.ts
CHANGED
|
@@ -15,18 +15,25 @@ export interface ModalProps extends BaseProps<'modal', typeof CLASSES>, React.HT
|
|
|
15
15
|
escClosable?: boolean;
|
|
16
16
|
skipFirstTransition?: boolean;
|
|
17
17
|
destroyAfterClose?: boolean;
|
|
18
|
+
lazyLoading?: boolean;
|
|
18
19
|
zIndex?: number | string;
|
|
19
20
|
onClose?: () => void;
|
|
20
21
|
afterVisibleChange?: (visible: boolean) => void;
|
|
21
22
|
}
|
|
22
23
|
export interface ModalHeaderProps extends BaseProps<'modal', typeof CLASSES>, React.HTMLAttributes<HTMLDivElement> {
|
|
23
|
-
actions?: React.ReactNode
|
|
24
|
+
actions?: (React.ReactNode | {
|
|
25
|
+
id: React.Key;
|
|
26
|
+
action: React.ReactNode;
|
|
27
|
+
})[];
|
|
24
28
|
closeProps?: ButtonProps;
|
|
25
29
|
onCloseClick?: () => any | Promise<any>;
|
|
26
30
|
}
|
|
27
31
|
export interface ModalFooterProps extends BaseProps<'modal', typeof CLASSES>, Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
28
32
|
align?: 'left' | 'center' | 'right';
|
|
29
|
-
actions?: React.ReactNode
|
|
33
|
+
actions?: (React.ReactNode | {
|
|
34
|
+
id: React.Key;
|
|
35
|
+
action: React.ReactNode;
|
|
36
|
+
})[];
|
|
30
37
|
cancelProps?: ButtonProps;
|
|
31
38
|
okProps?: ButtonProps;
|
|
32
39
|
onCancelClick?: () => any | Promise<any>;
|
package/modal/vars.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export declare const CLASSES: {
|
|
2
3
|
modal: string;
|
|
3
4
|
'modal--center': string;
|
|
@@ -21,3 +22,7 @@ export declare const CLASSES: {
|
|
|
21
22
|
'modal__alert-title': string;
|
|
22
23
|
'modal__alert-message': string;
|
|
23
24
|
};
|
|
25
|
+
export declare const ModalContext: import("react").Context<{
|
|
26
|
+
id: string;
|
|
27
|
+
onClose: () => void;
|
|
28
|
+
} | undefined>;
|
package/modal/vars.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
1
2
|
export const CLASSES = {
|
|
2
3
|
modal: '^modal',
|
|
3
4
|
'modal--center': '^modal--center',
|
|
@@ -21,3 +22,4 @@ export const CLASSES = {
|
|
|
21
22
|
'modal__alert-title': '^modal__alert-title',
|
|
22
23
|
'modal__alert-message': '^modal__alert-message',
|
|
23
24
|
};
|
|
25
|
+
export const ModalContext = createContext(undefined);
|