@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,211 @@
|
|
|
1
|
+
import Icon from '../../Icon';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import { isEmpty, isNil } from 'lodash';
|
|
4
|
+
import React, { useRef, useState, useImperativeHandle, useMemo } from 'react';
|
|
5
|
+
import { Tooltip as ToolTip } from 'antd';
|
|
6
|
+
import { ISelectorProps as SelectorProps } from '../interface';
|
|
7
|
+
import OverFLow from 'rc-overflow';
|
|
8
|
+
|
|
9
|
+
const ZERO = 0;
|
|
10
|
+
const ICON_LARGE_SIZE = 20;
|
|
11
|
+
const ICON_SMALL_SIZE = 16;
|
|
12
|
+
type TSize = 'small' | 'default' | 'large';
|
|
13
|
+
const defaultArrowComponent = (prefix: string, size: TSize) => (
|
|
14
|
+
<Icon
|
|
15
|
+
className={`${prefix}-icon-arrow`}
|
|
16
|
+
size={size === 'large' ? ICON_LARGE_SIZE : ICON_SMALL_SIZE}
|
|
17
|
+
type="expand_more1"
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
const defaultCloseComponent = (prefix: string, size: TSize) => (
|
|
21
|
+
<Icon
|
|
22
|
+
className={`${prefix}-icon-close`}
|
|
23
|
+
size={size === 'large' ? ICON_LARGE_SIZE : ICON_SMALL_SIZE}
|
|
24
|
+
type="cancel"
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const Selector: React.ForwardRefRenderFunction<unknown, SelectorProps> = (props, ref) => {
|
|
29
|
+
const {
|
|
30
|
+
input,
|
|
31
|
+
disabled,
|
|
32
|
+
prefix,
|
|
33
|
+
size,
|
|
34
|
+
multiple,
|
|
35
|
+
bordered,
|
|
36
|
+
isFocused,
|
|
37
|
+
className,
|
|
38
|
+
visible,
|
|
39
|
+
style,
|
|
40
|
+
allowClear,
|
|
41
|
+
label,
|
|
42
|
+
mode,
|
|
43
|
+
value,
|
|
44
|
+
searchType,
|
|
45
|
+
arrowComponent,
|
|
46
|
+
closeComponent,
|
|
47
|
+
placeholder,
|
|
48
|
+
deleteValue,
|
|
49
|
+
optionLabelRenderer,
|
|
50
|
+
getOptionByValue,
|
|
51
|
+
onInputChange,
|
|
52
|
+
onAllowClear,
|
|
53
|
+
filteredOptions,
|
|
54
|
+
...rest
|
|
55
|
+
} = props;
|
|
56
|
+
|
|
57
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
58
|
+
const selectorRef = useRef<HTMLDivElement>(null);
|
|
59
|
+
const selectorAllRef = useRef<HTMLSpanElement>(null);
|
|
60
|
+
const selectValuesRef = useRef<HTMLDivElement>(null);
|
|
61
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
62
|
+
const isEmptyValue = useMemo(() => !isEmpty(value), [value]);
|
|
63
|
+
const showClose = allowClear && (isEmptyValue || input) && isHovered && !disabled;
|
|
64
|
+
useImperativeHandle(ref, () => ({
|
|
65
|
+
clientWidth: selectorRef?.current?.clientWidth,
|
|
66
|
+
focus: () => {
|
|
67
|
+
inputRef?.current?.focus();
|
|
68
|
+
},
|
|
69
|
+
blur: () => {
|
|
70
|
+
inputRef?.current?.blur();
|
|
71
|
+
},
|
|
72
|
+
onBlur: () => {
|
|
73
|
+
selectorRef?.current?.blur();
|
|
74
|
+
},
|
|
75
|
+
onFocus: () => {
|
|
76
|
+
selectorRef?.current?.focus();
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
const onMouseEnter = () => {
|
|
81
|
+
if (allowClear) {
|
|
82
|
+
setIsHovered(true);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const onMouseLeave = () => {
|
|
86
|
+
if (allowClear) {
|
|
87
|
+
setIsHovered(false);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const onAllClearClick = (e: React.MouseEvent<Element, MouseEvent>) => {
|
|
91
|
+
e.stopPropagation();
|
|
92
|
+
if (allowClear) {
|
|
93
|
+
onAllowClear();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// ========================== render =======================
|
|
98
|
+
const renderPlaceHolder = () => {
|
|
99
|
+
if (isEmpty(value) && !input && placeholder) {
|
|
100
|
+
return <div className={`${prefix}-item ${prefix}-placeholder`}>{placeholder}</div>;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const renderMultipleValue = () => {
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
const allValueLabel = (value as Array<string | number>)?.reduce((prev, curr) => {
|
|
108
|
+
const item = getOptionByValue(curr);
|
|
109
|
+
if (item) {
|
|
110
|
+
return [...prev, item?.title || item?.label];
|
|
111
|
+
}
|
|
112
|
+
return [...prev, curr];
|
|
113
|
+
}, []);
|
|
114
|
+
if (Array.isArray(value) && value.length === filteredOptions.length) {
|
|
115
|
+
return <span>全部</span>;
|
|
116
|
+
}
|
|
117
|
+
const renderItem = (valueItem: string | number) => {
|
|
118
|
+
return <span>{optionLabelRenderer(valueItem, getOptionByValue(valueItem))}</span>;
|
|
119
|
+
};
|
|
120
|
+
const renderRest = (valueItems: Array<string | number>) => {
|
|
121
|
+
return <span>等{valueItems.length}项</span>;
|
|
122
|
+
};
|
|
123
|
+
return !input && !isNil(value) ? (
|
|
124
|
+
<ToolTip
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
title={allValueLabel?.join(',')}
|
|
127
|
+
placement="bottom"
|
|
128
|
+
getTooltipContainer={() => selectorRef?.current?.parentElement || document.body}
|
|
129
|
+
>
|
|
130
|
+
<OverFLow
|
|
131
|
+
className={`${prefix}-item-all`}
|
|
132
|
+
prefixCls={`${prefix}-overflow`}
|
|
133
|
+
data={value as Array<string | number>}
|
|
134
|
+
renderItem={renderItem}
|
|
135
|
+
renderRest={renderRest}
|
|
136
|
+
maxCount="responsive"
|
|
137
|
+
/>
|
|
138
|
+
</ToolTip>
|
|
139
|
+
) : null;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const renderSingleValue = () => {
|
|
143
|
+
const text = optionLabelRenderer(
|
|
144
|
+
value as string | number,
|
|
145
|
+
getOptionByValue(value as string | number),
|
|
146
|
+
);
|
|
147
|
+
return !input && (typeof value === 'string' || typeof value === 'number') ? (
|
|
148
|
+
// <Text>
|
|
149
|
+
<div className={classnames(`${prefix}-item`)}>
|
|
150
|
+
<span ref={selectorAllRef} className={classnames(`${prefix}-item-text`)}>
|
|
151
|
+
{text}
|
|
152
|
+
</span>
|
|
153
|
+
</div>
|
|
154
|
+
) : // </Text>
|
|
155
|
+
null;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<div
|
|
160
|
+
role={disabled ? undefined : 'combobox'}
|
|
161
|
+
aria-expanded={visible}
|
|
162
|
+
aria-controls="expandable"
|
|
163
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
164
|
+
tabIndex={ZERO}
|
|
165
|
+
className={classnames(
|
|
166
|
+
`${prefix}`,
|
|
167
|
+
`${prefix}-${size}`,
|
|
168
|
+
{
|
|
169
|
+
[`${prefix}-single`]: !multiple,
|
|
170
|
+
[`${prefix}-bordered`]: bordered,
|
|
171
|
+
[`${prefix}-focused`]: isFocused,
|
|
172
|
+
[`${prefix}-disabled`]: disabled,
|
|
173
|
+
},
|
|
174
|
+
className,
|
|
175
|
+
)}
|
|
176
|
+
aria-disabled={disabled}
|
|
177
|
+
aria-hidden="true"
|
|
178
|
+
style={style}
|
|
179
|
+
ref={selectorRef}
|
|
180
|
+
{...rest}
|
|
181
|
+
>
|
|
182
|
+
<div
|
|
183
|
+
className={`${prefix}-selector-wrap`}
|
|
184
|
+
onMouseEnter={onMouseEnter}
|
|
185
|
+
onMouseLeave={onMouseLeave}
|
|
186
|
+
>
|
|
187
|
+
{label && <div className={`${prefix}-selector-label`}>{label}</div>}
|
|
188
|
+
<div className={`${prefix}-selector`}>
|
|
189
|
+
<div className={classnames(`${prefix}-values-wrapper`)} ref={selectValuesRef}>
|
|
190
|
+
{multiple ? renderMultipleValue() : renderSingleValue()}
|
|
191
|
+
{renderPlaceHolder()}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
<div
|
|
195
|
+
aria-hidden="true"
|
|
196
|
+
className={classnames(`${prefix}-arrow`, {
|
|
197
|
+
[`${prefix}-arrow-focused`]: visible,
|
|
198
|
+
})}
|
|
199
|
+
onClick={showClose ? onAllClearClick : undefined}
|
|
200
|
+
>
|
|
201
|
+
{showClose
|
|
202
|
+
? closeComponent || defaultCloseComponent(prefix, size)
|
|
203
|
+
: arrowComponent || defaultArrowComponent(prefix, size)}
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const ForwardSelector = React.forwardRef(Selector);
|
|
211
|
+
export default ForwardSelector;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import List, { ListRef, ListProps } from 'rc-virtual-list';
|
|
3
|
+
import { IOption } from './interface';
|
|
4
|
+
|
|
5
|
+
const defaultListRowHeight = 44;
|
|
6
|
+
const defaultListHeight = 520;
|
|
7
|
+
|
|
8
|
+
const VirtualList: React.ForwardRefRenderFunction<ListRef, ListProps<IOption>> = (props, ref) => {
|
|
9
|
+
const {
|
|
10
|
+
itemHeight = defaultListRowHeight,
|
|
11
|
+
height = defaultListHeight,
|
|
12
|
+
prefixCls,
|
|
13
|
+
children,
|
|
14
|
+
data,
|
|
15
|
+
virtual,
|
|
16
|
+
itemKey,
|
|
17
|
+
} = props;
|
|
18
|
+
return (
|
|
19
|
+
<List<IOption>
|
|
20
|
+
itemKey={itemKey}
|
|
21
|
+
ref={ref}
|
|
22
|
+
itemHeight={itemHeight}
|
|
23
|
+
height={height}
|
|
24
|
+
data={data}
|
|
25
|
+
virtual={virtual}
|
|
26
|
+
prefixCls={`${prefixCls}-virtual-list`}
|
|
27
|
+
fullHeight={false}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</List>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const RefVirtualList = React.forwardRef(VirtualList);
|
|
35
|
+
|
|
36
|
+
export default RefVirtualList;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// import { Select } from '@aloudata/aloudata-design';
|
|
3
|
+
import Select from '../../index'
|
|
4
|
+
const Option = Select.Option;
|
|
5
|
+
export default () => {
|
|
6
|
+
return (
|
|
7
|
+
<div className='ald-select-demo'>
|
|
8
|
+
|
|
9
|
+
<Select
|
|
10
|
+
className='ald-select'
|
|
11
|
+
style={{ width: 200 }}
|
|
12
|
+
size='large'
|
|
13
|
+
multiple
|
|
14
|
+
disabled
|
|
15
|
+
placeholder="large"
|
|
16
|
+
>
|
|
17
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
18
|
+
</Select>
|
|
19
|
+
<Select
|
|
20
|
+
className='ald-select'
|
|
21
|
+
style={{ width: 200 }}
|
|
22
|
+
multiple
|
|
23
|
+
label='Label:'
|
|
24
|
+
disabled
|
|
25
|
+
placeholder="placeholder"
|
|
26
|
+
>
|
|
27
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
28
|
+
</Select>
|
|
29
|
+
<Select
|
|
30
|
+
className='ald-select'
|
|
31
|
+
style={{ width: 200 }}
|
|
32
|
+
multiple
|
|
33
|
+
size="small"
|
|
34
|
+
label='Label:'
|
|
35
|
+
defaultValue={['a', 'b']}
|
|
36
|
+
disabled
|
|
37
|
+
placeholder="normal"
|
|
38
|
+
>
|
|
39
|
+
<Option key='a' value="a">Example Text</Option>
|
|
40
|
+
<Option key='b' value="b">Example Text</Option>
|
|
41
|
+
</Select>
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// import { Select } from '@aloudata/aloudata-design';
|
|
3
|
+
import Select from '../../index'
|
|
4
|
+
import Icon from '../../../Icon'
|
|
5
|
+
const Option = Select.Option;
|
|
6
|
+
export default () => {
|
|
7
|
+
const [value, setValue] = React.useState('');
|
|
8
|
+
const onChange = (value: string) => {
|
|
9
|
+
console.log(value);
|
|
10
|
+
setValue(value);
|
|
11
|
+
}
|
|
12
|
+
return (
|
|
13
|
+
<div className='ald-select-demo'>
|
|
14
|
+
<Select
|
|
15
|
+
className='ald-select'
|
|
16
|
+
style={{ width: 200 }}
|
|
17
|
+
size='large'
|
|
18
|
+
multiple
|
|
19
|
+
placeholder="large size"
|
|
20
|
+
>
|
|
21
|
+
<Option key='a' value="Example Text">Example TexExample TextExample TextExample TextExample TextExample Textt</Option>
|
|
22
|
+
<Option key='b' value="b">b</Option>
|
|
23
|
+
<Option key='c' value="c">c</Option>
|
|
24
|
+
<Option key='d' value="d">d</Option>
|
|
25
|
+
<Option key='e' value="e">e</Option>
|
|
26
|
+
<Option key="f" value="f">f</Option>
|
|
27
|
+
<Option key="g" value="g">g</Option>
|
|
28
|
+
</Select>
|
|
29
|
+
<Select
|
|
30
|
+
className='ald-select'
|
|
31
|
+
style={{ width: 200 }}
|
|
32
|
+
size='default'
|
|
33
|
+
label='Label:'
|
|
34
|
+
multiple
|
|
35
|
+
listHeight={100}
|
|
36
|
+
placeholder="default"
|
|
37
|
+
>
|
|
38
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
39
|
+
<Option key='b' value="b">b</Option>
|
|
40
|
+
<Option key='c' value="c">c</Option>
|
|
41
|
+
<Option key='d' value="d">d</Option>
|
|
42
|
+
<Option key='e' value="e">e</Option>
|
|
43
|
+
<Option key="f" value="f">f</Option>
|
|
44
|
+
<Option key="g" value="g">g</Option>
|
|
45
|
+
</Select>
|
|
46
|
+
<Select
|
|
47
|
+
className='ald-select'
|
|
48
|
+
style={{ width: 200 }}
|
|
49
|
+
size='small'
|
|
50
|
+
multiple
|
|
51
|
+
value={value}
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
onChange={(v)=>{onChange(v)}}
|
|
54
|
+
placeholder="small"
|
|
55
|
+
>
|
|
56
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
57
|
+
</Select>
|
|
58
|
+
<br/>
|
|
59
|
+
<Select
|
|
60
|
+
className='ald-select'
|
|
61
|
+
style={{ width: 200 }}
|
|
62
|
+
size='large'
|
|
63
|
+
multiple
|
|
64
|
+
label={<Icon type='view_Partial_line' />}
|
|
65
|
+
placeholder="large size"
|
|
66
|
+
>
|
|
67
|
+
<Option key='a' value="Example Text">Example TexExample TextExample TextExample TextExample TextExample Textt</Option>
|
|
68
|
+
<Option key='b' value="b">b</Option>
|
|
69
|
+
<Option key='c' value="c">c</Option>
|
|
70
|
+
<Option key='d' value="d">d</Option>
|
|
71
|
+
<Option key='e' value="e">e</Option>
|
|
72
|
+
<Option key="f" value="f">f</Option>
|
|
73
|
+
<Option key="g" value="g">g</Option>
|
|
74
|
+
</Select>
|
|
75
|
+
</div>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// import { Select } from '@aloudata/aloudata-design';
|
|
3
|
+
import Select from '../../index'
|
|
4
|
+
const Option = Select.Option;
|
|
5
|
+
export default () => {
|
|
6
|
+
return (
|
|
7
|
+
<div className='ald-select-demo'>
|
|
8
|
+
|
|
9
|
+
<Select
|
|
10
|
+
className='ald-select'
|
|
11
|
+
style={{ width: 200 }}
|
|
12
|
+
size='large'
|
|
13
|
+
multiple
|
|
14
|
+
placeholder="large"
|
|
15
|
+
options={[
|
|
16
|
+
{
|
|
17
|
+
label: 'Option 1',
|
|
18
|
+
value: 'Option 1'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: 'Option 2',
|
|
22
|
+
value: 'Option 2'
|
|
23
|
+
}
|
|
24
|
+
]}
|
|
25
|
+
/>
|
|
26
|
+
<Select
|
|
27
|
+
className='ald-select'
|
|
28
|
+
style={{ width: 200 }}
|
|
29
|
+
multiple
|
|
30
|
+
label='Label:'
|
|
31
|
+
placeholder="placeholder"
|
|
32
|
+
options={[
|
|
33
|
+
{
|
|
34
|
+
label: 'Option 1',
|
|
35
|
+
value: 'Option 1'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Option 2',
|
|
39
|
+
value: 'Option 2'
|
|
40
|
+
}
|
|
41
|
+
]}
|
|
42
|
+
/>
|
|
43
|
+
<Select
|
|
44
|
+
className='ald-select'
|
|
45
|
+
style={{ width: 200 }}
|
|
46
|
+
multiple
|
|
47
|
+
size="small"
|
|
48
|
+
label='Label:'
|
|
49
|
+
placeholder="normal"
|
|
50
|
+
options={[
|
|
51
|
+
{
|
|
52
|
+
label: 'Option 1',
|
|
53
|
+
value: 'Option 1'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
label: 'Option 2',
|
|
57
|
+
value: 'Option 2'
|
|
58
|
+
}
|
|
59
|
+
]}
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// import { Select } from '@aloudata/aloudata-design';
|
|
3
|
+
import Select from '../../index'
|
|
4
|
+
const Option = Select.Option;
|
|
5
|
+
export default () => {
|
|
6
|
+
const [value, setValue] = React.useState('');
|
|
7
|
+
const onChange = (value: string) => {
|
|
8
|
+
console.log(value);
|
|
9
|
+
setValue(value);
|
|
10
|
+
}
|
|
11
|
+
return (
|
|
12
|
+
<div className='ald-select-demo'>
|
|
13
|
+
<Select
|
|
14
|
+
className='ald-select'
|
|
15
|
+
style={{ width: 200 }}
|
|
16
|
+
size='large'
|
|
17
|
+
allowClear
|
|
18
|
+
placeholder="large size"
|
|
19
|
+
>
|
|
20
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
21
|
+
<Option key='b' value="b">Menu item</Option>
|
|
22
|
+
<Option key='c' value="c">c</Option>
|
|
23
|
+
<Option key='d' value="d">d</Option>
|
|
24
|
+
<Option key='e' value="e">e</Option>
|
|
25
|
+
<Option key="f" value="f">f</Option>
|
|
26
|
+
<Option key="g" value="g">g</Option>
|
|
27
|
+
</Select>
|
|
28
|
+
<Select
|
|
29
|
+
className='ald-select'
|
|
30
|
+
style={{ width: 200 }}
|
|
31
|
+
size='default'
|
|
32
|
+
placeholder="default"
|
|
33
|
+
>
|
|
34
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
35
|
+
</Select>
|
|
36
|
+
<Select
|
|
37
|
+
className='ald-select'
|
|
38
|
+
style={{ width: 200 }}
|
|
39
|
+
size='small'
|
|
40
|
+
label='Label:'
|
|
41
|
+
placeholder="small"
|
|
42
|
+
value={value}
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
onChange={(v)=>{onChange(v)}}
|
|
45
|
+
>
|
|
46
|
+
<Option key='a' value="Example Text">Example Text</Option>
|
|
47
|
+
</Select>
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
|
+
import { TMaybeArray, IOption } from '../interface';
|
|
4
|
+
|
|
5
|
+
const optionSet = (map: Map<string | number, IOption>, key: string | number, value: IOption) => {
|
|
6
|
+
map.set(key, value);
|
|
7
|
+
};
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const groupOptionSet = (map: Map<string | number, any>, key: string | number, option: IOption) => {
|
|
10
|
+
if (map.get(key)) {
|
|
11
|
+
const { options: groupOptions = new Map(), ...rest } = map.get(key);
|
|
12
|
+
map.set(key, {
|
|
13
|
+
options: groupOptions.set(option.value, option),
|
|
14
|
+
...rest,
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
map.set(key, {
|
|
18
|
+
label: option.groupLabel,
|
|
19
|
+
value: option.groupValue,
|
|
20
|
+
isSelectOptGroup: true,
|
|
21
|
+
options: new Map([[option.value, option]]),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
map.set(option.value, option);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default function useCacheOptions() {
|
|
28
|
+
const cacheOptions = useRef(new Map());
|
|
29
|
+
const cacheOptionsMap = cacheOptions.current;
|
|
30
|
+
const [isGroup, setIsGroup] = useState(false);
|
|
31
|
+
const setCacheOptions = (options: IOption[]) => {
|
|
32
|
+
if (!isGroup) {
|
|
33
|
+
options.forEach((option: IOption) => optionSet(cacheOptionsMap, option.value, option));
|
|
34
|
+
} else {
|
|
35
|
+
options.forEach((option: IOption) => groupOptionSet(cacheOptionsMap, option.groupValue as string | number, option));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const updateGroup = (value: boolean) => {
|
|
40
|
+
if (value !== isGroup) {
|
|
41
|
+
setIsGroup(value);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
// value to option || options
|
|
45
|
+
const getOptionByValue = useCallback(
|
|
46
|
+
(optValue: string | number): IOption => cacheOptionsMap.get(optValue),
|
|
47
|
+
[cacheOptionsMap]
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const getOptionsByValue = (optValue: TMaybeArray<string | number>): TMaybeArray<IOption> => (Array.isArray(optValue)
|
|
51
|
+
? optValue.reduce((prev: IOption[], v) => {
|
|
52
|
+
const op = getOptionByValue(v);
|
|
53
|
+
if (op) {
|
|
54
|
+
prev.push(op);
|
|
55
|
+
}
|
|
56
|
+
return prev;
|
|
57
|
+
}, [])
|
|
58
|
+
: getOptionByValue(optValue));
|
|
59
|
+
return {
|
|
60
|
+
setCacheOptions,
|
|
61
|
+
getOptionByValue,
|
|
62
|
+
getOptionsByValue,
|
|
63
|
+
updateGroup,
|
|
64
|
+
cacheOptionsMap,
|
|
65
|
+
hasGroup: isGroup,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
# nav:
|
|
3
|
+
# title: 组件
|
|
4
|
+
# path: /components
|
|
5
|
+
title: Select 选择器
|
|
6
|
+
group:
|
|
7
|
+
title: 组件
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Select 选择器
|
|
11
|
+
|
|
12
|
+
下拉选择器
|
|
13
|
+
|
|
14
|
+
## 代码演示
|
|
15
|
+
|
|
16
|
+
<code src="./demo/single/index.tsx" title="单项选择"/>
|
|
17
|
+
<code src="./demo/multiple/index.tsx" title="多项选择"/>
|
|
18
|
+
<code src="./demo/disabled/index.tsx" title="禁用" description="使用disabled={true}可以禁用下拉选择框"/>
|
|
19
|
+
<code src="./demo/options/index.tsx" title="options">
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
### Select
|
|
25
|
+
|
|
26
|
+
<API src="./BaseSelect.tsx" >
|
|
27
|
+
|
|
28
|
+
### Select.Option
|
|
29
|
+
TODO: 待补充
|
|
30
|
+
|
|
31
|
+
## 类型定义
|
|
32
|
+
```
|
|
33
|
+
type TMayBeArray<T> = T | T[];
|
|
34
|
+
|
|
35
|
+
interface IOption {
|
|
36
|
+
/**
|
|
37
|
+
列表单项主要文字
|
|
38
|
+
*/
|
|
39
|
+
label: string | React.ReactNode;
|
|
40
|
+
/**
|
|
41
|
+
作为列表的 `key` 来使用
|
|
42
|
+
*/
|
|
43
|
+
value: string | number;
|
|
44
|
+
/**
|
|
45
|
+
列表次要文字
|
|
46
|
+
*/
|
|
47
|
+
description?: string;
|
|
48
|
+
/**
|
|
49
|
+
是否禁用
|
|
50
|
+
*/
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 选中该 Option 后,Select 的 title
|
|
54
|
+
*/
|
|
55
|
+
title?: string;
|
|
56
|
+
/**
|
|
57
|
+
`tooltip` 描述
|
|
58
|
+
*/
|
|
59
|
+
tooltip?: string;
|
|
60
|
+
/**
|
|
61
|
+
分组的 `key` ,与 `groupLabel` 一起使用
|
|
62
|
+
*/
|
|
63
|
+
groupValue?: string;
|
|
64
|
+
/**
|
|
65
|
+
分组的标题
|
|
66
|
+
*/
|
|
67
|
+
groupLabel?: string;
|
|
68
|
+
|
|
69
|
+
options?: Map<string | number, IOption>;
|
|
70
|
+
isSelectOptGroup?: boolean;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import BaseSelect from './BaseSelect';
|
|
2
|
+
import { IOption as Option, ISelectProps as SelectProps, IOptGroupProps as OptGroupProps, IOptionProps as OptionProps } from './interface';
|
|
3
|
+
import Options from './OptionsList/Options';
|
|
4
|
+
import OptGroup from './OptionsList/OptGroup';
|
|
5
|
+
import './style';
|
|
6
|
+
|
|
7
|
+
export type TSelect = typeof BaseSelect & {
|
|
8
|
+
Group: typeof OptGroup;
|
|
9
|
+
Option: typeof Options;
|
|
10
|
+
};
|
|
11
|
+
const Select = BaseSelect as TSelect;
|
|
12
|
+
|
|
13
|
+
Select.Option = Options;
|
|
14
|
+
Select.Group = OptGroup;
|
|
15
|
+
export {
|
|
16
|
+
Options as Option,
|
|
17
|
+
OptGroup as Group,
|
|
18
|
+
SelectProps,
|
|
19
|
+
OptionProps,
|
|
20
|
+
Option as SelectOptions,
|
|
21
|
+
OptGroupProps as GroupProps,
|
|
22
|
+
};
|
|
23
|
+
export default Select;
|