@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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { useAsync, useForceUpdate, useIsomorphicLayoutEffect, useUnmount } from '@laser-ui/hooks';
|
|
2
|
+
import { isNumber, isUndefined } from 'lodash';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import { flushSync } from 'react-dom';
|
|
5
|
+
const CLASSES = ['enter-from', 'enter-active', 'enter-to', 'leave-from', 'leave-active', 'leave-to'];
|
|
6
|
+
export function Transition(props) {
|
|
7
|
+
const { children, enter, name, duration, skipFirstTransition = true, onSkipEnter, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onSkipLeave, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, } = props;
|
|
8
|
+
const forceUpdate = useForceUpdate();
|
|
9
|
+
const async = useAsync();
|
|
10
|
+
const el = useRef(null);
|
|
11
|
+
const entering = useRef(false);
|
|
12
|
+
const leaving = useRef(false);
|
|
13
|
+
const skipTransition = useRef(skipFirstTransition);
|
|
14
|
+
const prevEnter = useRef(enter);
|
|
15
|
+
const leaved = useRef(skipFirstTransition ? !enter : false);
|
|
16
|
+
if (enter) {
|
|
17
|
+
leaved.current = false;
|
|
18
|
+
}
|
|
19
|
+
const resetClasses = useRef(() => { });
|
|
20
|
+
const clearTransitionEnd = useRef(() => { });
|
|
21
|
+
useIsomorphicLayoutEffect(() => {
|
|
22
|
+
if (enter !== prevEnter.current) {
|
|
23
|
+
skipTransition.current = false;
|
|
24
|
+
}
|
|
25
|
+
prevEnter.current = enter;
|
|
26
|
+
if (!skipTransition.current) {
|
|
27
|
+
if (entering.current) {
|
|
28
|
+
entering.current = false;
|
|
29
|
+
onEnterCancelled === null || onEnterCancelled === void 0 ? void 0 : onEnterCancelled(el.current);
|
|
30
|
+
}
|
|
31
|
+
if (leaving.current) {
|
|
32
|
+
leaving.current = false;
|
|
33
|
+
onLeaveCancelled === null || onLeaveCancelled === void 0 ? void 0 : onLeaveCancelled(el.current);
|
|
34
|
+
}
|
|
35
|
+
resetClasses.current();
|
|
36
|
+
resetClasses.current = () => {
|
|
37
|
+
if (el.current && name) {
|
|
38
|
+
for (const className of CLASSES) {
|
|
39
|
+
el.current.classList.toggle(`${name}-${className}`, false);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const addClasses = (classes) => {
|
|
44
|
+
if (el.current && name) {
|
|
45
|
+
for (const className of classes) {
|
|
46
|
+
el.current.classList.toggle(`${name}-${className}`, true);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const removeClasses = (classes) => {
|
|
51
|
+
if (el.current && name) {
|
|
52
|
+
for (const className of classes) {
|
|
53
|
+
el.current.classList.toggle(`${name}-${className}`, false);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
if (enter) {
|
|
58
|
+
entering.current = true;
|
|
59
|
+
onBeforeEnter === null || onBeforeEnter === void 0 ? void 0 : onBeforeEnter(el.current);
|
|
60
|
+
addClasses(['enter-from', 'enter-active']);
|
|
61
|
+
async.setAfterPainted(() => {
|
|
62
|
+
removeClasses(['enter-from', 'enter-active']);
|
|
63
|
+
onEnter === null || onEnter === void 0 ? void 0 : onEnter(el.current);
|
|
64
|
+
addClasses(['enter-active', 'enter-to']);
|
|
65
|
+
const handleAfterEnter = () => {
|
|
66
|
+
entering.current = false;
|
|
67
|
+
clearTransitionEnd.current();
|
|
68
|
+
removeClasses(['enter-active', 'enter-to']);
|
|
69
|
+
onAfterEnter === null || onAfterEnter === void 0 ? void 0 : onAfterEnter(el.current);
|
|
70
|
+
};
|
|
71
|
+
if (isUndefined(duration)) {
|
|
72
|
+
if (el.current) {
|
|
73
|
+
el.current.addEventListener('transitionend', handleAfterEnter);
|
|
74
|
+
clearTransitionEnd.current = () => {
|
|
75
|
+
if (el.current) {
|
|
76
|
+
el.current.removeEventListener('transitionend', handleAfterEnter);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const tid = setTimeout(handleAfterEnter, isNumber(duration) ? duration : duration.enter);
|
|
83
|
+
clearTransitionEnd.current = () => {
|
|
84
|
+
clearTimeout(tid);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
leaving.current = true;
|
|
91
|
+
onBeforeLeave === null || onBeforeLeave === void 0 ? void 0 : onBeforeLeave(el.current);
|
|
92
|
+
addClasses(['leave-from', 'leave-active']);
|
|
93
|
+
async.setAfterPainted(() => {
|
|
94
|
+
removeClasses(['leave-from', 'leave-active']);
|
|
95
|
+
onLeave === null || onLeave === void 0 ? void 0 : onLeave(el.current);
|
|
96
|
+
addClasses(['leave-active', 'leave-to']);
|
|
97
|
+
const handleAfterLeave = () => {
|
|
98
|
+
leaving.current = false;
|
|
99
|
+
clearTransitionEnd.current();
|
|
100
|
+
removeClasses(['leave-active', 'leave-to']);
|
|
101
|
+
onAfterLeave === null || onAfterLeave === void 0 ? void 0 : onAfterLeave(el.current);
|
|
102
|
+
leaved.current = true;
|
|
103
|
+
flushSync(() => {
|
|
104
|
+
forceUpdate();
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
if (isUndefined(duration)) {
|
|
108
|
+
if (el.current) {
|
|
109
|
+
el.current.addEventListener('transitionend', handleAfterLeave);
|
|
110
|
+
clearTransitionEnd.current = () => {
|
|
111
|
+
if (el.current) {
|
|
112
|
+
el.current.removeEventListener('transitionend', handleAfterLeave);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const tid = setTimeout(handleAfterLeave, isNumber(duration) ? duration : duration.leave);
|
|
119
|
+
clearTransitionEnd.current = () => {
|
|
120
|
+
clearTimeout(tid);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
if (enter) {
|
|
128
|
+
onSkipEnter === null || onSkipEnter === void 0 ? void 0 : onSkipEnter(el.current);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
onSkipLeave === null || onSkipLeave === void 0 ? void 0 : onSkipLeave(el.current);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return () => {
|
|
135
|
+
async.clearAll();
|
|
136
|
+
clearTransitionEnd.current();
|
|
137
|
+
};
|
|
138
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
139
|
+
}, [enter]);
|
|
140
|
+
useUnmount(() => {
|
|
141
|
+
async.clearAll();
|
|
142
|
+
clearTransitionEnd.current();
|
|
143
|
+
resetClasses.current();
|
|
144
|
+
});
|
|
145
|
+
return children((instance) => {
|
|
146
|
+
el.current = instance;
|
|
147
|
+
}, leaved.current);
|
|
148
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export {};
|
|
3
|
+
export interface TransitionProps {
|
|
4
|
+
children: (ref: React.RefCallback<HTMLElement | null>, leaved: boolean) => React.ReactElement | null;
|
|
5
|
+
enter: boolean;
|
|
6
|
+
name?: string;
|
|
7
|
+
duration?: number | {
|
|
8
|
+
enter: number;
|
|
9
|
+
leave: number;
|
|
10
|
+
};
|
|
11
|
+
skipFirstTransition?: boolean | {
|
|
12
|
+
enter: boolean;
|
|
13
|
+
leave: boolean;
|
|
14
|
+
};
|
|
15
|
+
onSkipEnter?: (el: HTMLElement | null) => void;
|
|
16
|
+
onBeforeEnter?: (el: HTMLElement | null) => void;
|
|
17
|
+
onEnter?: (el: HTMLElement | null) => void;
|
|
18
|
+
onAfterEnter?: (el: HTMLElement | null) => void;
|
|
19
|
+
onEnterCancelled?: (el: HTMLElement | null) => void;
|
|
20
|
+
onSkipLeave?: (el: HTMLElement | null) => void;
|
|
21
|
+
onBeforeLeave?: (el: HTMLElement | null) => void;
|
|
22
|
+
onLeave?: (el: HTMLElement | null) => void;
|
|
23
|
+
onAfterLeave?: (el: HTMLElement | null) => void;
|
|
24
|
+
onLeaveCancelled?: (el: HTMLElement | null) => void;
|
|
25
|
+
}
|
|
26
|
+
export interface CollapseTransitionProps extends TransitionProps {
|
|
27
|
+
width?: number;
|
|
28
|
+
height?: number;
|
|
29
|
+
}
|
package/tree/Tree.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { TreeItem, TreeProps } from './types';
|
|
3
|
-
export declare function Tree<V extends React.Key, T extends TreeItem<V>>(props: TreeProps<V, T>):
|
|
3
|
+
export declare function Tree<V extends React.Key, T extends TreeItem<V>>(props: TreeProps<V, T>): React.ReactElement | null;
|
package/tree/Tree.js
CHANGED
|
@@ -14,9 +14,7 @@ export function Tree(props) {
|
|
|
14
14
|
const namespace = useNamespace();
|
|
15
15
|
const styled = useStyled(CLASSES, { tree: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.tree }, styleOverrides);
|
|
16
16
|
const focusRef = useRef(null);
|
|
17
|
-
const
|
|
18
|
-
expands: new Set(),
|
|
19
|
-
});
|
|
17
|
+
const expandSaved = useRef(new Set());
|
|
20
18
|
const uniqueId = useId();
|
|
21
19
|
const getItemId = (val) => `${namespace}-tree-item-${val}-${uniqueId}`;
|
|
22
20
|
const [nodes, nodesMap] = useMemo(() => {
|
|
@@ -61,7 +59,7 @@ export function Tree(props) {
|
|
|
61
59
|
const expands = useMemo(() => new Set(_expands), [_expands]);
|
|
62
60
|
const { disabled } = useScopedProps({ disabled: disabledProp || (formControl === null || formControl === void 0 ? void 0 : formControl.control.disabled) });
|
|
63
61
|
const hasSelected = multiple ? selected.size > 0 : !isNull(selected);
|
|
64
|
-
const [focusVisible,
|
|
62
|
+
const [focusVisible, focusVisibleProps] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
|
|
65
63
|
const [_focused, setFocused] = useState();
|
|
66
64
|
const focused = (() => {
|
|
67
65
|
let node;
|
|
@@ -88,8 +86,8 @@ export function Tree(props) {
|
|
|
88
86
|
});
|
|
89
87
|
}
|
|
90
88
|
else {
|
|
91
|
-
if (!
|
|
92
|
-
|
|
89
|
+
if (!expandSaved.current.has(node.id)) {
|
|
90
|
+
expandSaved.current.add(node.id);
|
|
93
91
|
onFirstExpand === null || onFirstExpand === void 0 ? void 0 : onFirstExpand(node.id, node.origin);
|
|
94
92
|
}
|
|
95
93
|
changeExpands((draft) => {
|
|
@@ -109,9 +107,23 @@ export function Tree(props) {
|
|
|
109
107
|
}
|
|
110
108
|
}
|
|
111
109
|
};
|
|
112
|
-
return
|
|
110
|
+
return (_jsx(TreePanel, Object.assign({}, restProps, { ref: (instance) => {
|
|
111
|
+
focusRef.current = instance;
|
|
112
|
+
return () => {
|
|
113
|
+
focusRef.current = null;
|
|
114
|
+
};
|
|
115
|
+
}, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : (disabled ? -1 : 0), onFocus: (e) => {
|
|
116
|
+
var _a;
|
|
117
|
+
(_a = restProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
118
|
+
focusVisibleProps.onFocus(e);
|
|
119
|
+
}, onBlur: (e) => {
|
|
120
|
+
var _a;
|
|
121
|
+
(_a = restProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
122
|
+
focusVisibleProps.onBlur(e);
|
|
123
|
+
}, onKeyDown: (e) => {
|
|
113
124
|
var _a;
|
|
114
125
|
(_a = restProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
126
|
+
focusVisibleProps.onKeyDown(e);
|
|
115
127
|
const focusItem = (code) => {
|
|
116
128
|
if (focusRef.current) {
|
|
117
129
|
const item = focusRef.current(code);
|
|
@@ -4,6 +4,7 @@ import type { AbstractTreeNode } from '../node/abstract-node';
|
|
|
4
4
|
import type { TreeItem } from '../types';
|
|
5
5
|
import type { CLASSES } from '../vars';
|
|
6
6
|
interface TreePanelProps<V extends React.Key, T extends TreeItem<V>> extends Omit<React.HTMLAttributes<HTMLUListElement>, 'children'> {
|
|
7
|
+
ref?: React.Ref<(code: any) => AbstractTreeNode<V, T> | undefined>;
|
|
7
8
|
namespace: string;
|
|
8
9
|
styled: Styled<typeof CLASSES>;
|
|
9
10
|
list: AbstractTreeNode<V, T>[];
|
|
@@ -27,6 +28,5 @@ interface TreePanelProps<V extends React.Key, T extends TreeItem<V>> extends Omi
|
|
|
27
28
|
onNodeClick: (node: AbstractTreeNode<V, T>) => void;
|
|
28
29
|
onScrollBottom: (() => void) | undefined;
|
|
29
30
|
}
|
|
30
|
-
declare function
|
|
31
|
-
export declare const TreePanel: <V extends React.Key, T extends TreeItem<V>>(props: TreePanelProps<V, T> & React.RefAttributes<any>) => ReturnType<typeof TreePanelFC>;
|
|
31
|
+
export declare function TreePanel<V extends React.Key, T extends TreeItem<V>>(props: TreePanelProps<V, T>): React.ReactElement | null;
|
|
32
32
|
export {};
|
|
@@ -7,19 +7,19 @@ import AddBoxOutlined from '@material-design-icons/svg/outlined/add_box.svg?reac
|
|
|
7
7
|
import ArrowRightOutlined from '@material-design-icons/svg/outlined/arrow_right.svg?react';
|
|
8
8
|
import IndeterminateCheckBoxOutlined from '@material-design-icons/svg/outlined/indeterminate_check_box.svg?react';
|
|
9
9
|
import { isUndefined } from 'lodash';
|
|
10
|
-
import {
|
|
10
|
+
import { useImperativeHandle, useMemo, useRef } from 'react';
|
|
11
11
|
import { Checkbox } from '../../checkbox';
|
|
12
|
+
import { CircularProgress } from '../../circular-progress';
|
|
12
13
|
import { Empty } from '../../empty';
|
|
13
14
|
import { useTranslation } from '../../hooks';
|
|
14
15
|
import { Icon } from '../../icon';
|
|
15
|
-
import {
|
|
16
|
-
import { CollapseTransition } from '../../internal/transition';
|
|
16
|
+
import { CollapseTransition } from '../../transition';
|
|
17
17
|
import { mergeCS } from '../../utils';
|
|
18
18
|
import { TTANSITION_DURING_BASE } from '../../vars';
|
|
19
19
|
import { VirtualScroll } from '../../virtual-scroll';
|
|
20
|
-
function
|
|
20
|
+
export function TreePanel(props) {
|
|
21
21
|
var _a, _b;
|
|
22
|
-
const { namespace, styled, list, itemId, itemSelected, itemFocused, expands, customItem, showLine, multiple, onlyLeafSelectable, disabled, virtual, focusVisible, onNodeFocus, onNodeExpand, onNodeClick, onScrollBottom } = props, restProps = __rest(props, ["namespace", "styled", "list", "itemId", "itemSelected", "itemFocused", "expands", "customItem", "showLine", "multiple", "onlyLeafSelectable", "disabled", "virtual", "focusVisible", "onNodeFocus", "onNodeExpand", "onNodeClick", "onScrollBottom"]);
|
|
22
|
+
const { ref, namespace, styled, list, itemId, itemSelected, itemFocused, expands, customItem, showLine, multiple, onlyLeafSelectable, disabled, virtual, focusVisible, onNodeFocus, onNodeExpand, onNodeClick, onScrollBottom } = props, restProps = __rest(props, ["ref", "namespace", "styled", "list", "itemId", "itemSelected", "itemFocused", "expands", "customItem", "showLine", "multiple", "onlyLeafSelectable", "disabled", "virtual", "focusVisible", "onNodeFocus", "onNodeExpand", "onNodeClick", "onScrollBottom"]);
|
|
23
23
|
const { t } = useTranslation();
|
|
24
24
|
const listRef = useRef(null);
|
|
25
25
|
const vsRef = useRef(null);
|
|
@@ -83,7 +83,12 @@ function TreePanelFC(props, ref) {
|
|
|
83
83
|
itemExpand: (item) => (item.children ? expands.has(item.id) : undefined),
|
|
84
84
|
});
|
|
85
85
|
}, [expands, list, virtual]);
|
|
86
|
-
return (_jsx(VirtualScroll, Object.assign({}, vsProps, { ref:
|
|
86
|
+
return (_jsx(VirtualScroll, Object.assign({}, vsProps, { ref: (instance) => {
|
|
87
|
+
vsRef.current = instance;
|
|
88
|
+
return () => {
|
|
89
|
+
vsRef.current = null;
|
|
90
|
+
};
|
|
91
|
+
}, enable: !isUndefined(virtual), listSize: (_a = virtual === null || virtual === void 0 ? void 0 : virtual.listSize) !== null && _a !== void 0 ? _a : 0, listPadding: (_b = virtual === null || virtual === void 0 ? void 0 : virtual.listPadding) !== null && _b !== void 0 ? _b : 0, itemRender: (item, index, props, ancestry, children) => {
|
|
87
92
|
if (item.children) {
|
|
88
93
|
const isExpand = expands.has(item.id);
|
|
89
94
|
let isSelectedAncestry = false;
|
|
@@ -119,26 +124,21 @@ function TreePanelFC(props, ref) {
|
|
|
119
124
|
onNodeExpand(item);
|
|
120
125
|
}, children: _jsx(Icon, { children: item.origin.loading ? (_jsx(CircularProgress, {})) : showLine ? (isExpand ? (_jsx(IndeterminateCheckBoxOutlined, {})) : (_jsx(AddBoxOutlined, {}))) : (_jsx(ArrowRightOutlined, Object.assign({}, styled('tree__option-arrow', {
|
|
121
126
|
'tree__option-arrow.is-expand': isExpand,
|
|
122
|
-
})))) }) })), multiple && (_jsx("div", Object.assign({}, styled('tree__option-checkbox'), { children: _jsx(Checkbox, { model: item.checked, disabled: item.disabled, indeterminate: item.indeterminate,
|
|
127
|
+
})))) }) })), multiple && (_jsx("div", Object.assign({}, styled('tree__option-checkbox'), { children: _jsx(Checkbox, { model: item.checked, disabled: item.disabled, indeterminate: item.indeterminate, inputProps: { tabIndex: -1 }, onClick: (e) => {
|
|
123
128
|
e.stopPropagation();
|
|
124
129
|
onNodeFocus(item);
|
|
125
130
|
onNodeClick(item);
|
|
126
131
|
} }) }))), _jsx("div", Object.assign({}, styled('tree__option-content'), { children: customItem ? customItem(item.origin) : item.origin.label }))] })),
|
|
127
|
-
!item.origin.loading && (_jsx(CollapseTransition, {
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
leaved: { display: 'none' },
|
|
139
|
-
}, children: (listRef, collapseStyle) => (_jsx("ul", Object.assign({}, mergeCS(styled('tree__group'), {
|
|
140
|
-
style: collapseStyle,
|
|
141
|
-
}), { ref: listRef, role: "group", "aria-labelledby": itemId(item.id), children: children }))) }))));
|
|
132
|
+
!item.origin.loading && (_jsx(CollapseTransition, { height: 0, enter: isExpand, duration: TTANSITION_DURING_BASE, children: (transitionRef, leaved) => (_jsx("ul", Object.assign({}, mergeCS(styled('tree__group'), {
|
|
133
|
+
style: Object.assign({}, (leaved ? { display: 'none' } : undefined)),
|
|
134
|
+
}), { ref: (instance) => {
|
|
135
|
+
listRef.current = instance;
|
|
136
|
+
transitionRef(instance);
|
|
137
|
+
return () => {
|
|
138
|
+
listRef.current = null;
|
|
139
|
+
transitionRef(null);
|
|
140
|
+
};
|
|
141
|
+
}, role: "group", "aria-labelledby": itemId(item.id), children: children }))) }))));
|
|
142
142
|
}
|
|
143
143
|
return (_createElement("li", Object.assign({}, styled('tree__option', {
|
|
144
144
|
'tree__option.is-selected': !multiple && item.checked,
|
|
@@ -150,18 +150,24 @@ function TreePanelFC(props, ref) {
|
|
|
150
150
|
onNodeClick(item);
|
|
151
151
|
} }),
|
|
152
152
|
focusVisible && (itemFocused === null || itemFocused === void 0 ? void 0 : itemFocused.id) === item.id && _jsx("div", { className: `${namespace}-focus-outline` }),
|
|
153
|
-
multiple && (_jsx("div", Object.assign({}, styled('tree__option-checkbox'), { children: _jsx(Checkbox, { model: item.checked, disabled: item.disabled, indeterminate: item.indeterminate,
|
|
153
|
+
multiple && (_jsx("div", Object.assign({}, styled('tree__option-checkbox'), { children: _jsx(Checkbox, { model: item.checked, disabled: item.disabled, indeterminate: item.indeterminate, inputProps: { tabIndex: -1 }, onClick: (e) => {
|
|
154
154
|
e.stopPropagation();
|
|
155
155
|
onNodeFocus(item);
|
|
156
156
|
onNodeClick(item);
|
|
157
157
|
} }) }))),
|
|
158
158
|
_jsx("div", Object.assign({}, styled('tree__option-content'), { children: customItem ? customItem(item.origin) : item.origin.label }))));
|
|
159
|
-
}, itemFocused: itemFocused === null || itemFocused === void 0 ? void 0 : itemFocused.id, itemEmptyRender: () => (_jsx("li", Object.assign({}, styled('tree__empty'), { children: _jsx("div", Object.assign({}, styled('tree__option-content'), { children: t('No data') })) }))), itemInAriaSetsize: (item) => !item.children, placeholder: "li", onScrollEnd: onScrollBottom, children: (vsList, onScroll) => (
|
|
159
|
+
}, itemFocused: itemFocused === null || itemFocused === void 0 ? void 0 : itemFocused.id, itemEmptyRender: () => (_jsx("li", Object.assign({}, styled('tree__empty'), { children: _jsx("div", Object.assign({}, styled('tree__option-content'), { children: t('No data') })) }))), itemInAriaSetsize: (item) => !item.children, placeholder: "li", onScrollEnd: onScrollBottom, children: (vsList, onScroll) => (
|
|
160
|
+
// eslint-disable-next-line jsx-a11y/aria-activedescendant-has-tabindex
|
|
161
|
+
_jsx("ul", Object.assign({}, restProps, mergeCS(styled('tree', {
|
|
160
162
|
'tree.is-disabled': disabled,
|
|
161
163
|
'tree--line': showLine,
|
|
162
164
|
}), {
|
|
163
165
|
className: restProps.className,
|
|
164
166
|
style: restProps.style,
|
|
165
|
-
}), { ref:
|
|
167
|
+
}), { ref: (instance) => {
|
|
168
|
+
listRef.current = instance;
|
|
169
|
+
return () => {
|
|
170
|
+
listRef.current = null;
|
|
171
|
+
};
|
|
172
|
+
}, role: "tree", "aria-multiselectable": multiple, "aria-activedescendant": isUndefined(itemFocused) ? undefined : itemId(itemFocused.id), onScroll: onScroll, children: list.length === 0 ? _jsx(Empty, { style: { padding: '12px 28px' }, image: Empty.SIMPLE_IMG }) : vsList }))) })));
|
|
166
173
|
}
|
|
167
|
-
export const TreePanel = forwardRef(TreePanelFC);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { TreeSelectProps
|
|
2
|
+
import type { TreeSelectProps } from './types';
|
|
3
3
|
import type { TreeItem } from '../tree/types';
|
|
4
|
-
declare function
|
|
5
|
-
export declare const TreeSelect: <ID extends React.Key, T extends TreeItem<ID>>(props: TreeSelectProps<ID, T> & React.RefAttributes<TreeSelectRef>) => ReturnType<typeof TreeSelectFC>;
|
|
6
|
-
export {};
|
|
4
|
+
export declare function TreeSelect<V extends React.Key, T extends TreeItem<V>>(props: TreeSelectProps<V, T>): React.ReactElement | null;
|