@aloudata/aloudata-design 0.1.0-beta1
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/.editorconfig +16 -0
- package/.eslintrc.js +43 -0
- package/.fatherrc.ts +16 -0
- package/.prettierignore +7 -0
- package/.prettierrc.js +1 -0
- package/.stylelintrc.json +36 -0
- package/.umirc.ts +15 -0
- package/README.md +82 -0
- package/commitlint.config.js +21 -0
- package/docs/index.md +21 -0
- package/jest/setupTests.js +1 -0
- package/lib/Button/demo/Icon/index.d.ts +3 -0
- package/lib/Button/demo/Icon/index.js +82 -0
- package/lib/Button/demo/Icon/index.less +6 -0
- package/lib/Button/demo/basic/index.d.ts +4 -0
- package/lib/Button/demo/basic/index.js +73 -0
- package/lib/Button/demo/basic/index.less +7 -0
- package/lib/Button/demo/disable/index.d.ts +3 -0
- package/lib/Button/demo/disable/index.js +37 -0
- package/lib/Button/demo/disable/index.less +0 -0
- package/lib/Button/demo/href/index.d.ts +2 -0
- package/lib/Button/demo/href/index.js +30 -0
- package/lib/Button/demo/loading/index.d.ts +3 -0
- package/lib/Button/demo/loading/index.js +51 -0
- package/lib/Button/demo/loading/index.less +6 -0
- package/lib/Button/index.d.ts +50 -0
- package/lib/Button/index.js +124 -0
- package/lib/Button/style/index.d.ts +2 -0
- package/lib/Button/style/index.js +5 -0
- package/lib/Button/style/index.less +255 -0
- package/lib/Dropdown/Button.d.ts +69 -0
- package/lib/Dropdown/Button.js +52 -0
- package/lib/Dropdown/demo/basic/index.d.ts +4 -0
- package/lib/Dropdown/demo/basic/index.js +35 -0
- package/lib/Dropdown/demo/button/index.d.ts +3 -0
- package/lib/Dropdown/demo/button/index.js +182 -0
- package/lib/Dropdown/demo/button/index.less +9 -0
- package/lib/Dropdown/demo/placement/index.d.ts +2 -0
- package/lib/Dropdown/demo/placement/index.js +56 -0
- package/lib/Dropdown/demo/subMenu/index.d.ts +2 -0
- package/lib/Dropdown/demo/subMenu/index.js +59 -0
- package/lib/Dropdown/demo/trigger/index.d.ts +2 -0
- package/lib/Dropdown/demo/trigger/index.js +32 -0
- package/lib/Dropdown/index.d.ts +59 -0
- package/lib/Dropdown/index.js +47 -0
- package/lib/Dropdown/style/index.d.ts +2 -0
- package/lib/Dropdown/style/index.js +5 -0
- package/lib/Dropdown/style/index.less +40 -0
- package/lib/Icon/iconfont/demo.css +539 -0
- package/lib/Icon/iconfont/demo_index.html +628 -0
- package/lib/Icon/iconfont/iconfont.css +93 -0
- package/lib/Icon/iconfont/iconfont.js +48 -0
- package/lib/Icon/iconfont/iconfont.json +142 -0
- package/lib/Icon/iconfont/iconfont.ttf +0 -0
- package/lib/Icon/iconfont/iconfont.woff +0 -0
- package/lib/Icon/iconfont/iconfont.woff2 +0 -0
- package/lib/Icon/index.d.ts +11 -0
- package/lib/Icon/index.js +54 -0
- package/lib/Icon/index.less +32 -0
- package/lib/Input/components/Group/index.d.ts +15 -0
- package/lib/Input/components/Group/index.js +24 -0
- package/lib/Input/components/Password/index.d.ts +10 -0
- package/lib/Input/components/Password/index.js +33 -0
- package/lib/Input/components/TextArea/index.d.ts +52 -0
- package/lib/Input/components/TextArea/index.js +26 -0
- package/lib/Input/demo/allowClear/index.d.ts +3 -0
- package/lib/Input/demo/allowClear/index.js +25 -0
- package/lib/Input/demo/allowClear/index.less +0 -0
- package/lib/Input/demo/basic/index.d.ts +4 -0
- package/lib/Input/demo/basic/index.js +80 -0
- package/lib/Input/demo/basic/index.less +6 -0
- package/lib/Input/demo/gourp/index.d.ts +2 -0
- package/lib/Input/demo/gourp/index.js +81 -0
- package/lib/Input/demo/password/index.d.ts +3 -0
- package/lib/Input/demo/password/index.js +35 -0
- package/lib/Input/demo/password/index.less +0 -0
- package/lib/Input/demo/prefix/index.d.ts +3 -0
- package/lib/Input/demo/prefix/index.js +32 -0
- package/lib/Input/demo/prefix/index.less +0 -0
- package/lib/Input/demo/showCount/index.d.ts +3 -0
- package/lib/Input/demo/showCount/index.js +31 -0
- package/lib/Input/demo/showCount/index.less +0 -0
- package/lib/Input/demo/textArea/autoSize.d.ts +2 -0
- package/lib/Input/demo/textArea/autoSize.js +63 -0
- package/lib/Input/index.d.ts +65 -0
- package/lib/Input/index.js +63 -0
- package/lib/Input/style/index.d.ts +2 -0
- package/lib/Input/style/index.js +5 -0
- package/lib/Input/style/index.less +62 -0
- package/lib/Menu/Divider.d.ts +5 -0
- package/lib/Menu/Divider.js +28 -0
- package/lib/Menu/MenuItem.d.ts +17 -0
- package/lib/Menu/MenuItem.js +28 -0
- package/lib/Menu/SubMenu.d.ts +26 -0
- package/lib/Menu/SubMenu.js +44 -0
- package/lib/Menu/index.d.ts +20 -0
- package/lib/Menu/index.js +49 -0
- package/lib/Menu/style/index.d.ts +2 -0
- package/lib/Menu/style/index.js +5 -0
- package/lib/Menu/style/index.less +33 -0
- package/lib/Select/BaseSelect.d.ts +5 -0
- package/lib/Select/BaseSelect.js +433 -0
- package/lib/Select/OptionsList/OptGroup.d.ts +7 -0
- package/lib/Select/OptionsList/OptGroup.js +14 -0
- package/lib/Select/OptionsList/OptionItem.d.ts +35 -0
- package/lib/Select/OptionsList/OptionItem.js +185 -0
- package/lib/Select/OptionsList/Options.d.ts +7 -0
- package/lib/Select/OptionsList/Options.js +14 -0
- package/lib/Select/OptionsList/index.d.ts +4 -0
- package/lib/Select/OptionsList/index.js +207 -0
- package/lib/Select/Selector/index.d.ts +4 -0
- package/lib/Select/Selector/index.js +273 -0
- package/lib/Select/VirtualList.d.ts +5 -0
- package/lib/Select/VirtualList.js +42 -0
- package/lib/Select/demo/disabled/index.d.ts +2 -0
- package/lib/Select/demo/disabled/index.js +64 -0
- package/lib/Select/demo/multiple/index.d.ts +2 -0
- package/lib/Select/demo/multiple/index.js +154 -0
- package/lib/Select/demo/options/index.d.ts +2 -0
- package/lib/Select/demo/options/index.js +69 -0
- package/lib/Select/demo/single/index.d.ts +2 -0
- package/lib/Select/demo/single/index.js +99 -0
- package/lib/Select/hooks/useCacheOption.d.ts +9 -0
- package/lib/Select/hooks/useCacheOption.js +113 -0
- package/lib/Select/index.d.ts +12 -0
- package/lib/Select/index.js +34 -0
- package/lib/Select/interface.d.ts +221 -0
- package/lib/Select/interface.js +5 -0
- package/lib/Select/style/index.d.ts +2 -0
- package/lib/Select/style/index.js +5 -0
- package/lib/Select/style/index.less +539 -0
- package/lib/Select/utils.d.ts +21 -0
- package/lib/Select/utils.js +233 -0
- package/lib/Tabs/TabPane.d.ts +21 -0
- package/lib/Tabs/TabPane.js +24 -0
- package/lib/Tabs/demo/adaptHeight/index.d.ts +3 -0
- package/lib/Tabs/demo/adaptHeight/index.js +34 -0
- package/lib/Tabs/demo/adaptHeight/index.less +3 -0
- package/lib/Tabs/demo/basic/index.d.ts +4 -0
- package/lib/Tabs/demo/basic/index.js +67 -0
- package/lib/Tabs/demo/basic/index.less +5 -0
- package/lib/Tabs/demo/horizontalScroll/index.d.ts +3 -0
- package/lib/Tabs/demo/horizontalScroll/index.js +45 -0
- package/lib/Tabs/demo/horizontalScroll/index.less +3 -0
- package/lib/Tabs/index.d.ts +41 -0
- package/lib/Tabs/index.js +58 -0
- package/lib/Tabs/style/index.d.ts +2 -0
- package/lib/Tabs/style/index.js +5 -0
- package/lib/Tabs/style/index.less +61 -0
- package/lib/Tooltip/demo/basic/index.d.ts +2 -0
- package/lib/Tooltip/demo/basic/index.js +20 -0
- package/lib/Tooltip/demo/overflow/index.d.ts +2 -0
- package/lib/Tooltip/demo/overflow/index.js +20 -0
- package/lib/Tooltip/demo/placement/index.d.ts +6 -0
- package/lib/Tooltip/demo/placement/index.js +86 -0
- package/lib/Tooltip/demo/placement/index.less +7 -0
- package/lib/Tooltip/demo/trigger/index.d.ts +3 -0
- package/lib/Tooltip/demo/trigger/index.js +34 -0
- package/lib/Tooltip/demo/trigger/index.less +5 -0
- package/lib/Tooltip/index.d.ts +63 -0
- package/lib/Tooltip/index.js +44 -0
- package/lib/Tooltip/style/index.d.ts +2 -0
- package/lib/Tooltip/style/index.js +5 -0
- package/lib/Tooltip/style/index.less +14 -0
- package/lib/_utils/hooks/useControlledState.d.ts +2 -0
- package/lib/_utils/hooks/useControlledState.js +63 -0
- package/lib/_utils/hooks/usePrefixCls.d.ts +2 -0
- package/lib/_utils/hooks/usePrefixCls.js +27 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +63 -0
- package/lib/style/index.d.ts +2 -0
- package/lib/style/index.js +5 -0
- package/lib/style/index.less +3 -0
- package/lib/style/mixins/index.less +0 -0
- package/lib/style/themes/default/index.less +36 -0
- package/lib/style/themes/default/themeColor.less +259 -0
- package/package.json +83 -0
- package/public/favicon.ico +0 -0
- package/src/Button/demo/Icon/index.less +6 -0
- package/src/Button/demo/Icon/index.tsx +41 -0
- package/src/Button/demo/basic/index.less +7 -0
- package/src/Button/demo/basic/index.tsx +26 -0
- package/src/Button/demo/disable/index.less +0 -0
- package/src/Button/demo/disable/index.tsx +16 -0
- package/src/Button/demo/href/index.tsx +14 -0
- package/src/Button/demo/loading/index.less +6 -0
- package/src/Button/demo/loading/index.tsx +21 -0
- package/src/Button/index.md +25 -0
- package/src/Button/index.test.tsx +58 -0
- package/src/Button/index.tsx +136 -0
- package/src/Button/style/index.less +255 -0
- package/src/Button/style/index.ts +2 -0
- package/src/Dropdown/Button.tsx +93 -0
- package/src/Dropdown/demo/basic/index.tsx +20 -0
- package/src/Dropdown/demo/button/index.less +9 -0
- package/src/Dropdown/demo/button/index.tsx +98 -0
- package/src/Dropdown/demo/placement/index.tsx +47 -0
- package/src/Dropdown/demo/subMenu/index.tsx +35 -0
- package/src/Dropdown/demo/trigger/index.tsx +19 -0
- package/src/Dropdown/index.md +35 -0
- package/src/Dropdown/index.test.tsx +185 -0
- package/src/Dropdown/index.tsx +71 -0
- package/src/Dropdown/style/index.less +40 -0
- package/src/Dropdown/style/index.ts +2 -0
- package/src/Icon/iconfont/demo.css +539 -0
- package/src/Icon/iconfont/demo_index.html +628 -0
- package/src/Icon/iconfont/iconfont.css +93 -0
- package/src/Icon/iconfont/iconfont.js +1 -0
- package/src/Icon/iconfont/iconfont.json +142 -0
- package/src/Icon/iconfont/iconfont.ttf +0 -0
- package/src/Icon/iconfont/iconfont.woff +0 -0
- package/src/Icon/iconfont/iconfont.woff2 +0 -0
- package/src/Icon/index.less +32 -0
- package/src/Icon/index.tsx +38 -0
- package/src/Input/components/Group/index.tsx +21 -0
- package/src/Input/components/Password/index.tsx +23 -0
- package/src/Input/components/TextArea/index.tsx +57 -0
- package/src/Input/demo/allowClear/index.less +0 -0
- package/src/Input/demo/allowClear/index.tsx +10 -0
- package/src/Input/demo/basic/index.less +6 -0
- package/src/Input/demo/basic/index.tsx +25 -0
- package/src/Input/demo/gourp/index.tsx +30 -0
- package/src/Input/demo/password/index.less +0 -0
- package/src/Input/demo/password/index.tsx +11 -0
- package/src/Input/demo/prefix/index.less +0 -0
- package/src/Input/demo/prefix/index.tsx +13 -0
- package/src/Input/demo/showCount/index.less +0 -0
- package/src/Input/demo/showCount/index.tsx +16 -0
- package/src/Input/demo/textArea/autoSize.tsx +21 -0
- package/src/Input/index.md +37 -0
- package/src/Input/index.test.tsx +78 -0
- package/src/Input/index.tsx +91 -0
- package/src/Input/style/index.less +62 -0
- package/src/Input/style/index.ts +2 -0
- package/src/Menu/Divider.tsx +12 -0
- package/src/Menu/MenuItem.tsx +24 -0
- package/src/Menu/SubMenu.tsx +37 -0
- package/src/Menu/index.md +36 -0
- package/src/Menu/index.test.tsx +144 -0
- package/src/Menu/index.tsx +27 -0
- package/src/Menu/style/index.less +33 -0
- package/src/Menu/style/index.ts +2 -0
- package/src/Select/BaseSelect.tsx +321 -0
- package/src/Select/OptionsList/OptGroup.tsx +9 -0
- package/src/Select/OptionsList/OptionItem.tsx +151 -0
- package/src/Select/OptionsList/Options.tsx +11 -0
- package/src/Select/OptionsList/index.tsx +169 -0
- package/src/Select/Selector/index.tsx +211 -0
- package/src/Select/VirtualList.tsx +36 -0
- package/src/Select/demo/disabled/index.tsx +44 -0
- package/src/Select/demo/multiple/index.tsx +77 -0
- package/src/Select/demo/options/index.tsx +63 -0
- package/src/Select/demo/single/index.tsx +50 -0
- package/src/Select/hooks/useCacheOption.ts +67 -0
- package/src/Select/index.md +72 -0
- package/src/Select/index.tsx +23 -0
- package/src/Select/interface.ts +231 -0
- package/src/Select/style/index.less +539 -0
- package/src/Select/style/index.ts +2 -0
- package/src/Select/utils.tsx +133 -0
- package/src/Tabs/TabPane.tsx +28 -0
- package/src/Tabs/demo/adaptHeight/index.less +3 -0
- package/src/Tabs/demo/adaptHeight/index.tsx +33 -0
- package/src/Tabs/demo/basic/index.less +5 -0
- package/src/Tabs/demo/basic/index.tsx +30 -0
- package/src/Tabs/demo/horizontalScroll/index.less +3 -0
- package/src/Tabs/demo/horizontalScroll/index.tsx +36 -0
- package/src/Tabs/index.md +30 -0
- package/src/Tabs/index.test.tsx +100 -0
- package/src/Tabs/index.tsx +64 -0
- package/src/Tabs/style/index.less +61 -0
- package/src/Tabs/style/index.ts +2 -0
- package/src/Tooltip/demo/basic/index.tsx +10 -0
- package/src/Tooltip/demo/overflow/index.tsx +10 -0
- package/src/Tooltip/demo/placement/index.less +7 -0
- package/src/Tooltip/demo/placement/index.tsx +60 -0
- package/src/Tooltip/demo/trigger/index.less +5 -0
- package/src/Tooltip/demo/trigger/index.tsx +22 -0
- package/src/Tooltip/index.md +28 -0
- package/src/Tooltip/index.test.tsx +152 -0
- package/src/Tooltip/index.tsx +113 -0
- package/src/Tooltip/style/index.less +14 -0
- package/src/Tooltip/style/index.ts +2 -0
- package/src/_utils/hooks/useControlledState.ts +39 -0
- package/src/_utils/hooks/usePrefixCls.ts +11 -0
- package/src/index.ts +8 -0
- package/src/style/index.less +3 -0
- package/src/style/index.ts +2 -0
- package/src/style/mixins/index.less +0 -0
- package/src/style/themes/default/index.less +36 -0
- package/src/style/themes/default/themeColor.less +259 -0
- package/tsconfig.json +13 -0
- package/typings.d.ts +3 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import React, { useState, useMemo, useRef, useEffect, ReactText } from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import { filter, isNil, without } from 'lodash';
|
|
4
|
+
import Selector from './Selector';
|
|
5
|
+
import OptionsList from './OptionsList';
|
|
6
|
+
import usePrefixCls from '../_utils/hooks/usePrefixCls';
|
|
7
|
+
import { ISelectProps as SelectProps, IOption as Option, TMaybeArray as MaybeArray, IOptionProps as OptionProps } from './interface';
|
|
8
|
+
import Trigger from 'rc-trigger';
|
|
9
|
+
import {
|
|
10
|
+
convertChildrenToData,
|
|
11
|
+
handleOptions,
|
|
12
|
+
defaultLabelRenderer,
|
|
13
|
+
defaultSearchPredicate,
|
|
14
|
+
defaultOptionLabelRenderer,
|
|
15
|
+
getFlattenOptions,
|
|
16
|
+
} from './utils';
|
|
17
|
+
import useCacheOptions from './hooks/useCacheOption';
|
|
18
|
+
import useControlledState from '../_utils/hooks/useControlledState';
|
|
19
|
+
|
|
20
|
+
const DEFAULT_LIST_HEIGHT = 256;
|
|
21
|
+
const DEFAULT_ACTIVE_INDEX = -1;
|
|
22
|
+
const ZERO = 0;
|
|
23
|
+
export const Select = (props: SelectProps, ref: React.MutableRefObject<HTMLDivElement>) => {
|
|
24
|
+
const {
|
|
25
|
+
size = 'default',
|
|
26
|
+
options = [],
|
|
27
|
+
defaultValue = null,
|
|
28
|
+
value: controlledValue,
|
|
29
|
+
multiple = false,
|
|
30
|
+
placeholder,
|
|
31
|
+
disabled = false,
|
|
32
|
+
customizePrefixCls,
|
|
33
|
+
label,
|
|
34
|
+
className,
|
|
35
|
+
style,
|
|
36
|
+
optionStyle,
|
|
37
|
+
groupStyle,
|
|
38
|
+
allowClear = false,
|
|
39
|
+
listHeight = DEFAULT_LIST_HEIGHT,
|
|
40
|
+
listRowHeight,
|
|
41
|
+
labelRenderer = defaultLabelRenderer,
|
|
42
|
+
searchPredicate = defaultSearchPredicate,
|
|
43
|
+
optionLabelRenderer = defaultOptionLabelRenderer,
|
|
44
|
+
onChange,
|
|
45
|
+
onSelect,
|
|
46
|
+
onClear,
|
|
47
|
+
getContainer,
|
|
48
|
+
open,
|
|
49
|
+
defaultOpen = false,
|
|
50
|
+
onDropDownVisibleChange,
|
|
51
|
+
dropDownClassName,
|
|
52
|
+
dropDownStyle,
|
|
53
|
+
dropdownMatchSelectWidth = 'width',
|
|
54
|
+
children,
|
|
55
|
+
} = props;
|
|
56
|
+
const prefix = usePrefixCls('select-legacy', customizePrefixCls);
|
|
57
|
+
const [value, setSelectValue] = useControlledState(controlledValue, defaultValue);
|
|
58
|
+
const [tempValue, setTempValue] = useState<React.ReactText[]>([]);
|
|
59
|
+
const [isFocused, setFocused] = useState<boolean>(false);
|
|
60
|
+
const [_visible, _setVisible] = useState<boolean>(defaultOpen);
|
|
61
|
+
const visible = isNil(open) ? _visible : open;
|
|
62
|
+
const setVisible = isNil(onDropDownVisibleChange) ? _setVisible : onDropDownVisibleChange;
|
|
63
|
+
const [input, setInput] = useState('');
|
|
64
|
+
const selectRef = useRef<HTMLDivElement>(null);
|
|
65
|
+
const optionListRef = useRef(null);
|
|
66
|
+
const selectorRef = ref || selectRef;
|
|
67
|
+
// empty
|
|
68
|
+
// keydown
|
|
69
|
+
const [activeIndex, setActiveIndex] = useState<number>(DEFAULT_ACTIVE_INDEX);
|
|
70
|
+
const [optionChecked, setOptionChecked] = useState<React.ReactText[]>([]);
|
|
71
|
+
// Exhibition value (tempvalue + value);
|
|
72
|
+
const selectorValue = useMemo(() => {
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
// filter: if v in value and tempValue no Exhibition
|
|
75
|
+
return value.concat(tempValue).filter((v) => !value.includes(v) || !tempValue.includes(v));
|
|
76
|
+
}
|
|
77
|
+
if (multiple) {
|
|
78
|
+
return tempValue;
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}, [value, multiple, tempValue]);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!disabled) {
|
|
85
|
+
if (visible) {
|
|
86
|
+
selectorRef?.current?.focus();
|
|
87
|
+
setFocused(visible);
|
|
88
|
+
} else {
|
|
89
|
+
setActiveIndex(DEFAULT_ACTIVE_INDEX);
|
|
90
|
+
setFocused(visible);
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
optionListRef?.current?.onBlur();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
}, [visible, disabled]);
|
|
97
|
+
/** merge Option & nodeOption & mergedOptionsMap */
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
const nodesToOptions = useMemo<OptionProps[]>(() => convertChildrenToData(children), [children]);
|
|
100
|
+
const { setCacheOptions, getOptionByValue, getOptionsByValue, updateGroup, hasGroup } = useCacheOptions();
|
|
101
|
+
const { flattenOptions: mergedFlattenOPtions } = useMemo(
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
() => handleOptions([...options, ...nodesToOptions], setCacheOptions, updateGroup),
|
|
104
|
+
[nodesToOptions, options, setCacheOptions, updateGroup]
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// input change
|
|
108
|
+
const onInputChange = (_value: string) => {
|
|
109
|
+
setInput(_value);
|
|
110
|
+
};
|
|
111
|
+
// clear
|
|
112
|
+
const clearInput = () => setInput('');
|
|
113
|
+
|
|
114
|
+
// dropdown visible
|
|
115
|
+
const onVisibleChange = (optVisible: boolean) => {
|
|
116
|
+
if (!disabled) {
|
|
117
|
+
setVisible(optVisible);
|
|
118
|
+
if (!optVisible) {
|
|
119
|
+
setTimeout(clearInput, ZERO);
|
|
120
|
+
selectorRef.current?.blur();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// tempValue change methods
|
|
126
|
+
const onTempValueChange = (values: React.ReactText[]) => {
|
|
127
|
+
// value is array
|
|
128
|
+
const concatValue = isNil(value)
|
|
129
|
+
? values
|
|
130
|
+
: values.concat(value).filter((v) => !(value as React.ReactText[])?.includes(v) || !values?.includes(v));
|
|
131
|
+
onChange?.(concatValue, getOptionsByValue(concatValue));
|
|
132
|
+
onVisibleChange(false);
|
|
133
|
+
setSelectValue(concatValue);
|
|
134
|
+
// clear tempValue
|
|
135
|
+
setTempValue([]);
|
|
136
|
+
};
|
|
137
|
+
const deleteValue = (optValue: React.ReactText[], v: React.ReactText) => {
|
|
138
|
+
return tempValue.includes(v)
|
|
139
|
+
? onTempValueChange(without((optValue as MaybeArray<string>) || [], v))
|
|
140
|
+
: onValueChange(without((optValue as MaybeArray<string>) || [], v));
|
|
141
|
+
};
|
|
142
|
+
const setTempValueFC = (tempvalues: React.ReactText[]) => {
|
|
143
|
+
setTempValue(tempvalues);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const onListSelect = (selectedValue: React.ReactText, option: Option) => {
|
|
147
|
+
if (!multiple) {
|
|
148
|
+
selectorRef.current?.blur();
|
|
149
|
+
} else {
|
|
150
|
+
selectorRef.current?.focus();
|
|
151
|
+
}
|
|
152
|
+
onSelect?.(selectedValue, option);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const onAllowClearClick = () => {
|
|
156
|
+
if (input) {
|
|
157
|
+
clearInput();
|
|
158
|
+
}
|
|
159
|
+
onValueChange(!multiple ? null : []);
|
|
160
|
+
onClear?.();
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// 选项点击
|
|
164
|
+
const onOptionClick = (selectValue: React.ReactText) => {
|
|
165
|
+
const selectedOption = getOptionByValue(selectValue) as Option;
|
|
166
|
+
const isTempSelected = tempValue.includes(selectValue);
|
|
167
|
+
const isSelected = !Array.isArray(value) ? value === selectValue : value.includes(selectValue);
|
|
168
|
+
const isOptionChecked = optionChecked.includes(selectValue);
|
|
169
|
+
if (!multiple) {
|
|
170
|
+
onVisibleChange(false);
|
|
171
|
+
}
|
|
172
|
+
if (isTempSelected) {
|
|
173
|
+
setTempValue((tempvalues) => without(tempvalues, selectValue) as unknown as [ReactText]);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// 点击的时候已经是被选中
|
|
177
|
+
if (isSelected) {
|
|
178
|
+
if (isOptionChecked) {
|
|
179
|
+
onValueChange(Array.isArray(value) ? without((value as MaybeArray<string>) || [], selectValue) : null);
|
|
180
|
+
setOptionChecked(without((value as MaybeArray<string>) || [], selectValue));
|
|
181
|
+
} else {
|
|
182
|
+
onValueChange(Array.isArray(value) ? [...optionChecked, selectValue] : null);
|
|
183
|
+
setOptionChecked([...optionChecked, selectValue]);
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
onListSelect(selectValue, selectedOption);
|
|
187
|
+
if (Array.isArray(value)) {
|
|
188
|
+
onValueChange([...value, selectValue]);
|
|
189
|
+
setOptionChecked([...value, selectValue]);
|
|
190
|
+
} else {
|
|
191
|
+
onValueChange(!multiple ? selectValue : [selectValue]);
|
|
192
|
+
setOptionChecked([selectValue]);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// search filter InputValue // match input(label === input)
|
|
198
|
+
const filteredOptions: Option[] = useMemo(
|
|
199
|
+
() => filter(mergedFlattenOPtions, searchPredicate(input)),
|
|
200
|
+
[mergedFlattenOPtions, searchPredicate, input]
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const flattenOptions = useMemo(() => getFlattenOptions(filteredOptions, false), [filteredOptions]);
|
|
204
|
+
// value other methods
|
|
205
|
+
const onValueChange = (optValue: MaybeArray<string | number> | null) => {
|
|
206
|
+
setSelectValue(optValue);
|
|
207
|
+
if (Array.isArray(optValue) && flattenOptions.length === optValue.length) {
|
|
208
|
+
setOptionChecked([]);
|
|
209
|
+
}
|
|
210
|
+
if (isNil(optValue)) {
|
|
211
|
+
onChange?.(null, null);
|
|
212
|
+
} else {
|
|
213
|
+
onChange?.(optValue, getOptionsByValue(optValue));
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const realSize = useMemo(() => {
|
|
217
|
+
return ['small', 'default', 'large'].includes(size) ? size : 'default';
|
|
218
|
+
}, [size]);
|
|
219
|
+
|
|
220
|
+
const list = (
|
|
221
|
+
<>
|
|
222
|
+
<OptionsList
|
|
223
|
+
ref={optionListRef}
|
|
224
|
+
multiple={multiple}
|
|
225
|
+
prefixCls={prefix}
|
|
226
|
+
selected={selectorValue}
|
|
227
|
+
optionChecked={optionChecked}
|
|
228
|
+
visible={visible}
|
|
229
|
+
hasGroup={hasGroup}
|
|
230
|
+
groupStyle={groupStyle}
|
|
231
|
+
optionStyle={optionStyle}
|
|
232
|
+
searchType="no-search"
|
|
233
|
+
placeholder={placeholder}
|
|
234
|
+
data={flattenOptions as Option[]}
|
|
235
|
+
labelRenderer={labelRenderer(input, prefix)}
|
|
236
|
+
value={value}
|
|
237
|
+
tempValue={tempValue}
|
|
238
|
+
onOptionClick={onOptionClick}
|
|
239
|
+
onValueChange={onValueChange}
|
|
240
|
+
onTempValueChange={onTempValueChange}
|
|
241
|
+
setTempValue={setTempValueFC}
|
|
242
|
+
onInputChange={onInputChange}
|
|
243
|
+
input={input}
|
|
244
|
+
height={listHeight}
|
|
245
|
+
getContainer={getContainer}
|
|
246
|
+
itemHeight={listRowHeight}
|
|
247
|
+
activeIndex={activeIndex}
|
|
248
|
+
setActiveIndex={setActiveIndex}
|
|
249
|
+
/>
|
|
250
|
+
</>
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<Trigger
|
|
255
|
+
popupVisible={visible}
|
|
256
|
+
onPopupVisibleChange={onVisibleChange}
|
|
257
|
+
action={['click']}
|
|
258
|
+
popupPlacement="bottomLeft"
|
|
259
|
+
popup={list}
|
|
260
|
+
prefixCls={prefix}
|
|
261
|
+
popupClassName={classnames(`${prefix}-dropdown`, dropDownClassName)}
|
|
262
|
+
popupStyle={dropDownStyle}
|
|
263
|
+
getPopupContainer={getContainer}
|
|
264
|
+
stretch={dropdownMatchSelectWidth ? 'width' : 'minWidth'}
|
|
265
|
+
zIndex={100}
|
|
266
|
+
builtinPlacements={{
|
|
267
|
+
left: {
|
|
268
|
+
points: ['cr', 'cl'],
|
|
269
|
+
},
|
|
270
|
+
right: {
|
|
271
|
+
points: ['cl', 'cr'],
|
|
272
|
+
},
|
|
273
|
+
top: {
|
|
274
|
+
points: ['bc', 'tc'],
|
|
275
|
+
},
|
|
276
|
+
bottom: {
|
|
277
|
+
points: ['tc', 'bc'],
|
|
278
|
+
},
|
|
279
|
+
topLeft: {
|
|
280
|
+
points: ['bl', 'tl'],
|
|
281
|
+
},
|
|
282
|
+
topRight: {
|
|
283
|
+
points: ['br', 'tr'],
|
|
284
|
+
},
|
|
285
|
+
bottomRight: {
|
|
286
|
+
points: ['tr', 'br'],
|
|
287
|
+
},
|
|
288
|
+
bottomLeft: {
|
|
289
|
+
points: ['tl', 'bl'],
|
|
290
|
+
},
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
<Selector
|
|
294
|
+
size={realSize}
|
|
295
|
+
input={input}
|
|
296
|
+
disabled={disabled}
|
|
297
|
+
prefix={prefix}
|
|
298
|
+
multiple={multiple}
|
|
299
|
+
bordered
|
|
300
|
+
isFocused={isFocused}
|
|
301
|
+
className={className}
|
|
302
|
+
visible={visible}
|
|
303
|
+
label={label}
|
|
304
|
+
ref={selectorRef}
|
|
305
|
+
style={style}
|
|
306
|
+
allowClear={allowClear}
|
|
307
|
+
value={selectorValue}
|
|
308
|
+
filteredOptions={filteredOptions}
|
|
309
|
+
searchType="no-search"
|
|
310
|
+
placeholder={placeholder}
|
|
311
|
+
deleteValue={deleteValue}
|
|
312
|
+
onAllowClear={onAllowClearClick}
|
|
313
|
+
optionLabelRenderer={optionLabelRenderer}
|
|
314
|
+
getOptionByValue={getOptionByValue}
|
|
315
|
+
onInputChange={onInputChange}
|
|
316
|
+
/>
|
|
317
|
+
</Trigger>
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
// @ts-ignore
|
|
321
|
+
export default React.forwardRef(Select);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IOptGroupProps } from '../interface';
|
|
3
|
+
|
|
4
|
+
export interface IOptionGroupFC extends React.FC<IOptGroupProps> {
|
|
5
|
+
isSelectOptGroup: boolean;
|
|
6
|
+
}
|
|
7
|
+
const OptGroup: IOptionGroupFC = () => null;
|
|
8
|
+
OptGroup.isSelectOptGroup = true;
|
|
9
|
+
export default OptGroup;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isNull, noop } from 'lodash';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { IOption as Option, TMaybeArray as MaybeArray } from '../interface';
|
|
5
|
+
import { Tooltip, Checkbox } from 'antd';
|
|
6
|
+
import Icon from '../../Icon';
|
|
7
|
+
|
|
8
|
+
const FIRST_INDEX = 0;
|
|
9
|
+
const INVALID_INDEX = -1;
|
|
10
|
+
interface IGroupProps {
|
|
11
|
+
option: Option;
|
|
12
|
+
prefixCls: string;
|
|
13
|
+
groupStyle?: React.CSSProperties;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ITooltipProps {
|
|
17
|
+
render: JSX.Element & React.ReactNode;
|
|
18
|
+
getContainer?: (node: HTMLElement) => HTMLElement;
|
|
19
|
+
tooltip?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface IOptionProp {
|
|
23
|
+
option: Option;
|
|
24
|
+
selected: MaybeArray<string | number> | null | undefined;
|
|
25
|
+
prefixCls?: string;
|
|
26
|
+
labelRenderer: (option: Option, isGruop: false) => React.ReactNode;
|
|
27
|
+
onOptionClick?: (selectedValue: string | number) => void;
|
|
28
|
+
index: number;
|
|
29
|
+
|
|
30
|
+
optionStyle?: React.CSSProperties;
|
|
31
|
+
multiple?: boolean;
|
|
32
|
+
// children?: React.ReactNode;
|
|
33
|
+
activeIndex: number;
|
|
34
|
+
setActiveIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ================= RenderGroup =====================
|
|
38
|
+
const RenderGroup: React.ForwardRefRenderFunction<unknown, IGroupProps> = (props, ref) => {
|
|
39
|
+
const {
|
|
40
|
+
option: { value, label },
|
|
41
|
+
prefixCls,
|
|
42
|
+
groupStyle,
|
|
43
|
+
} = props;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div ref={ref as React.LegacyRef<HTMLDivElement>} className={`${prefixCls}-list-group`} style={groupStyle}>
|
|
47
|
+
{label !== undefined ? label : value}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
export const RenderLabelIcon = ({
|
|
52
|
+
isSelected = false,
|
|
53
|
+
multiple = false,
|
|
54
|
+
disabled = false,
|
|
55
|
+
prefixCls,
|
|
56
|
+
isIndeterminate = false
|
|
57
|
+
}: { isSelected: boolean, multiple: boolean, disabled?: boolean, prefixCls?: string, isIndeterminate?: boolean }) => {
|
|
58
|
+
if (multiple) {
|
|
59
|
+
return (
|
|
60
|
+
<div className={`${prefixCls}-list-option-icon`} key={`${String(isSelected)}`}>
|
|
61
|
+
<Checkbox
|
|
62
|
+
className={`${prefixCls}-list-option-icon-checkbox`}
|
|
63
|
+
checked={isSelected}
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
onChange={noop}
|
|
66
|
+
indeterminate={isIndeterminate}
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (isSelected) {
|
|
72
|
+
return (
|
|
73
|
+
<div className={`${prefixCls}-list-option-icon`} key={`${String(isSelected)}`}>
|
|
74
|
+
<Icon type="check" size={16} />
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
// ================= RenderOption =====================
|
|
81
|
+
const RenderOption: React.ForwardRefRenderFunction<unknown, IOptionProp> = (props, ref) => {
|
|
82
|
+
const {
|
|
83
|
+
option: { value, disabled, tooltip, groupValue, groupLabel, label, ...restOption },
|
|
84
|
+
selected,
|
|
85
|
+
onOptionClick,
|
|
86
|
+
labelRenderer,
|
|
87
|
+
prefixCls,
|
|
88
|
+
optionStyle,
|
|
89
|
+
multiple,
|
|
90
|
+
index,
|
|
91
|
+
activeIndex,
|
|
92
|
+
setActiveIndex,
|
|
93
|
+
} = props;
|
|
94
|
+
const isSelected = typeof selected === 'string' || typeof selected === 'number' || isNull(selected) || typeof selected === 'undefined'
|
|
95
|
+
? selected === value
|
|
96
|
+
: selected.includes(value);
|
|
97
|
+
const onClick = (e: React.MouseEvent) => {
|
|
98
|
+
onOptionClick?.(value);
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
};
|
|
101
|
+
const labelNode = labelRenderer(
|
|
102
|
+
{
|
|
103
|
+
value,
|
|
104
|
+
disabled,
|
|
105
|
+
tooltip,
|
|
106
|
+
groupValue,
|
|
107
|
+
groupLabel,
|
|
108
|
+
label,
|
|
109
|
+
...restOption,
|
|
110
|
+
},
|
|
111
|
+
false
|
|
112
|
+
);
|
|
113
|
+
return (
|
|
114
|
+
<div ref={ref as React.LegacyRef<HTMLDivElement>} className={`${prefixCls}-list-option-container`} style={optionStyle}>
|
|
115
|
+
<div
|
|
116
|
+
onMouseEnter={() => setActiveIndex(index)}
|
|
117
|
+
onMouseLeave={() => setActiveIndex(INVALID_INDEX)}
|
|
118
|
+
className={classnames(`${prefixCls}-list-option`, {
|
|
119
|
+
[`${prefixCls}-list-option-isSelected`]: isSelected,
|
|
120
|
+
[`${prefixCls}-list-option-isHover`]: !disabled && index === activeIndex,
|
|
121
|
+
[`${prefixCls}-list-option-disabled`]: disabled,
|
|
122
|
+
[`${prefixCls}-list-option-nomargin`]: index === FIRST_INDEX,
|
|
123
|
+
})}
|
|
124
|
+
onClick={disabled ? undefined : onClick}
|
|
125
|
+
onKeyDown={noop}
|
|
126
|
+
aria-hidden="true"
|
|
127
|
+
>
|
|
128
|
+
<RenderLabelIcon isSelected={isSelected} multiple={!!multiple} disabled={!!disabled} prefixCls={prefixCls} />
|
|
129
|
+
{labelNode}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// ================= RenderTooltip =====================
|
|
136
|
+
const RenderTooltip: React.ForwardRefRenderFunction<unknown, ITooltipProps> = (props, ref) => {
|
|
137
|
+
const { tooltip, render, getContainer } = props;
|
|
138
|
+
if (tooltip) {
|
|
139
|
+
return (
|
|
140
|
+
<div ref={ref as React.LegacyRef<HTMLDivElement>}>
|
|
141
|
+
<Tooltip title={tooltip} destroyTooltipOnHide placement="right" getTooltipContainer={getContainer}>
|
|
142
|
+
<div>{render}</div>
|
|
143
|
+
</Tooltip>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return <div ref={ref as React.LegacyRef<HTMLDivElement>}>{render}</div>;
|
|
148
|
+
};
|
|
149
|
+
export const ForwardRenderGroup = React.forwardRef(RenderGroup);
|
|
150
|
+
export const ForwardRenderOption = React.forwardRef(RenderOption);
|
|
151
|
+
export const ForwardRenderTooltip = React.forwardRef(RenderTooltip);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IOptionProps } from '../interface';
|
|
3
|
+
|
|
4
|
+
export interface IOptionFC extends React.FC<IOptionProps> {
|
|
5
|
+
isSelectOption: boolean;
|
|
6
|
+
}
|
|
7
|
+
const Option: IOptionFC = () => null;
|
|
8
|
+
|
|
9
|
+
Option.isSelectOption = true;
|
|
10
|
+
|
|
11
|
+
export default Option;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
import React, { LegacyRef, useCallback, useImperativeHandle, useMemo, useRef, useEffect } from 'react';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { ListRef } from 'rc-virtual-list';
|
|
5
|
+
import VirtualList from '../VirtualList';
|
|
6
|
+
import { IOptionsListProps, IOption } from '../interface';
|
|
7
|
+
import { ForwardRenderGroup, ForwardRenderOption, ForwardRenderTooltip, RenderLabelIcon } from './OptionItem';
|
|
8
|
+
|
|
9
|
+
const ZERO_LENGTH = 0;
|
|
10
|
+
const DEFAULT_ACTIVE_INDEX = -1;
|
|
11
|
+
const OptionsList: React.ForwardRefRenderFunction<unknown, IOptionsListProps> = (props, ref) => {
|
|
12
|
+
const {
|
|
13
|
+
input,
|
|
14
|
+
prefixCls,
|
|
15
|
+
data,
|
|
16
|
+
groupStyle,
|
|
17
|
+
height,
|
|
18
|
+
itemHeight,
|
|
19
|
+
selected,
|
|
20
|
+
optionChecked,
|
|
21
|
+
// searchType,
|
|
22
|
+
tempValue,
|
|
23
|
+
value,
|
|
24
|
+
placeholder,
|
|
25
|
+
notFoundContent,
|
|
26
|
+
onValueChange,
|
|
27
|
+
onTempValueChange,
|
|
28
|
+
setTempValue,
|
|
29
|
+
onInputChange,
|
|
30
|
+
onOptionClick,
|
|
31
|
+
activeIndex,
|
|
32
|
+
multiple,
|
|
33
|
+
visible,
|
|
34
|
+
style,
|
|
35
|
+
setActiveIndex,
|
|
36
|
+
...restProps
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const selectAllRef = useRef(null);
|
|
40
|
+
const OptionListRef = useRef<HTMLDivElement>(null);
|
|
41
|
+
const VirtualListRef = useRef<ListRef>(null);
|
|
42
|
+
useImperativeHandle(ref, () => ({
|
|
43
|
+
onConfirm: () => {
|
|
44
|
+
onConfirm();
|
|
45
|
+
},
|
|
46
|
+
onCancel: () => {
|
|
47
|
+
onCancel();
|
|
48
|
+
},
|
|
49
|
+
onFocus: () => {
|
|
50
|
+
OptionListRef?.current?.focus();
|
|
51
|
+
},
|
|
52
|
+
onBlur: () => {
|
|
53
|
+
OptionListRef?.current?.blur();
|
|
54
|
+
},
|
|
55
|
+
scrollIntoView: (index: number, offset?: number) => {
|
|
56
|
+
scrollIntoView(index, offset);
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
const filterflattenOptions = useMemo(
|
|
60
|
+
() => data.filter((filterOption: IOption) => !filterOption.isSelectOptGroup),
|
|
61
|
+
[data]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// 有选中值
|
|
65
|
+
const isChecked = useMemo(() => (selected as [])?.length >= 1, [selected]);
|
|
66
|
+
// 部分选中
|
|
67
|
+
// 全部列表选项选中
|
|
68
|
+
const isAllChecked = isChecked && (selected as [])?.length === filterflattenOptions?.length;
|
|
69
|
+
// ”全部“选项是否选中
|
|
70
|
+
const allOptionChecked = isAllChecked && (Array.isArray(optionChecked) && optionChecked.length === ZERO_LENGTH);
|
|
71
|
+
// 点击全选
|
|
72
|
+
const onAllClick = useCallback(() => {
|
|
73
|
+
onValueChange?.(
|
|
74
|
+
allOptionChecked
|
|
75
|
+
? null
|
|
76
|
+
: filterflattenOptions.reduce((prev: Array<number | string>, curr: IOption) => [...prev, curr.value], [])
|
|
77
|
+
);
|
|
78
|
+
}, [allOptionChecked, filterflattenOptions, onValueChange]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!visible && !allOptionChecked && multiple && Array.isArray(selected) && selected.length === filterflattenOptions?.length) {
|
|
81
|
+
onAllClick();
|
|
82
|
+
}
|
|
83
|
+
}, [visible, selected, multiple, filterflattenOptions, onAllClick, allOptionChecked]);
|
|
84
|
+
const onSingleOptionClick = useCallback((selectedValue: string | number) => {
|
|
85
|
+
onOptionClick?.(selectedValue);
|
|
86
|
+
}, [onOptionClick]);
|
|
87
|
+
|
|
88
|
+
const onConfirm = useCallback(() => onTempValueChange(tempValue), [onTempValueChange, tempValue]);
|
|
89
|
+
const onCancel = useCallback(() => onTempValueChange([]), [onTempValueChange]);
|
|
90
|
+
|
|
91
|
+
const scrollIntoView = (index: number, offset?: number) => {
|
|
92
|
+
VirtualListRef?.current?.scrollTo({ index, offset });
|
|
93
|
+
};
|
|
94
|
+
// 渲染”全部“选项
|
|
95
|
+
const renderAllOptions = () => (
|
|
96
|
+
<div
|
|
97
|
+
ref={selectAllRef}
|
|
98
|
+
className={classnames(
|
|
99
|
+
`${prefixCls}-list-option-all`,
|
|
100
|
+
{ [`${prefixCls}-list-option-all-isSelected`]: isChecked }
|
|
101
|
+
)}
|
|
102
|
+
onClick={(e) => {
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
onAllClick();
|
|
105
|
+
}}
|
|
106
|
+
aria-hidden="true"
|
|
107
|
+
>
|
|
108
|
+
<RenderLabelIcon isSelected={allOptionChecked} multiple prefixCls={prefixCls} />
|
|
109
|
+
全部
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
return (
|
|
113
|
+
<div
|
|
114
|
+
className={`${prefixCls}-list`}
|
|
115
|
+
style={style}
|
|
116
|
+
ref={OptionListRef as LegacyRef<HTMLDivElement>}
|
|
117
|
+
role="list"
|
|
118
|
+
aria-hidden="true"
|
|
119
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
120
|
+
tabIndex={0}
|
|
121
|
+
onMouseLeave={() => setActiveIndex(DEFAULT_ACTIVE_INDEX)}
|
|
122
|
+
>
|
|
123
|
+
{/* {searchType === 'inner' && (
|
|
124
|
+
<div className={classnames(`${prefixCls}-list-search-bar`, {})}>
|
|
125
|
+
<SearchBar onChange={onInputChange} value={input} placeholder={placeholder} />
|
|
126
|
+
</div>
|
|
127
|
+
)} */}
|
|
128
|
+
{multiple && renderAllOptions()}
|
|
129
|
+
{data.length > ZERO_LENGTH ? (
|
|
130
|
+
<VirtualList
|
|
131
|
+
itemKey="key"
|
|
132
|
+
prefixCls={prefixCls}
|
|
133
|
+
ref={VirtualListRef}
|
|
134
|
+
data={data}
|
|
135
|
+
height={height}
|
|
136
|
+
itemHeight={itemHeight}
|
|
137
|
+
{...restProps}
|
|
138
|
+
>
|
|
139
|
+
{(option: IOption, index: number) => (option.isSelectOptGroup ? (
|
|
140
|
+
<ForwardRenderGroup option={option} prefixCls={prefixCls} groupStyle={groupStyle} />
|
|
141
|
+
) : (
|
|
142
|
+
<ForwardRenderTooltip
|
|
143
|
+
tooltip={option?.tooltip}
|
|
144
|
+
render={(
|
|
145
|
+
<ForwardRenderOption
|
|
146
|
+
option={option}
|
|
147
|
+
prefixCls={prefixCls}
|
|
148
|
+
selected={optionChecked}
|
|
149
|
+
index={index}
|
|
150
|
+
activeIndex={activeIndex}
|
|
151
|
+
multiple={multiple}
|
|
152
|
+
onOptionClick={onSingleOptionClick}
|
|
153
|
+
setActiveIndex={setActiveIndex}
|
|
154
|
+
{...restProps}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
/>
|
|
158
|
+
))}
|
|
159
|
+
</VirtualList>
|
|
160
|
+
) : (
|
|
161
|
+
notFoundContent
|
|
162
|
+
)}
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const ForwardRenderOptionList = React.forwardRef(OptionsList);
|
|
168
|
+
|
|
169
|
+
export default ForwardRenderOptionList;
|