@qsxy/element-plus-react 1.0.1 → 1.0.2
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/dist/Calendar/Calendar.js +12 -3
- package/dist/Calendar/Footer.js +4 -2
- package/dist/Calendar/QuarterPanel.d.ts +4 -0
- package/dist/Calendar/QuarterPanel.js +109 -0
- package/dist/Calendar/WeekPanel.js +1 -1
- package/dist/Calendar/typings.d.ts +1 -1
- package/dist/Card/Card.js +9 -4
- package/dist/Card/typings.d.ts +1 -1
- package/dist/Cascader/Cascader.js +1 -1
- package/dist/DatePicker/DatePicker.js +38 -12
- package/dist/DatePicker/DateRangePicker.js +27 -9
- package/dist/DatePicker/main.js +1 -1
- package/dist/DatePicker/typings.d.ts +1 -1
- package/dist/DateTimePicker/DateTimePicker.js +2 -2
- package/dist/Input/Input.1.d.ts +16 -0
- package/dist/Input/Input.1.js +376 -0
- package/dist/Input/Input.js +137 -121
- package/dist/Input/InputRange.js +1 -1
- package/dist/Input/TextArea.js +87 -12
- package/dist/Input/typings.d.ts +15 -5
- package/dist/Input/useComposition.d.ts +23 -0
- package/dist/Input/useComposition.js +63 -0
- package/dist/Input/utils.d.ts +6 -0
- package/dist/Input/utils.js +91 -0
- package/dist/InputNumber/InputNumber.js +1 -1
- package/dist/InputNumber/typings.d.ts +1 -1
- package/dist/Select/Option.js +30 -14
- package/dist/Select/SelectContext.d.ts +3 -4
- package/dist/Select/SelectCore.d.ts +2 -2
- package/dist/Select/SelectCore.js +164 -447
- package/dist/Select/SelectDropdown.js +67 -145
- package/dist/Select/typings.d.ts +47 -21
- package/dist/Select/useSelect.d.ts +125 -0
- package/dist/Select/useSelect.js +516 -0
- package/dist/Table/util.js +6 -5
- package/dist/Tag/Tag.js +22 -17
- package/dist/TimePicker/TimePicker.js +2 -2
- package/dist/TreeSelect/TreeSelect.js +2 -2
- package/dist/Util/aria.d.ts +25 -0
- package/dist/Util/aria.js +118 -0
- package/dist/hooks/useCalcInputWidth.d.ts +8 -0
- package/dist/hooks/useCalcInputWidth.js +30 -0
- package/dist/hooks/useComposition.d.ts +16 -0
- package/dist/hooks/useComposition.js +39 -0
- package/dist/hooks/useCursor.d.ts +2 -0
- package/dist/hooks/useCursor.js +52 -0
- package/dist/hooks/useFocusController.d.ts +27 -0
- package/dist/hooks/useFocusController.js +72 -0
- package/dist/index.css +1 -1
- package/dist/locale/en.d.ts +15 -0
- package/dist/locale/en.js +15 -0
- package/dist/locale/zhCn.d.ts +15 -0
- package/dist/locale/zhCn.js +15 -0
- package/package.json +1 -1
- package/theme-chalk/calendar/index.scss +1 -0
- package/theme-chalk/calendar/quarter-table.scss +78 -0
- package/theme-chalk/common/var.scss +1 -1
- package/theme-chalk/input/input.scss +424 -578
- package/theme-chalk/input/input.scss--bak +578 -0
- package/theme-chalk/select/index.scss +272 -247
- package/theme-chalk/select/index.scss--bak +247 -0
- package/theme-chalk/select/option-group.scss +2 -2
- package/theme-chalk/select/option.scss +2 -2
- package/theme-chalk/select/select-dropdown.scss +2 -2
- package/theme-chalk/tag.scss +181 -203
- package/theme-chalk/tag.scss--bak +203 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _templateObject
|
|
1
|
+
var _templateObject;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
3
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
4
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -7,21 +7,18 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
7
7
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
8
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
9
|
import classNames from 'classnames';
|
|
10
|
-
import trim from 'lodash/trim';
|
|
11
10
|
import React, { Children, cloneElement, forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
12
11
|
import { useTranslation } from 'react-i18next';
|
|
13
12
|
import { useConfigProvider } from "../ConfigProvider/ConfigProviderContext";
|
|
14
|
-
import { Divider } from "../Divider";
|
|
15
|
-
import Icon from "../Icon/Icon";
|
|
16
|
-
import Input from "../Input/Input";
|
|
17
13
|
import Scrollbar from "../Scrollbar/Scrollbar";
|
|
18
|
-
import {
|
|
14
|
+
import { isNotEmpty } from "../Util";
|
|
19
15
|
import { useClassNames } from "../hooks";
|
|
20
16
|
import Option from "./Option";
|
|
21
17
|
import { SelectContext } from "./SelectContext";
|
|
22
18
|
var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
23
19
|
var value = props.value,
|
|
24
20
|
filterable = props.filterable,
|
|
21
|
+
allowCreate = props.allowCreate,
|
|
25
22
|
_props$multiple = props.multiple,
|
|
26
23
|
multiple = _props$multiple === void 0 ? false : _props$multiple,
|
|
27
24
|
filterMethod = props.filterMethod,
|
|
@@ -29,22 +26,22 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
29
26
|
remote = _props$remote === void 0 ? false : _props$remote,
|
|
30
27
|
remoteMethod = props.remoteMethod,
|
|
31
28
|
loadingText = props.loadingText,
|
|
29
|
+
loadingIcon = props.loadingIcon,
|
|
32
30
|
noMatchText = props.noMatchText,
|
|
33
31
|
noDataText = props.noDataText,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
setCreateItem = props.setCreateItem,
|
|
37
|
-
createInputRef = props.createInputRef,
|
|
32
|
+
searchText = props.inputValue,
|
|
33
|
+
setInputValue = props.setInputValue,
|
|
38
34
|
onChoose = props.onChoose,
|
|
39
35
|
popperInstRef = props.popperInstRef,
|
|
40
|
-
contentRef = props.contentRef
|
|
36
|
+
contentRef = props.contentRef,
|
|
37
|
+
header = props.header,
|
|
38
|
+
footer = props.footer;
|
|
41
39
|
var _useClassNames = useClassNames('select'),
|
|
42
40
|
b = _useClassNames.b,
|
|
43
41
|
e = _useClassNames.e,
|
|
44
42
|
be = _useClassNames.be,
|
|
45
43
|
is = _useClassNames.is;
|
|
46
44
|
var ulRef = useRef(null);
|
|
47
|
-
var remoteSearchRef = useRef(null);
|
|
48
45
|
var _useConfigProvider = useConfigProvider(),
|
|
49
46
|
locale = _useConfigProvider.locale;
|
|
50
47
|
var _useTranslation = useTranslation(),
|
|
@@ -55,13 +52,6 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
55
52
|
_useState2 = _slicedToArray(_useState, 2),
|
|
56
53
|
hover = _useState2[0],
|
|
57
54
|
setHover = _useState2[1];
|
|
58
|
-
// 搜索关键词
|
|
59
|
-
var _useState3 = useState(''),
|
|
60
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
61
|
-
searchText = _useState4[0],
|
|
62
|
-
setSearchText = _useState4[1];
|
|
63
|
-
// const [remoteSearch, setRemoteSearch] = useState('');
|
|
64
|
-
// const remoteSearch = useMemo(() => searchInstance.current?.getValue(), [searchInstance]);
|
|
65
55
|
|
|
66
56
|
/** 搜索时 */
|
|
67
57
|
useEffect(function () {
|
|
@@ -69,30 +59,12 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
69
59
|
var _popperInstRef$curren;
|
|
70
60
|
(_popperInstRef$curren = popperInstRef.current) === null || _popperInstRef$curren === void 0 || _popperInstRef$curren.update();
|
|
71
61
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/** 清除搜索关键词 */
|
|
76
|
-
var onClearSearch = useCallback(function (event) {
|
|
77
|
-
event === null || event === void 0 || event.stopPropagation();
|
|
78
|
-
setSearchText('');
|
|
79
|
-
}, []);
|
|
80
|
-
|
|
81
|
-
/** 搜索 */
|
|
82
|
-
var onSearch = useCallback(function (val) {
|
|
83
|
-
var keywords = trim(val + '');
|
|
84
|
-
if (keywords === searchText) {
|
|
85
|
-
return;
|
|
86
|
-
} else if (isEmpty(keywords)) {
|
|
87
|
-
setSearchText('');
|
|
62
|
+
if (filterable && remote) {
|
|
63
|
+
remoteMethod === null || remoteMethod === void 0 || remoteMethod(searchText);
|
|
88
64
|
}
|
|
89
|
-
setSearchText(keywords);
|
|
90
|
-
}, [searchText]);
|
|
91
65
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
remoteMethod === null || remoteMethod === void 0 || remoteMethod(val);
|
|
95
|
-
}, [remoteMethod]);
|
|
66
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
+
}, [searchText]);
|
|
96
68
|
var filterAction = useCallback(function (p) {
|
|
97
69
|
if (isNotEmpty(searchText) && isNotEmpty(p.value)) {
|
|
98
70
|
if (filterMethod) {
|
|
@@ -100,9 +72,9 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
100
72
|
var filterResult = filterMethod((_p$label = p.label) !== null && _p$label !== void 0 ? _p$label : p.value.toString(), searchText);
|
|
101
73
|
return filterResult;
|
|
102
74
|
} else {
|
|
103
|
-
var _p$label2;
|
|
75
|
+
var _ref, _p$label2;
|
|
104
76
|
var regex = new RegExp(searchText, 'gi');
|
|
105
|
-
var res = null !== ((_p$label2 = p.label) !== null && _p$label2 !== void 0 ? _p$label2 : p.value
|
|
77
|
+
var res = null !== "".concat((_ref = (_p$label2 = p.label) !== null && _p$label2 !== void 0 ? _p$label2 : p.value) !== null && _ref !== void 0 ? _ref : '').match(regex);
|
|
106
78
|
return res;
|
|
107
79
|
}
|
|
108
80
|
} else {
|
|
@@ -128,40 +100,56 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
128
100
|
useImperativeHandle(ref, function () {
|
|
129
101
|
return {
|
|
130
102
|
clear: function clear() {
|
|
131
|
-
setSearchText('');
|
|
132
103
|
remoteMethod === null || remoteMethod === void 0 || remoteMethod('');
|
|
133
104
|
},
|
|
134
|
-
onEnter: function onEnter() {
|
|
135
|
-
setTimeout(function () {
|
|
136
|
-
var _searchInstance$curre, _remoteSearchRef$curr;
|
|
137
|
-
(_searchInstance$curre = searchInstance.current) === null || _searchInstance$curre === void 0 || _searchInstance$curre.focus();
|
|
138
|
-
(_remoteSearchRef$curr = remoteSearchRef.current) === null || _remoteSearchRef$curr === void 0 || _remoteSearchRef$curr.focus();
|
|
139
|
-
}, 500);
|
|
140
|
-
},
|
|
141
105
|
hover: setHover,
|
|
142
106
|
scrollToSelected: scrollToSelected
|
|
143
107
|
};
|
|
144
108
|
});
|
|
145
109
|
var loading = useMemo(function () {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
110
|
+
if (loadingIcon) {
|
|
111
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
112
|
+
className: be('dropdown', 'loading')
|
|
113
|
+
}, loadingIcon);
|
|
114
|
+
} else if (loadingText) {
|
|
115
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
116
|
+
className: be('dropdown', 'empty')
|
|
117
|
+
}, loadingText);
|
|
118
|
+
}
|
|
119
|
+
}, [be, loadingIcon, loadingText]);
|
|
151
120
|
var options = useMemo(function () {
|
|
121
|
+
// 正在创建新的选项
|
|
122
|
+
if (filterable && allowCreate && isNotEmpty(searchText)) {
|
|
123
|
+
// 单选时的创建项显示在下拉项里
|
|
124
|
+
if (!multiple && value === searchText) {
|
|
125
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, searchText && !multiple && /*#__PURE__*/React.createElement(Option, {
|
|
126
|
+
value: searchText,
|
|
127
|
+
label: searchText
|
|
128
|
+
}), props.children);
|
|
129
|
+
}
|
|
130
|
+
return /*#__PURE__*/React.createElement(Option, {
|
|
131
|
+
value: searchText,
|
|
132
|
+
label: searchText,
|
|
133
|
+
onClick: function onClick() {
|
|
134
|
+
if (multiple) {
|
|
135
|
+
setInputValue('');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
152
140
|
// 搜索
|
|
153
|
-
if (isNotEmpty(searchText)) {
|
|
141
|
+
if (filterable && !remote && isNotEmpty(searchText)) {
|
|
154
142
|
var match = false;
|
|
155
143
|
return props.children ? /*#__PURE__*/React.createElement(React.Fragment, null, Children.toArray(props.children).map(function (item) {
|
|
156
144
|
var _nodeType;
|
|
157
145
|
var nodeType = item === null || item === void 0 ? void 0 : item.type;
|
|
158
146
|
nodeType = ((_nodeType = nodeType) === null || _nodeType === void 0 ? void 0 : _nodeType.displayName) || nodeType;
|
|
159
|
-
if (nodeType === '
|
|
147
|
+
if (nodeType === 'ElOption') {
|
|
160
148
|
if (filterAction(item.props)) {
|
|
161
149
|
match = true;
|
|
162
150
|
return item;
|
|
163
151
|
}
|
|
164
|
-
} else if (nodeType === '
|
|
152
|
+
} else if (nodeType === 'ElOptionGroup') {
|
|
165
153
|
if (item.props.children) {
|
|
166
154
|
var matchChildren = Children.toArray(item.props.children).filter(function (item1) {
|
|
167
155
|
if (filterAction(item1.props)) {
|
|
@@ -179,104 +167,33 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
179
167
|
// match = true;
|
|
180
168
|
// return item;
|
|
181
169
|
// }
|
|
182
|
-
}), !match && /*#__PURE__*/React.createElement(
|
|
183
|
-
className:
|
|
184
|
-
value: "",
|
|
185
|
-
key: 'noMatchText'
|
|
170
|
+
}), !match && /*#__PURE__*/React.createElement("div", {
|
|
171
|
+
className: be('dropdown', 'empty')
|
|
186
172
|
}, noMatchText)) : null;
|
|
187
|
-
}
|
|
188
|
-
// 正在创建新的选项
|
|
189
|
-
else if (isNotEmpty(createItem)) {
|
|
190
|
-
// 单选时的创建项显示在下拉项里
|
|
191
|
-
if (!multiple && value === createItem) {
|
|
192
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, createItem && !multiple && /*#__PURE__*/React.createElement(Option, {
|
|
193
|
-
value: createItem,
|
|
194
|
-
label: createItem
|
|
195
|
-
}), props.children);
|
|
196
|
-
}
|
|
197
|
-
return /*#__PURE__*/React.createElement(Option, {
|
|
198
|
-
value: createItem,
|
|
199
|
-
label: createItem,
|
|
200
|
-
onClick: function onClick() {
|
|
201
|
-
if (multiple) {
|
|
202
|
-
setCreateItem('');
|
|
203
|
-
if (createInputRef.current) {
|
|
204
|
-
createInputRef.current.value = '';
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
173
|
} else {
|
|
210
174
|
if (Children.count(props.children) > 0) {
|
|
211
175
|
return props.children;
|
|
212
176
|
} else {
|
|
213
|
-
return /*#__PURE__*/React.createElement(
|
|
214
|
-
className:
|
|
215
|
-
|
|
216
|
-
}, noDataText);
|
|
177
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
178
|
+
className: be('dropdown', 'empty')
|
|
179
|
+
}, remote ? noMatchText : noDataText);
|
|
217
180
|
}
|
|
218
181
|
}
|
|
219
|
-
}, [searchText,
|
|
182
|
+
}, [filterable, allowCreate, searchText, remote, multiple, value, props.children, setInputValue, noMatchText, filterAction, be, noDataText]);
|
|
220
183
|
return /*#__PURE__*/React.createElement("div", {
|
|
221
184
|
className: classNames(b(_templateObject || (_templateObject = _taggedTemplateLiteral(["dorpdown"]))), is({
|
|
222
185
|
multiple: multiple
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
ref: contentRef
|
|
228
|
-
}, /*#__PURE__*/React.createElement(React.Fragment, null, filterable && !remote ? /*#__PURE__*/React.createElement("div", {
|
|
229
|
-
className: e(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["search"]))),
|
|
230
|
-
onClick: function onClick(event) {
|
|
231
|
-
return event.stopPropagation();
|
|
232
|
-
}
|
|
233
|
-
}, /*#__PURE__*/React.createElement(Input, {
|
|
234
|
-
ref: searchInstance,
|
|
235
|
-
placeholder: t('el.select.search', {
|
|
236
|
-
lng: locale
|
|
186
|
+
}), {
|
|
187
|
+
'custom-header': header,
|
|
188
|
+
'custom-footer': footer
|
|
237
189
|
}),
|
|
238
|
-
clearable: true,
|
|
239
|
-
plain: true
|
|
240
|
-
// debounceInput
|
|
241
|
-
,
|
|
242
|
-
onClear: onClearSearch,
|
|
243
|
-
onChange: onSearch,
|
|
244
|
-
prefix: /*#__PURE__*/React.createElement(Icon, {
|
|
245
|
-
prefix: "fal",
|
|
246
|
-
name: "search"
|
|
247
|
-
})
|
|
248
|
-
}), /*#__PURE__*/React.createElement(Divider, {
|
|
249
|
-
style: {
|
|
250
|
-
margin: 0
|
|
251
|
-
}
|
|
252
|
-
})) : null, filterable && remote ? /*#__PURE__*/React.createElement("div", {
|
|
253
|
-
className: e(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["search"]))),
|
|
254
190
|
onClick: function onClick(event) {
|
|
255
191
|
return event.stopPropagation();
|
|
256
|
-
}
|
|
257
|
-
}, /*#__PURE__*/React.createElement(Input, {
|
|
258
|
-
ref: remoteSearchRef
|
|
259
|
-
// value={remoteSearch}
|
|
260
|
-
,
|
|
261
|
-
placeholder: t('el.select.search', {
|
|
262
|
-
lng: locale
|
|
263
|
-
}),
|
|
264
|
-
clearable: true,
|
|
265
|
-
plain: true,
|
|
266
|
-
debounceInput: true,
|
|
267
|
-
onClear: function onClear() {
|
|
268
|
-
return onRemote('');
|
|
269
192
|
},
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
})
|
|
275
|
-
}), /*#__PURE__*/React.createElement(Divider, {
|
|
276
|
-
style: {
|
|
277
|
-
margin: 0
|
|
278
|
-
}
|
|
279
|
-
})) : null, /*#__PURE__*/React.createElement(SelectContext.Provider, {
|
|
193
|
+
ref: contentRef
|
|
194
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, header ? /*#__PURE__*/React.createElement("div", {
|
|
195
|
+
className: be('dropdown', 'header')
|
|
196
|
+
}, header) : null, /*#__PURE__*/React.createElement(SelectContext.Provider, {
|
|
280
197
|
value: {
|
|
281
198
|
value: value,
|
|
282
199
|
onChoose: onChoose,
|
|
@@ -285,10 +202,15 @@ var SelectDropdown = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
285
202
|
multiple: multiple
|
|
286
203
|
}
|
|
287
204
|
}, /*#__PURE__*/React.createElement(Scrollbar, {
|
|
288
|
-
wrapClass: be('dropdown', 'wrap')
|
|
205
|
+
wrapClass: be('dropdown', 'wrap'),
|
|
206
|
+
wrapStyle: {
|
|
207
|
+
display: props.loading ? 'none' : undefined
|
|
208
|
+
}
|
|
289
209
|
}, /*#__PURE__*/React.createElement("ul", {
|
|
290
210
|
className: be('dropdown', 'list'),
|
|
291
211
|
ref: ulRef
|
|
292
|
-
}, props.loading ? loading :
|
|
212
|
+
}, options)), props.loading ? loading : null), footer ? /*#__PURE__*/React.createElement("div", {
|
|
213
|
+
className: be('dropdown', 'footer')
|
|
214
|
+
}, footer) : null));
|
|
293
215
|
});
|
|
294
216
|
export default SelectDropdown;
|
package/dist/Select/typings.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { IconName } from '../Icon';
|
|
3
3
|
import { PopperOptionRef, PopperOptions } from '../Popper';
|
|
4
4
|
import { AnimationEventProps, BaseProps, FormControlBaseProps, NativeProps, TypeAttributes } from '../types/common';
|
|
5
|
-
export type
|
|
5
|
+
export type OptionValue = string | number | boolean;
|
|
6
|
+
export type ValueType = OptionValue | OptionValue[];
|
|
6
7
|
export type SelectRef = {
|
|
7
|
-
inputInstance?: RefObject<InputRef>;
|
|
8
|
-
searchInstance?: RefObject<InputRef>;
|
|
9
8
|
popperInstRef: RefObject<PopperOptionRef>;
|
|
10
|
-
selectedLabel: string | string[];
|
|
11
|
-
setLabel: (label: string) => void;
|
|
12
9
|
getValue: () => ValueType;
|
|
13
10
|
setValue: (value: ValueType) => void;
|
|
14
11
|
onClear: (event?: any) => void;
|
|
@@ -24,6 +21,8 @@ export interface SelectProps<V = ValueType> extends Omit<FormControlBaseProps<V>
|
|
|
24
21
|
valueKey?: string;
|
|
25
22
|
/** 是否可以清空选项 */
|
|
26
23
|
clearable?: boolean;
|
|
24
|
+
/** 自定义清除图标 */
|
|
25
|
+
clearIcon?: IconName;
|
|
27
26
|
/** 占位符 */
|
|
28
27
|
placeholder?: string;
|
|
29
28
|
/** 是否可搜索 */
|
|
@@ -31,13 +30,15 @@ export interface SelectProps<V = ValueType> extends Omit<FormControlBaseProps<V>
|
|
|
31
30
|
/** 自定义搜索方法 */
|
|
32
31
|
filterMethod?: (val: ValueType, searchText: string) => boolean;
|
|
33
32
|
/** 选项为空时显示的文字 */
|
|
34
|
-
noDataText?:
|
|
33
|
+
noDataText?: string;
|
|
35
34
|
/** 搜索条件无匹配时显示的文字 */
|
|
36
|
-
noMatchText?:
|
|
35
|
+
noMatchText?: string;
|
|
37
36
|
/** 是否正在从远程获取数据 */
|
|
38
37
|
loading?: boolean;
|
|
39
38
|
/** 远程加载时显示的文字 */
|
|
40
|
-
loadingText?:
|
|
39
|
+
loadingText?: string;
|
|
40
|
+
/** 远程加载时显示的图标 */
|
|
41
|
+
loadingIcon?: React.ReactElement;
|
|
41
42
|
/** */
|
|
42
43
|
max?: boolean;
|
|
43
44
|
/** 下拉菜单的内容是否有箭头 */
|
|
@@ -74,29 +75,53 @@ export interface SelectProps<V = ValueType> extends Omit<FormControlBaseProps<V>
|
|
|
74
75
|
remote?: boolean;
|
|
75
76
|
/** 自定义搜索方法 */
|
|
76
77
|
remoteMethod?: (searchText: string) => void;
|
|
78
|
+
/** 远程搜索方法显示后缀图标 */
|
|
79
|
+
remoteShowSuffix?: boolean;
|
|
80
|
+
/** 自定义后缀图标组件 */
|
|
81
|
+
suffixIcon?: IconName;
|
|
77
82
|
/** 标签类型 */
|
|
78
83
|
tagType?: TypeAttributes.Appearance;
|
|
79
84
|
/** 标签效果 */
|
|
80
85
|
tagEffect?: 'light' | 'dark' | 'plain';
|
|
86
|
+
labelFormat?: (index: number, value: OptionValue, label?: OptionValue) => React.ReactElement;
|
|
81
87
|
/** 选中值发生变化时触发 */
|
|
82
|
-
onChange?: (value: ValueType,
|
|
88
|
+
onChange?: (value: ValueType, data?: OptionData | OptionData[]) => void;
|
|
83
89
|
/** 下拉框出现/隐藏时触发 */
|
|
84
90
|
onVisibleChange?: (visible: boolean) => void;
|
|
85
91
|
/** 多选模式下移除tag时触发/隐藏时触发 */
|
|
86
92
|
onRemoveTag?: (tagValue: any) => void;
|
|
87
93
|
/** 可清空的单选模式下用户点击清空按钮时触发 */
|
|
88
94
|
onClear?: () => void;
|
|
89
|
-
/**
|
|
90
|
-
|
|
95
|
+
/** 对于不可搜索的 Select,是否在输入框获得焦点后自动弹出选项菜单 */
|
|
96
|
+
automaticDropdown?: boolean;
|
|
97
|
+
/** 下拉列表顶部的内容 */
|
|
98
|
+
header?: React.ReactElement;
|
|
99
|
+
/** 下拉列表底部的内容 */
|
|
100
|
+
footer?: React.ReactElement;
|
|
101
|
+
/** 作为 Select 组件的内容时 */
|
|
102
|
+
tag?: (params: {
|
|
103
|
+
data: OptionData[];
|
|
104
|
+
selectDisabled: boolean;
|
|
105
|
+
deleteTag: (event: React.MouseEvent<HTMLElement, MouseEvent>, tag: OptionData) => void;
|
|
106
|
+
}) => React.ReactElement;
|
|
91
107
|
}
|
|
92
108
|
export interface SelectOptionProps extends BaseProps, NativeProps {
|
|
93
109
|
/** 选项的值 */
|
|
94
|
-
value:
|
|
110
|
+
value: OptionValue;
|
|
95
111
|
/** 选项的标签,若不设置则默认与 value 相同 */
|
|
96
|
-
label?:
|
|
112
|
+
label?: OptionValue;
|
|
113
|
+
/** option 的附加数据,会传递到 onClick 事件的参数 data 中 */
|
|
114
|
+
data?: any;
|
|
97
115
|
/** 是否禁用该选项 */
|
|
98
116
|
disabled?: boolean;
|
|
99
|
-
onClick?: (value: ValueType,
|
|
117
|
+
onClick?: (value: ValueType, data: OptionData) => void;
|
|
118
|
+
}
|
|
119
|
+
export interface OptionData {
|
|
120
|
+
index?: number;
|
|
121
|
+
value: OptionValue;
|
|
122
|
+
label: OptionValue;
|
|
123
|
+
disabled?: boolean;
|
|
124
|
+
data?: any;
|
|
100
125
|
}
|
|
101
126
|
export interface SelectOptionGroupProps extends BaseProps<React.ReactElement<SelectOptionProps> | React.ReactElement<SelectOptionProps>[]>, NativeProps {
|
|
102
127
|
/** 分组的组名 */
|
|
@@ -106,17 +131,18 @@ export interface SelectOptionGroupProps extends BaseProps<React.ReactElement<Sel
|
|
|
106
131
|
}
|
|
107
132
|
export interface SelectDropdownProps extends SelectProps {
|
|
108
133
|
value: ValueType;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
onChoose: (val: string, text: string, event: any) => void;
|
|
134
|
+
inputValue: string;
|
|
135
|
+
setInputValue: (value: string) => void;
|
|
136
|
+
onChoose: (val: string, data: OptionData, event: any) => void;
|
|
113
137
|
contentRef: RefObject<HTMLDivElement>;
|
|
114
|
-
createInputRef: RefObject<HTMLInputElement>;
|
|
115
138
|
popperInstRef: RefObject<PopperOptionRef>;
|
|
139
|
+
/** 下拉列表顶部的内容 */
|
|
140
|
+
header?: React.ReactElement;
|
|
141
|
+
/** 下拉列表底部的内容 */
|
|
142
|
+
footer?: React.ReactElement;
|
|
116
143
|
}
|
|
117
144
|
export interface SelectDropdownRef {
|
|
118
145
|
clear: () => void;
|
|
119
|
-
onEnter: () => void;
|
|
120
146
|
hover: (value: ValueType) => void;
|
|
121
147
|
scrollToSelected: () => void;
|
|
122
148
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PopperOptionRef } from '../Popper/typings';
|
|
3
|
+
import { TooltipRef } from '../Tooltip/typings';
|
|
4
|
+
import { OptionData, OptionValue, SelectDropdownRef, SelectOptionGroupProps, SelectOptionProps, SelectProps, ValueType } from './typings';
|
|
5
|
+
declare const useSelect: (props: SelectProps) => {
|
|
6
|
+
nsSelect: {
|
|
7
|
+
wb: (...classes: import("../hooks/useClassNames").ClassValue[]) => string;
|
|
8
|
+
b: (...classes: import("../hooks/useClassNames").ClassValue[]) => string;
|
|
9
|
+
e: (...classes: import("../hooks/useClassNames").ClassValue[]) => string;
|
|
10
|
+
m: (...classes: import("../hooks/useClassNames").ClassValue[]) => string;
|
|
11
|
+
be: (prefix: string, sub: string, compName?: boolean) => string;
|
|
12
|
+
em: (sub: string, modifier: string, compName?: boolean) => string;
|
|
13
|
+
bm: (prefix: string, modifier: string, compName?: boolean) => string;
|
|
14
|
+
bem: (prefix: string, sub: string, modifier: string, compName?: boolean) => string;
|
|
15
|
+
ebm: (sub: string, prefix: string, modifier: string, compName?: boolean) => string;
|
|
16
|
+
is: (...classes: import("../hooks/useClassNames").ClassValue[]) => string;
|
|
17
|
+
cssVarBlock: (object: Record<string, string>) => Record<string, string>;
|
|
18
|
+
cssVarBlockName: (name: string) => string;
|
|
19
|
+
cssVarName: (name: string) => string;
|
|
20
|
+
};
|
|
21
|
+
containerRef: React.MutableRefObject<HTMLDivElement>;
|
|
22
|
+
contentRef: React.MutableRefObject<HTMLDivElement>;
|
|
23
|
+
wrapperRef: React.MutableRefObject<HTMLInputElement>;
|
|
24
|
+
popperInstRef: React.MutableRefObject<PopperOptionRef>;
|
|
25
|
+
selectDropdownRef: React.MutableRefObject<SelectDropdownRef>;
|
|
26
|
+
tagTooltipRef: React.MutableRefObject<TooltipRef>;
|
|
27
|
+
inputRef: React.MutableRefObject<HTMLInputElement>;
|
|
28
|
+
suffixWrapperRef: React.MutableRefObject<HTMLDivElement>;
|
|
29
|
+
inputValue: string;
|
|
30
|
+
setInputHovering: (hovering: boolean) => void;
|
|
31
|
+
setInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
32
|
+
setIsFocused: (focused: boolean) => void;
|
|
33
|
+
filterable: boolean;
|
|
34
|
+
clearable: boolean;
|
|
35
|
+
clearIcon: import("..").IconName;
|
|
36
|
+
multiple: boolean;
|
|
37
|
+
onChange: (value: ValueType, data?: OptionData | OptionData[]) => void;
|
|
38
|
+
allowCreate: boolean;
|
|
39
|
+
onEnter: (node?: HTMLElement | Text) => void;
|
|
40
|
+
afterLeave: (node?: HTMLElement | Text) => void;
|
|
41
|
+
onVisibleChange: (visible: boolean) => void;
|
|
42
|
+
onRemoveTag: (tagValue: any) => void;
|
|
43
|
+
htmlInputProps: React.AllHTMLAttributes<any>;
|
|
44
|
+
transitionProps: import("..").TransitionProps;
|
|
45
|
+
popperProps: Partial<import("../Popper/typings").PopperProps>;
|
|
46
|
+
value: ValueType;
|
|
47
|
+
setValue: (value: ValueType) => void;
|
|
48
|
+
disabled: boolean;
|
|
49
|
+
size: import("..").TypeAttributes.Size;
|
|
50
|
+
optionData: OptionData[];
|
|
51
|
+
multiValue: OptionValue[];
|
|
52
|
+
multiOptionData: OptionData[];
|
|
53
|
+
selected: OptionData | OptionData[];
|
|
54
|
+
label: string;
|
|
55
|
+
visible: boolean;
|
|
56
|
+
setVisible: React.Dispatch<React.SetStateAction<boolean>>;
|
|
57
|
+
popperStyle: React.CSSProperties;
|
|
58
|
+
placeholder: string;
|
|
59
|
+
shouldShowPlaceholder: boolean;
|
|
60
|
+
handleEnter: (node: any) => void;
|
|
61
|
+
handleAfterLeave: (node?: any) => void;
|
|
62
|
+
toggleMenu: (event: React.MouseEvent<HTMLSpanElement>) => void;
|
|
63
|
+
onCloseTag: (event: React.MouseEvent<HTMLElement, MouseEvent>, item: OptionData) => void;
|
|
64
|
+
onClear: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
65
|
+
onChoose: (val: string, data: OptionData, event?: any) => void;
|
|
66
|
+
labelFormat: (index: number, value: OptionValue, label?: OptionValue) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
67
|
+
iconComponent: import("..").IconName;
|
|
68
|
+
iconReverse: string;
|
|
69
|
+
isComposing: React.MutableRefObject<boolean>;
|
|
70
|
+
remote: boolean;
|
|
71
|
+
handleCompositionStart: (event: React.CompositionEvent<HTMLInputElement>) => void;
|
|
72
|
+
handleCompositionUpdate: (event: React.CompositionEvent<HTMLInputElement>) => void;
|
|
73
|
+
handleCompositionEnd: (event: React.CompositionEvent<HTMLInputElement>) => void;
|
|
74
|
+
valueKey?: string;
|
|
75
|
+
filterMethod?: (val: ValueType, searchText: string) => boolean;
|
|
76
|
+
noDataText?: string;
|
|
77
|
+
noMatchText?: string;
|
|
78
|
+
loading?: boolean;
|
|
79
|
+
loadingText?: string;
|
|
80
|
+
loadingIcon?: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
81
|
+
max?: boolean;
|
|
82
|
+
showArrow?: boolean;
|
|
83
|
+
required?: boolean;
|
|
84
|
+
error?: boolean;
|
|
85
|
+
warning?: boolean;
|
|
86
|
+
maxWidth?: number;
|
|
87
|
+
collapseTags?: boolean;
|
|
88
|
+
maxCollapseTags?: number;
|
|
89
|
+
collapseTagsTooltip?: boolean;
|
|
90
|
+
collapseTips?: (collapseNum: number, total: number) => string;
|
|
91
|
+
plain?: boolean;
|
|
92
|
+
prepend?: string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
93
|
+
append?: string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
94
|
+
appendToBody?: boolean;
|
|
95
|
+
remoteMethod?: (searchText: string) => void;
|
|
96
|
+
tagType?: import("..").TypeAttributes.Appearance;
|
|
97
|
+
tagEffect?: "light" | "dark" | "plain";
|
|
98
|
+
automaticDropdown?: boolean;
|
|
99
|
+
header?: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
100
|
+
footer?: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
101
|
+
tag?: (params: {
|
|
102
|
+
data: OptionData[];
|
|
103
|
+
selectDisabled: boolean;
|
|
104
|
+
deleteTag: (event: React.MouseEvent<HTMLElement, MouseEvent>, tag: OptionData) => void;
|
|
105
|
+
}) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
106
|
+
name?: string;
|
|
107
|
+
readOnly?: boolean;
|
|
108
|
+
defaultValue?: ValueType;
|
|
109
|
+
classPrefix?: string;
|
|
110
|
+
children?: (React.ReactElement<SelectOptionGroupProps | SelectOptionProps, string | React.JSXElementConstructor<any>> | React.ReactElement<SelectOptionGroupProps | SelectOptionProps, string | React.JSXElementConstructor<any>>[]) | (React.ReactElement<SelectOptionGroupProps | SelectOptionProps, string | React.JSXElementConstructor<any>> | React.ReactElement<SelectOptionGroupProps | SelectOptionProps, string | React.JSXElementConstructor<any>>[])[];
|
|
111
|
+
className?: string;
|
|
112
|
+
style?: React.CSSProperties & Partial<Record<never, string>>;
|
|
113
|
+
beforeEnter?: (node?: HTMLElement | Text) => void;
|
|
114
|
+
afterEnter?: (node?: HTMLElement | Text) => void;
|
|
115
|
+
beforeLeave?: (node?: HTMLElement | Text) => void;
|
|
116
|
+
onLeave?: (node?: HTMLElement | Text) => void;
|
|
117
|
+
offset?: number;
|
|
118
|
+
placement?: import("@popperjs/core/lib/enums").Placement;
|
|
119
|
+
arrowOffset?: number;
|
|
120
|
+
popperClass?: string;
|
|
121
|
+
effect?: string;
|
|
122
|
+
popperOptions?: import("@popperjs/core/lib/types").Options;
|
|
123
|
+
fallbackPlacements?: import("@popperjs/core/lib/enums").Placement[] | ((placement?: import("@popperjs/core/lib/enums").Placement) => import("@popperjs/core/lib/enums").Placement[]);
|
|
124
|
+
};
|
|
125
|
+
export default useSelect;
|