@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/cascader/Cascader.js
CHANGED
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useEventCallback,
|
|
4
|
-
import { findNested } from '@laser-ui/utils';
|
|
3
|
+
import { useEventCallback, useResize } from '@laser-ui/hooks';
|
|
4
|
+
import { findNested, setRef } from '@laser-ui/utils';
|
|
5
5
|
import CancelFilled from '@material-design-icons/svg/filled/cancel.svg?react';
|
|
6
6
|
import CloseOutlined from '@material-design-icons/svg/outlined/close.svg?react';
|
|
7
7
|
import KeyboardArrowDownOutlined from '@material-design-icons/svg/outlined/keyboard_arrow_down.svg?react';
|
|
8
8
|
import SearchOutlined from '@material-design-icons/svg/outlined/search.svg?react';
|
|
9
9
|
import { isNull, isUndefined } from 'lodash';
|
|
10
|
-
import {
|
|
10
|
+
import { useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
11
11
|
import { CascaderPanel } from './internal/CascaderPanel';
|
|
12
12
|
import { CascaderSearchPanel } from './internal/CascaderSearchPanel';
|
|
13
13
|
import { CLASSES } from './vars';
|
|
14
14
|
import { BaseInput } from '../base-input';
|
|
15
|
+
import { CircularProgress } from '../circular-progress';
|
|
15
16
|
import { Dropdown } from '../dropdown';
|
|
16
|
-
import { useComponentProps, useContainerScrolling, useControlled, useDesign, useFocusVisible,
|
|
17
|
+
import { useComponentProps, useContainerScrolling, useControlled, useDesign, useFocusVisible, useLayout, useMaxIndex, useNamespace, useScopedProps, useStyled, useTranslation, } from '../hooks';
|
|
17
18
|
import { Icon } from '../icon';
|
|
18
|
-
import { CircularProgress } from '../internal/circular-progress';
|
|
19
19
|
import { Portal } from '../internal/portal';
|
|
20
|
-
import { Transition } from '../internal/transition';
|
|
21
20
|
import { ROOT_DATA } from '../root/vars';
|
|
22
21
|
import { Tag } from '../tag';
|
|
22
|
+
import { Transition } from '../transition';
|
|
23
23
|
import { MultipleTreeNode } from '../tree/node/multiple-node';
|
|
24
24
|
import { SingleTreeNode } from '../tree/node/single-node';
|
|
25
25
|
import { getTreeNodeLabel } from '../tree/utils';
|
|
26
26
|
import { TREE_NODE_KEY } from '../tree/vars';
|
|
27
27
|
import { getVerticalSidePosition, isPrintableCharacter, mergeCS } from '../utils';
|
|
28
28
|
import { TTANSITION_DURING_POPUP, WINDOW_SPACE } from '../vars';
|
|
29
|
-
function
|
|
30
|
-
const _a = useComponentProps('Cascader', props), { styleOverrides, styleProvider, formControl, list, model, defaultModel, visible: visibleProp, defaultVisible, placeholder, multiple = false, searchable = false, searchValue: searchValueProp, defaultSearchValue, onlyLeafSelectable = true, clearable: clearableProp = false, loading = false, size: sizeProp, disabled: disabledProp = false, virtual = false, escClosable = true, customItem, customSelected, customSearch,
|
|
29
|
+
export function Cascader(props) {
|
|
30
|
+
const _a = useComponentProps('Cascader', props), { ref, styleOverrides, styleProvider, formControl, list, model, defaultModel, visible: visibleProp, defaultVisible, placeholder, multiple = false, searchable = false, searchValue: searchValueProp, defaultSearchValue, onlyLeafSelectable = true, clearable: clearableProp = false, loading = false, size: sizeProp, disabled: disabledProp = false, virtual = false, escClosable = true, customItem, customSelected, customSearch, inputProps, popupRender, onModelChange, onVisibleChange, onSearch, onClear, onFirstFocus, afterVisibleChange } = _a, restProps = __rest(_a, ["ref", "styleOverrides", "styleProvider", "formControl", "list", "model", "defaultModel", "visible", "defaultVisible", "placeholder", "multiple", "searchable", "searchValue", "defaultSearchValue", "onlyLeafSelectable", "clearable", "loading", "size", "disabled", "virtual", "escClosable", "customItem", "customSelected", "customSearch", "inputProps", "popupRender", "onModelChange", "onVisibleChange", "onSearch", "onClear", "onFirstFocus", "afterVisibleChange"]);
|
|
31
31
|
const namespace = useNamespace();
|
|
32
32
|
const styled = useStyled(CLASSES, { cascader: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.cascader, 'cascader-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['cascader-popup'] }, styleOverrides);
|
|
33
|
-
const sheet = useJSS();
|
|
34
33
|
const { t } = useTranslation();
|
|
35
34
|
const uniqueId = useId();
|
|
36
35
|
const listId = `${namespace}-cascader-list-${uniqueId}`;
|
|
@@ -39,11 +38,8 @@ function CascaderFC(props, ref) {
|
|
|
39
38
|
const boxRef = useRef(null);
|
|
40
39
|
const popupRef = useRef(null);
|
|
41
40
|
const inputRef = useRef(null);
|
|
42
|
-
const combineInputRef = useForkRef(inputRef, inputRefProp);
|
|
43
41
|
const focusRef = useRef(null);
|
|
44
|
-
const
|
|
45
|
-
itemFocused: new Set(),
|
|
46
|
-
});
|
|
42
|
+
const itemFocused = useRef(new Set());
|
|
47
43
|
const [nodes, nodesMap] = useMemo(() => {
|
|
48
44
|
const nodes = list.map((item) => multiple
|
|
49
45
|
? new MultipleTreeNode(item, (origin) => origin.value, {
|
|
@@ -141,11 +137,11 @@ function CascaderFC(props, ref) {
|
|
|
141
137
|
return searchList;
|
|
142
138
|
})();
|
|
143
139
|
const isEmpty = hasSearch ? searchList.length === 0 : nodes.length === 0;
|
|
144
|
-
const [focusVisible,
|
|
140
|
+
const [focusVisible, focusVisibleProps] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
|
|
145
141
|
const [_itemFocusedWithoutSearch, setItemFocusedWithoutSearch] = useState();
|
|
146
142
|
const changeItemFocusedWithoutSearch = (node) => {
|
|
147
|
-
if (!
|
|
148
|
-
|
|
143
|
+
if (!itemFocused.current.has(node.id)) {
|
|
144
|
+
itemFocused.current.add(node.id);
|
|
149
145
|
onFirstFocus === null || onFirstFocus === void 0 ? void 0 : onFirstFocus(node.id, node.origin);
|
|
150
146
|
}
|
|
151
147
|
setItemFocusedWithoutSearch(node);
|
|
@@ -163,8 +159,8 @@ function CascaderFC(props, ref) {
|
|
|
163
159
|
})();
|
|
164
160
|
const [_itemFocusedWithSearch, setItemFocusedWithSearch] = useState();
|
|
165
161
|
const changeItemFocusedWithSearch = (item) => {
|
|
166
|
-
if (!
|
|
167
|
-
|
|
162
|
+
if (!itemFocused.current.has(item.value)) {
|
|
163
|
+
itemFocused.current.add(item.value);
|
|
168
164
|
onFirstFocus === null || onFirstFocus === void 0 ? void 0 : onFirstFocus(item.value, item[TREE_NODE_KEY].origin);
|
|
169
165
|
}
|
|
170
166
|
setItemFocusedWithSearch(item);
|
|
@@ -180,7 +176,6 @@ function CascaderFC(props, ref) {
|
|
|
180
176
|
})();
|
|
181
177
|
const maxZIndex = useMaxIndex(visible);
|
|
182
178
|
const zIndex = `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
183
|
-
const transformOrigin = useRef();
|
|
184
179
|
const updatePosition = useEventCallback(() => {
|
|
185
180
|
if (visible && boxRef.current && popupRef.current) {
|
|
186
181
|
const height = popupRef.current.offsetHeight;
|
|
@@ -190,16 +185,10 @@ function CascaderFC(props, ref) {
|
|
|
190
185
|
placement: 'bottom-left',
|
|
191
186
|
inWindow: WINDOW_SPACE,
|
|
192
187
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
sheet.replaceRule('position', {
|
|
198
|
-
top: position.top,
|
|
199
|
-
left: position.left,
|
|
200
|
-
maxWidth,
|
|
201
|
-
});
|
|
202
|
-
popupRef.current.classList.toggle(sheet.classes.position, true);
|
|
188
|
+
popupRef.current.style.setProperty(`--popup-down-transform-origin`, position.transformOrigin);
|
|
189
|
+
popupRef.current.style.top = position.top + 'px';
|
|
190
|
+
popupRef.current.style.left = position.left + 'px';
|
|
191
|
+
popupRef.current.style.maxWidth = maxWidth + 'px';
|
|
203
192
|
}
|
|
204
193
|
});
|
|
205
194
|
useContainerScrolling(boxRef, updatePosition, !visible);
|
|
@@ -214,141 +203,9 @@ function CascaderFC(props, ref) {
|
|
|
214
203
|
e.preventDefault();
|
|
215
204
|
}
|
|
216
205
|
};
|
|
217
|
-
const scrollCallback = useRef();
|
|
206
|
+
const scrollCallback = useRef(() => { });
|
|
218
207
|
const inputable = searchable && visible;
|
|
219
208
|
const clearable = clearableProp && hasSelected && !visible && !loading && !disabled;
|
|
220
|
-
const inputNode = focusVisibleWrapper(createElement(searchable ? BaseInput : 'div', Object.assign(Object.assign(Object.assign(Object.assign({}, mergeCS(styled('cascader__search'), {
|
|
221
|
-
style: {
|
|
222
|
-
opacity: inputable ? undefined : 0,
|
|
223
|
-
zIndex: inputable ? undefined : -1,
|
|
224
|
-
},
|
|
225
|
-
})), formControl === null || formControl === void 0 ? void 0 : formControl.inputAria), { ref: combineInputRef, tabIndex: disabled ? -1 : 0, role: 'combobox', 'aria-haspopup': 'listbox', 'aria-expanded': visible, 'aria-controls': listId, onBlur: () => {
|
|
226
|
-
changeVisible(false);
|
|
227
|
-
}, onKeyDown: (e) => {
|
|
228
|
-
if (e.code === 'Escape') {
|
|
229
|
-
if (visible && escClosable) {
|
|
230
|
-
e.stopPropagation();
|
|
231
|
-
e.preventDefault();
|
|
232
|
-
changeVisible(false);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
const focusItem = (code) => {
|
|
237
|
-
if (focusRef.current) {
|
|
238
|
-
const item = focusRef.current(code);
|
|
239
|
-
if (item) {
|
|
240
|
-
hasSearch ? changeItemFocusedWithSearch(item) : changeItemFocusedWithoutSearch(item);
|
|
241
|
-
if (virtual === false && !code.includes('level')) {
|
|
242
|
-
scrollCallback.current = () => {
|
|
243
|
-
const el = document.getElementById(getItemId(hasSearch ? item.value : item.id));
|
|
244
|
-
if (el) {
|
|
245
|
-
focusRef.current(el);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
if (visible) {
|
|
249
|
-
scrollCallback.current();
|
|
250
|
-
scrollCallback.current = undefined;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
if (visible) {
|
|
257
|
-
switch (e.code) {
|
|
258
|
-
case 'ArrowUp': {
|
|
259
|
-
e.preventDefault();
|
|
260
|
-
focusItem('prev');
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
case 'ArrowDown': {
|
|
264
|
-
e.preventDefault();
|
|
265
|
-
focusItem('next');
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case 'ArrowLeft': {
|
|
269
|
-
if (!hasSearch) {
|
|
270
|
-
e.preventDefault();
|
|
271
|
-
focusItem('prev-level');
|
|
272
|
-
}
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
case 'ArrowRight': {
|
|
276
|
-
if (!hasSearch) {
|
|
277
|
-
e.preventDefault();
|
|
278
|
-
focusItem('next-level');
|
|
279
|
-
}
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case 'Home': {
|
|
283
|
-
e.preventDefault();
|
|
284
|
-
focusItem('first');
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
case 'End': {
|
|
288
|
-
e.preventDefault();
|
|
289
|
-
focusItem('last');
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
default: {
|
|
293
|
-
if (e.code === 'Enter' || (e.code === 'Space' && !searchable)) {
|
|
294
|
-
e.preventDefault();
|
|
295
|
-
if (hasSearch) {
|
|
296
|
-
if (itemFocusedWithSearch) {
|
|
297
|
-
changeSelectedByClickWithSearch(itemFocusedWithSearch);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
if (itemFocusedWithoutSearch) {
|
|
302
|
-
changeSelectedByClickWithoutSearch(itemFocusedWithoutSearch);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
else if (!(searchable && ['Home', 'End', 'Enter', 'Space'].includes(e.code))) {
|
|
311
|
-
switch (e.code) {
|
|
312
|
-
case 'End':
|
|
313
|
-
case 'ArrowUp': {
|
|
314
|
-
e.preventDefault();
|
|
315
|
-
changeVisible(true);
|
|
316
|
-
focusItem('last');
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
case 'Home':
|
|
320
|
-
case 'ArrowDown': {
|
|
321
|
-
e.preventDefault();
|
|
322
|
-
changeVisible(true);
|
|
323
|
-
focusItem('first');
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
case 'Enter':
|
|
327
|
-
case 'Space': {
|
|
328
|
-
e.preventDefault();
|
|
329
|
-
changeVisible(true);
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
default: {
|
|
333
|
-
if (isPrintableCharacter(e.key)) {
|
|
334
|
-
changeVisible(true);
|
|
335
|
-
}
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
} }), searchable
|
|
342
|
-
? {
|
|
343
|
-
type: 'text',
|
|
344
|
-
value: searchValue,
|
|
345
|
-
autoComplete: 'off',
|
|
346
|
-
disabled,
|
|
347
|
-
onValueChange: (val) => {
|
|
348
|
-
changeSearchValue(val);
|
|
349
|
-
},
|
|
350
|
-
}
|
|
351
|
-
: {})));
|
|
352
209
|
const [selectedNode, suffixNode, selectedLabel] = (() => {
|
|
353
210
|
let selectedNode = null;
|
|
354
211
|
let suffixNode = null;
|
|
@@ -372,7 +229,7 @@ function CascaderFC(props, ref) {
|
|
|
372
229
|
draft.splice(draft.findIndex((v) => v === id), 1);
|
|
373
230
|
});
|
|
374
231
|
return false;
|
|
375
|
-
}, children: _jsx(Tag, { tabIndex: -1, size: size, children: selected.size }) }));
|
|
232
|
+
}, children: (dropdownProps) => (_jsx(Tag, Object.assign({}, dropdownProps, { tabIndex: -1, size: size, children: selected.size }))) }));
|
|
376
233
|
selectedNode = selectedNodes.map(({ value, label, node }) => (_jsxs(Tag, { size: size, children: [label, !((node === null || node === void 0 ? void 0 : node.disabled) || disabled) && (_jsx("div", Object.assign({}, styled('cascader__close'), { role: "button", "aria-label": t('Close'), onClick: (e) => {
|
|
377
234
|
e.stopPropagation();
|
|
378
235
|
const checkeds = node.changeStatus('UNCHECKED', selected);
|
|
@@ -398,7 +255,12 @@ function CascaderFC(props, ref) {
|
|
|
398
255
|
}), {
|
|
399
256
|
className: restProps.className,
|
|
400
257
|
style: restProps.style,
|
|
401
|
-
}), designProps, { ref:
|
|
258
|
+
}), designProps, { ref: (instance) => {
|
|
259
|
+
boxRef.current = instance;
|
|
260
|
+
return () => {
|
|
261
|
+
boxRef.current = null;
|
|
262
|
+
};
|
|
263
|
+
}, onMouseDown: (e) => {
|
|
402
264
|
var _a;
|
|
403
265
|
(_a = restProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
404
266
|
preventBlur(e);
|
|
@@ -411,7 +273,158 @@ function CascaderFC(props, ref) {
|
|
|
411
273
|
(_a = restProps.onClick) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
412
274
|
(_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus({ preventScroll: true });
|
|
413
275
|
changeVisible((draft) => (searchable ? true : !draft));
|
|
414
|
-
}, children: [_jsxs("div", Object.assign({}, styled('cascader__container'), { title: selectedLabel, children: [
|
|
276
|
+
}, children: [_jsxs("div", Object.assign({}, styled('cascader__container'), { title: selectedLabel, children: [(() => {
|
|
277
|
+
const nodeProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, inputProps), mergeCS(styled('cascader__search'), {
|
|
278
|
+
style: {
|
|
279
|
+
opacity: inputable ? undefined : 0,
|
|
280
|
+
zIndex: inputable ? undefined : -1,
|
|
281
|
+
},
|
|
282
|
+
})), formControl === null || formControl === void 0 ? void 0 : formControl.inputAria), { ref: (instance) => {
|
|
283
|
+
inputRef.current = instance;
|
|
284
|
+
const ret = setRef(inputProps === null || inputProps === void 0 ? void 0 : inputProps.ref, instance);
|
|
285
|
+
return () => {
|
|
286
|
+
inputRef.current = null;
|
|
287
|
+
ret();
|
|
288
|
+
};
|
|
289
|
+
}, tabIndex: disabled ? -1 : 0, role: 'combobox', 'aria-haspopup': 'listbox', 'aria-expanded': visible, 'aria-controls': listId, onFocus: (e) => {
|
|
290
|
+
var _a;
|
|
291
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
292
|
+
focusVisibleProps.onFocus(e);
|
|
293
|
+
}, onBlur: (e) => {
|
|
294
|
+
var _a;
|
|
295
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
296
|
+
focusVisibleProps.onBlur(e);
|
|
297
|
+
changeVisible(false);
|
|
298
|
+
}, onKeyDown: (e) => {
|
|
299
|
+
var _a;
|
|
300
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
301
|
+
focusVisibleProps.onKeyDown(e);
|
|
302
|
+
if (e.code === 'Escape') {
|
|
303
|
+
if (visible && escClosable) {
|
|
304
|
+
e.stopPropagation();
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
changeVisible(false);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
const focusItem = (code) => {
|
|
311
|
+
if (focusRef.current) {
|
|
312
|
+
const item = focusRef.current(code);
|
|
313
|
+
if (item) {
|
|
314
|
+
hasSearch ? changeItemFocusedWithSearch(item) : changeItemFocusedWithoutSearch(item);
|
|
315
|
+
if (virtual === false && !code.includes('level')) {
|
|
316
|
+
scrollCallback.current = () => {
|
|
317
|
+
scrollCallback.current = () => { };
|
|
318
|
+
const el = document.getElementById(getItemId(hasSearch ? item.value : item.id));
|
|
319
|
+
if (el) {
|
|
320
|
+
focusRef.current(el);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
if (visible) {
|
|
324
|
+
scrollCallback.current();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
if (visible) {
|
|
331
|
+
switch (e.code) {
|
|
332
|
+
case 'ArrowUp': {
|
|
333
|
+
e.preventDefault();
|
|
334
|
+
focusItem('prev');
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case 'ArrowDown': {
|
|
338
|
+
e.preventDefault();
|
|
339
|
+
focusItem('next');
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case 'ArrowLeft': {
|
|
343
|
+
if (!hasSearch) {
|
|
344
|
+
e.preventDefault();
|
|
345
|
+
focusItem('prev-level');
|
|
346
|
+
}
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case 'ArrowRight': {
|
|
350
|
+
if (!hasSearch) {
|
|
351
|
+
e.preventDefault();
|
|
352
|
+
focusItem('next-level');
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case 'Home': {
|
|
357
|
+
e.preventDefault();
|
|
358
|
+
focusItem('first');
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
case 'End': {
|
|
362
|
+
e.preventDefault();
|
|
363
|
+
focusItem('last');
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
default: {
|
|
367
|
+
if (e.code === 'Enter' || (e.code === 'Space' && !searchable)) {
|
|
368
|
+
e.preventDefault();
|
|
369
|
+
if (hasSearch) {
|
|
370
|
+
if (itemFocusedWithSearch) {
|
|
371
|
+
changeSelectedByClickWithSearch(itemFocusedWithSearch);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
if (itemFocusedWithoutSearch) {
|
|
376
|
+
changeSelectedByClickWithoutSearch(itemFocusedWithoutSearch);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else if (!(searchable && ['Home', 'End', 'Enter', 'Space'].includes(e.code))) {
|
|
385
|
+
switch (e.code) {
|
|
386
|
+
case 'End':
|
|
387
|
+
case 'ArrowUp': {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
changeVisible(true);
|
|
390
|
+
focusItem('last');
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
case 'Home':
|
|
394
|
+
case 'ArrowDown': {
|
|
395
|
+
e.preventDefault();
|
|
396
|
+
changeVisible(true);
|
|
397
|
+
focusItem('first');
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case 'Enter':
|
|
401
|
+
case 'Space': {
|
|
402
|
+
e.preventDefault();
|
|
403
|
+
changeVisible(true);
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
default: {
|
|
407
|
+
if (isPrintableCharacter(e.key)) {
|
|
408
|
+
changeVisible(true);
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
} }), searchable
|
|
416
|
+
? {
|
|
417
|
+
type: 'text',
|
|
418
|
+
value: searchValue,
|
|
419
|
+
autoComplete: 'off',
|
|
420
|
+
disabled,
|
|
421
|
+
onValueChange: (val) => {
|
|
422
|
+
changeSearchValue(val);
|
|
423
|
+
},
|
|
424
|
+
}
|
|
425
|
+
: {});
|
|
426
|
+
return searchable ? _jsx(BaseInput, Object.assign({}, nodeProps)) : _jsx("div", Object.assign({}, nodeProps));
|
|
427
|
+
})(), !inputable &&
|
|
415
428
|
(hasSelected ? (_jsx("div", Object.assign({}, styled('cascader__content'), { children: selectedNode }))) : placeholder ? (_jsx("div", Object.assign({}, styled('cascader__placeholder-wrapper'), { children: _jsx("div", Object.assign({}, styled('cascader__placeholder'), { children: placeholder })) }))) : null)] })), multiple && (_jsx("div", Object.assign({}, styled('cascader__multiple-count'), { onClick: (e) => {
|
|
416
429
|
e.stopPropagation();
|
|
417
430
|
}, children: suffixNode }))), clearable && (_jsx("div", Object.assign({}, styled('cascader__clear'), { role: "button", "aria-label": t('Clear'), onClick: (e) => {
|
|
@@ -433,56 +446,46 @@ function CascaderFC(props, ref) {
|
|
|
433
446
|
document.body.appendChild(el);
|
|
434
447
|
}
|
|
435
448
|
return el;
|
|
436
|
-
}, children: _jsx(Transition, { enter: visible,
|
|
437
|
-
|
|
449
|
+
}, children: _jsx(Transition, { enter: visible, name: `${namespace}-popup-down`, duration: TTANSITION_DURING_POPUP, onSkipEnter: () => {
|
|
450
|
+
updatePosition();
|
|
451
|
+
scrollCallback.current();
|
|
452
|
+
}, onBeforeEnter: () => {
|
|
438
453
|
updatePosition();
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}, afterEnter: () => {
|
|
454
|
+
scrollCallback.current();
|
|
455
|
+
}, onAfterEnter: () => {
|
|
442
456
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
|
|
443
|
-
},
|
|
457
|
+
}, onAfterLeave: () => {
|
|
444
458
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
445
|
-
}, children: (
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}, children: (() => {
|
|
478
|
-
const el = (_jsxs("div", Object.assign({}, styled('cascader-popup__content'), { children: [loading && (_jsx("div", Object.assign({}, styled('cascader-popup__loading', {
|
|
479
|
-
'cascader-popup__loading--empty': isEmpty,
|
|
480
|
-
}), { children: _jsx(Icon, { children: _jsx(CircularProgress, {}) }) }))), loading && isEmpty ? null : hasSearch ? (_jsx(CascaderSearchPanel, { ref: focusRef, namespace: namespace, styled: styled, id: listId, list: searchList, customItem: customItem, itemId: getItemId, itemFocused: itemFocusedWithSearch, multiple: multiple, onlyLeafSelectable: onlyLeafSelectable, virtual: virtual, focusVisible: focusVisible, onClick: (item) => {
|
|
481
|
-
changeItemFocusedWithSearch(item);
|
|
482
|
-
changeSelectedByClickWithSearch(item);
|
|
483
|
-
} })) : (_jsx(CascaderPanel, { ref: focusRef, namespace: namespace, styled: styled, id: listId, list: nodes, customItem: customItem, itemId: getItemId, itemSelected: !multiple && hasSelected ? nodesMap.get(selected) : undefined, itemFocused: itemFocusedWithoutSearch, multiple: multiple, virtual: virtual, focusVisible: focusVisible, onFocus: changeItemFocusedWithoutSearch, onClick: changeSelectedByClickWithoutSearch }))] })));
|
|
484
|
-
return popupRender ? popupRender(el) : el;
|
|
485
|
-
})() })));
|
|
486
|
-
} }) })] }));
|
|
459
|
+
}, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, mergeCS(styled('cascader-popup'), {
|
|
460
|
+
style: Object.assign({ zIndex }, (leaved ? { display: 'none' } : undefined)),
|
|
461
|
+
}), { ref: (instance) => {
|
|
462
|
+
popupRef.current = instance;
|
|
463
|
+
transitionRef(instance);
|
|
464
|
+
return () => {
|
|
465
|
+
popupRef.current = null;
|
|
466
|
+
transitionRef(null);
|
|
467
|
+
};
|
|
468
|
+
}, onMouseDown: (e) => {
|
|
469
|
+
preventBlur(e);
|
|
470
|
+
}, onMouseUp: (e) => {
|
|
471
|
+
preventBlur(e);
|
|
472
|
+
}, children: (() => {
|
|
473
|
+
const el = (_jsxs("div", Object.assign({}, styled('cascader-popup__content'), { children: [loading && (_jsx("div", Object.assign({}, styled('cascader-popup__loading', {
|
|
474
|
+
'cascader-popup__loading--empty': isEmpty,
|
|
475
|
+
}), { children: _jsx(Icon, { children: _jsx(CircularProgress, {}) }) }))), loading && isEmpty ? null : hasSearch ? (_jsx(CascaderSearchPanel, { ref: (instance) => {
|
|
476
|
+
focusRef.current = instance;
|
|
477
|
+
return () => {
|
|
478
|
+
focusRef.current = null;
|
|
479
|
+
};
|
|
480
|
+
}, namespace: namespace, styled: styled, id: listId, list: searchList, customItem: customItem, itemId: getItemId, itemFocused: itemFocusedWithSearch, multiple: multiple, onlyLeafSelectable: onlyLeafSelectable, virtual: virtual, focusVisible: focusVisible, onClick: (item) => {
|
|
481
|
+
changeItemFocusedWithSearch(item);
|
|
482
|
+
changeSelectedByClickWithSearch(item);
|
|
483
|
+
} })) : (_jsx(CascaderPanel, { ref: (instance) => {
|
|
484
|
+
focusRef.current = instance;
|
|
485
|
+
return () => {
|
|
486
|
+
focusRef.current = null;
|
|
487
|
+
};
|
|
488
|
+
}, namespace: namespace, styled: styled, id: listId, list: nodes, customItem: customItem, itemId: getItemId, itemSelected: !multiple && hasSelected ? nodesMap.get(selected) : undefined, itemFocused: itemFocusedWithoutSearch, multiple: multiple, virtual: virtual, focusVisible: focusVisible, onFocus: changeItemFocusedWithoutSearch, onClick: changeSelectedByClickWithoutSearch }))] })));
|
|
489
|
+
return popupRender ? popupRender(el) : el;
|
|
490
|
+
})() }))) }) })] }));
|
|
487
491
|
}
|
|
488
|
-
export const Cascader = forwardRef(CascaderFC);
|
|
@@ -4,6 +4,7 @@ import type { AbstractTreeNode } from '../../tree/node/abstract-node';
|
|
|
4
4
|
import type { CascaderItem } from '../types';
|
|
5
5
|
import type { CLASSES } from '../vars';
|
|
6
6
|
interface CascaderPanelProps<V extends React.Key, T extends CascaderItem<V>> {
|
|
7
|
+
ref?: React.Ref<(code: any) => AbstractTreeNode<V, T> | undefined>;
|
|
7
8
|
namespace: string;
|
|
8
9
|
styled: Styled<typeof CLASSES>;
|
|
9
10
|
id: string | undefined;
|
|
@@ -18,6 +19,5 @@ interface CascaderPanelProps<V extends React.Key, T extends CascaderItem<V>> {
|
|
|
18
19
|
onFocus: (item: AbstractTreeNode<V, T>) => void;
|
|
19
20
|
onClick: (item: AbstractTreeNode<V, T>) => void;
|
|
20
21
|
}
|
|
21
|
-
declare function
|
|
22
|
-
export declare const CascaderPanel: <V extends React.Key, T extends CascaderItem<V>>(props: CascaderPanelProps<V, T> & React.RefAttributes<any>) => ReturnType<typeof CascaderPanelFC>;
|
|
22
|
+
export declare function CascaderPanel<V extends React.Key, T extends CascaderItem<V>>(props: CascaderPanelProps<V, T>): React.ReactElement | null;
|
|
23
23
|
export {};
|
|
@@ -4,14 +4,14 @@ import { useEventCallback } from '@laser-ui/hooks';
|
|
|
4
4
|
import { scrollIntoViewIfNeeded } from '@laser-ui/utils';
|
|
5
5
|
import KeyboardArrowRightOutlined from '@material-design-icons/svg/outlined/keyboard_arrow_right.svg?react';
|
|
6
6
|
import { isNumber, isUndefined } from 'lodash';
|
|
7
|
-
import {
|
|
7
|
+
import { useImperativeHandle, useMemo, useRef } from 'react';
|
|
8
8
|
import { Checkbox } from '../../checkbox';
|
|
9
|
+
import { CircularProgress } from '../../circular-progress';
|
|
9
10
|
import { Empty } from '../../empty';
|
|
10
11
|
import { Icon } from '../../icon';
|
|
11
|
-
import { CircularProgress } from '../../internal/circular-progress';
|
|
12
12
|
import { VirtualScroll } from '../../virtual-scroll';
|
|
13
|
-
function
|
|
14
|
-
const { namespace, styled, id, list, customItem, itemId, itemSelected, itemFocused, multiple, virtual, focusVisible, onFocus, onClick, _root = true, } = props;
|
|
13
|
+
export function CascaderPanel(props) {
|
|
14
|
+
const { ref, namespace, styled, id, list, customItem, itemId, itemSelected, itemFocused, multiple, virtual, focusVisible, onFocus, onClick, _root = true, } = props;
|
|
15
15
|
const listRef = useRef(null);
|
|
16
16
|
const vsRef = useRef(null);
|
|
17
17
|
const focusRef = useRef(null);
|
|
@@ -99,7 +99,12 @@ function CascaderPanelFC(props, ref) {
|
|
|
99
99
|
itemSize: isNumber(virtual) ? virtual : 32,
|
|
100
100
|
itemFocusable: (item) => item.enabled,
|
|
101
101
|
}), [list, virtual]);
|
|
102
|
-
return (_jsxs(_Fragment, { children: [_jsx(VirtualScroll, Object.assign({}, vsProps, { ref:
|
|
102
|
+
return (_jsxs(_Fragment, { children: [_jsx(VirtualScroll, Object.assign({}, vsProps, { ref: (instance) => {
|
|
103
|
+
vsRef.current = instance;
|
|
104
|
+
return () => {
|
|
105
|
+
vsRef.current = null;
|
|
106
|
+
};
|
|
107
|
+
}, enable: virtual !== false, listSize: 264, listPadding: 4, itemRender: (item, index, props) => {
|
|
103
108
|
let isSelectedAncestry = false;
|
|
104
109
|
if (item.children && itemSelected) {
|
|
105
110
|
let node = itemSelected;
|
|
@@ -130,6 +135,15 @@ function CascaderPanelFC(props, ref) {
|
|
|
130
135
|
} }) }))),
|
|
131
136
|
_jsx("div", Object.assign({}, styled('cascader__option-content'), { children: customItem ? customItem(item.origin) : item.origin.label })),
|
|
132
137
|
!item.isLeaf && (_jsx("div", Object.assign({}, styled('cascader__option-icon'), { children: _jsx(Icon, { children: item.origin.loading ? _jsx(CircularProgress, {}) : _jsx(KeyboardArrowRightOutlined, {}) }) })))));
|
|
133
|
-
}, itemFocused: nodeFocused === null || nodeFocused === void 0 ? void 0 : nodeFocused.id, placeholder: "li", children: (vsList, onScroll) => (_jsx("ul", Object.assign({}, styled('cascader__list', 'cascader__list--inline'), { ref:
|
|
138
|
+
}, itemFocused: nodeFocused === null || nodeFocused === void 0 ? void 0 : nodeFocused.id, placeholder: "li", children: (vsList, onScroll) => (_jsx("ul", Object.assign({}, styled('cascader__list', 'cascader__list--inline'), { ref: (instance) => {
|
|
139
|
+
listRef.current = instance;
|
|
140
|
+
return () => {
|
|
141
|
+
listRef.current = null;
|
|
142
|
+
};
|
|
143
|
+
}, id: id, tabIndex: -1, role: "listbox", "aria-multiselectable": multiple, "aria-activedescendant": _root && !isUndefined(itemFocused) ? itemId(itemFocused.id) : undefined, onScroll: onScroll, children: list.length === 0 ? _jsx(Empty, { style: { padding: '12px 28px' }, image: Empty.SIMPLE_IMG }) : vsList }))) })), nodeFocused && !nodeFocused.origin.loading && nodeFocused.children && (_jsx(CascaderPanel, Object.assign({}, props, { _root: false, ref: (instance) => {
|
|
144
|
+
focusRef.current = instance;
|
|
145
|
+
return () => {
|
|
146
|
+
focusRef.current = null;
|
|
147
|
+
};
|
|
148
|
+
}, id: undefined, list: nodeFocused.children })))] }));
|
|
134
149
|
}
|
|
135
|
-
export const CascaderPanel = forwardRef(CascaderPanelFC);
|
|
@@ -4,6 +4,7 @@ import type { Styled } from '../../hooks/useStyled';
|
|
|
4
4
|
import type { CascaderItem } from '../types';
|
|
5
5
|
import type { CLASSES } from '../vars';
|
|
6
6
|
interface CascaderSearchPanelProps<V extends React.Key, T extends CascaderItem<V>> {
|
|
7
|
+
ref?: React.Ref<(code: any) => CascaderSearchPanelItem<V, T> | undefined>;
|
|
7
8
|
namespace: string;
|
|
8
9
|
styled: Styled<typeof CLASSES>;
|
|
9
10
|
id: string;
|
|
@@ -17,6 +18,5 @@ interface CascaderSearchPanelProps<V extends React.Key, T extends CascaderItem<V
|
|
|
17
18
|
focusVisible: boolean;
|
|
18
19
|
onClick: (item: CascaderSearchPanelItem<V, T>) => void;
|
|
19
20
|
}
|
|
20
|
-
declare function
|
|
21
|
-
export declare const CascaderSearchPanel: <V extends React.Key, T extends CascaderItem<V>>(props: CascaderSearchPanelProps<V, T> & React.RefAttributes<any>) => ReturnType<typeof CascaderSearchPanelFC>;
|
|
21
|
+
export declare function CascaderSearchPanel<V extends React.Key, T extends CascaderItem<V>>(props: CascaderSearchPanelProps<V, T>): React.ReactElement | null;
|
|
22
22
|
export {};
|