@hi-ui/check-select 4.0.0-beta.3 → 4.0.0-beta.32
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/README.md +25 -25
- package/lib/cjs/CheckSelect.js +115 -73
- package/lib/cjs/context.js +0 -1
- package/lib/cjs/hooks/use-data.js +0 -1
- package/lib/cjs/hooks/use-flatten-data.js +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/styles/index.scss.js +2 -3
- package/lib/cjs/use-check-select.js +18 -17
- package/lib/esm/CheckSelect.js +100 -58
- package/lib/esm/context.js +0 -1
- package/lib/esm/hooks/use-data.js +0 -1
- package/lib/esm/hooks/use-flatten-data.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/styles/index.scss.js +3 -5
- package/lib/esm/use-check-select.js +19 -18
- package/lib/types/CheckSelect.d.ts +6 -10
- package/lib/types/context.d.ts +4 -2
- package/lib/types/types.d.ts +9 -7
- package/lib/types/use-check-select.d.ts +7 -7
- package/package.json +27 -27
- package/lib/cjs/CheckSelect.js.map +0 -1
- package/lib/cjs/context.js.map +0 -1
- package/lib/cjs/hooks/use-data.js.map +0 -1
- package/lib/cjs/hooks/use-flatten-data.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/styles/index.scss.js.map +0 -1
- package/lib/cjs/use-check-select.js.map +0 -1
- package/lib/esm/CheckSelect.js.map +0 -1
- package/lib/esm/context.js.map +0 -1
- package/lib/esm/hooks/use-data.js.map +0 -1
- package/lib/esm/hooks/use-flatten-data.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/styles/index.scss.js.map +0 -1
- package/lib/esm/use-check-select.js.map +0 -1
package/lib/esm/CheckSelect.js
CHANGED
@@ -8,21 +8,21 @@
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
10
|
import { __rest } from 'tslib';
|
11
|
-
import React, { forwardRef, useCallback, useState,
|
11
|
+
import React, { forwardRef, useCallback, useMemo, useState, useRef } from 'react';
|
12
12
|
import { getPrefixCls, cx } from '@hi-ui/classname';
|
13
13
|
import { __DEV__ } from '@hi-ui/env';
|
14
14
|
import { useCheckSelect } from './use-check-select.js';
|
15
15
|
import { UpOutlined, DownOutlined } from '@hi-ui/icons';
|
16
16
|
import { CheckSelectProvider, useCheckSelectContext } from './context.js';
|
17
|
-
import {
|
17
|
+
import { useLatestRef } from '@hi-ui/use-latest';
|
18
18
|
import Checkbox from '@hi-ui/checkbox';
|
19
19
|
import { TagInputMock } from '@hi-ui/tag-input';
|
20
20
|
import { isUndef, isFunction, isArrayNonEmpty } from '@hi-ui/type-assertion';
|
21
21
|
import VirtualList from 'rc-virtual-list';
|
22
22
|
import { Picker } from '@hi-ui/picker';
|
23
|
-
import { uniqBy } from '
|
23
|
+
import { uniqBy } from '@hi-ui/array-utils';
|
24
24
|
import { Highlighter } from '@hi-ui/highlighter';
|
25
|
-
import {
|
25
|
+
import { useUncontrolledToggle } from '@hi-ui/use-toggle';
|
26
26
|
import { times } from '@hi-ui/times';
|
27
27
|
import { callAllFuncs } from '@hi-ui/func-utils';
|
28
28
|
import { useLocaleContext } from '@hi-ui/locale-context';
|
@@ -60,6 +60,8 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
60
60
|
itemHeight = _a$itemHeight === void 0 ? 40 : _a$itemHeight,
|
61
61
|
_a$virtual = _a.virtual,
|
62
62
|
virtual = _a$virtual === void 0 ? true : _a$virtual,
|
63
|
+
onOpen = _a.onOpen,
|
64
|
+
onClose = _a.onClose,
|
63
65
|
appearance = _a.appearance,
|
64
66
|
invalid = _a.invalid,
|
65
67
|
dataSource = _a.dataSource,
|
@@ -70,14 +72,18 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
70
72
|
onSearchProp = _a.onSearch,
|
71
73
|
_a$fieldNames = _a.fieldNames,
|
72
74
|
fieldNames = _a$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _a$fieldNames,
|
73
|
-
rest = __rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "
|
75
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "showCheckAll", "showOnlyShowChecked", "placeholder", "displayRender", "onSelect", "height", "itemHeight", "virtual", "onOpen", "onClose", "appearance", "invalid", "dataSource", "filterOption", "searchable", "render", "renderExtraFooter", "onSearch", "fieldNames"]);
|
74
76
|
|
75
77
|
var i18n = useLocaleContext();
|
76
78
|
var placeholder = isUndef(placeholderProp) ? i18n.get('checkSelect.placeholder') : placeholderProp; // ************************** Picker ************************* //
|
77
79
|
|
78
|
-
var
|
79
|
-
|
80
|
-
|
80
|
+
var _useUncontrolledToggl = useUncontrolledToggle({
|
81
|
+
disabled: disabled,
|
82
|
+
onOpen: onOpen,
|
83
|
+
onClose: onClose
|
84
|
+
}),
|
85
|
+
menuVisible = _useUncontrolledToggl[0],
|
86
|
+
menuVisibleAction = _useUncontrolledToggl[1];
|
81
87
|
|
82
88
|
var displayRender = useCallback(function (item) {
|
83
89
|
if (isFunction(displayRenderProp)) {
|
@@ -85,34 +91,20 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
85
91
|
}
|
86
92
|
|
87
93
|
return item.title;
|
88
|
-
}, [displayRenderProp]);
|
89
|
-
|
90
|
-
var _useState = useState([]),
|
91
|
-
selectedItems = _useState[0],
|
92
|
-
setSelectedItems = _useState[1];
|
93
|
-
|
94
|
-
var onSelect = useLatestCallback(function (value, item, shouldChecked) {
|
95
|
-
onSelectProp === null || onSelectProp === void 0 ? void 0 : onSelectProp(value, item, shouldChecked);
|
96
|
-
|
97
|
-
if (shouldChecked) {
|
98
|
-
// TODO:as useCheckList
|
99
|
-
setSelectedItems(function (prev) {
|
100
|
-
return [].concat(prev, [item]);
|
101
|
-
});
|
102
|
-
}
|
103
|
-
});
|
94
|
+
}, [displayRenderProp]);
|
104
95
|
|
105
96
|
var _b = useCheckSelect(Object.assign(Object.assign({}, rest), {
|
106
97
|
children: children,
|
107
98
|
fieldNames: fieldNames,
|
108
|
-
onSelect:
|
99
|
+
onSelect: onSelectProp
|
109
100
|
})),
|
110
101
|
rootProps = _b.rootProps,
|
111
102
|
context = __rest(_b, ["rootProps"]);
|
112
103
|
|
113
104
|
var value = context.value,
|
114
105
|
tryChangeValue = context.tryChangeValue,
|
115
|
-
flattedData = context.flattedData
|
106
|
+
flattedData = context.flattedData,
|
107
|
+
checkedItems = context.checkedItems; // ************************** 搜索 ************************* //
|
116
108
|
|
117
109
|
var _c = useAsyncSearch({
|
118
110
|
dataSource: dataSource,
|
@@ -168,18 +160,19 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
168
160
|
var shouldUseSearch = !!searchValue && !hasError;
|
169
161
|
var showData = useMemo(function () {
|
170
162
|
return shouldUseSearch ? stateInSearch.data : flattedData;
|
171
|
-
}, [shouldUseSearch, flattedData, stateInSearch.data]); //
|
163
|
+
}, [shouldUseSearch, flattedData, stateInSearch.data]); // 根据 id 进行合并,注意必须是扁平数据
|
172
164
|
|
173
165
|
var mergedData = useMemo(function () {
|
174
|
-
var nextData =
|
166
|
+
var nextData = checkedItems.concat(flattedData);
|
175
167
|
return uniqBy(nextData, 'id');
|
176
|
-
}, [
|
168
|
+
}, [checkedItems, flattedData]);
|
177
169
|
|
178
|
-
var
|
179
|
-
filterItems =
|
180
|
-
setFilterItems =
|
170
|
+
var _useState = useState(null),
|
171
|
+
filterItems = _useState[0],
|
172
|
+
setFilterItems = _useState[1];
|
181
173
|
|
182
174
|
var dropdownItems = filterItems || showData;
|
175
|
+
var activeExpandable = showOnlyShowChecked && !!filterItems && menuVisible;
|
183
176
|
|
184
177
|
var _useMemo = useMemo(function () {
|
185
178
|
var dropdownIds = dropdownItems.filter(function (item) {
|
@@ -201,23 +194,47 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
201
194
|
allChecked = _useMemo[0],
|
202
195
|
indeterminate = _useMemo[1];
|
203
196
|
|
197
|
+
var valueLatestRef = useLatestRef(value);
|
204
198
|
var toggleCheckAll = useCallback(function (showChecked) {
|
205
|
-
var
|
206
|
-
|
207
|
-
});
|
199
|
+
var value = valueLatestRef.current; // 当前页的数据选项
|
200
|
+
|
208
201
|
var items = dropdownItems.filter(function (item) {
|
209
202
|
return !('groupTitle' in item);
|
210
203
|
});
|
204
|
+
var targetIds = items.map(function (_ref2) {
|
205
|
+
var id = _ref2.id;
|
206
|
+
return id;
|
207
|
+
});
|
208
|
+
var allData = uniqBy(items.concat(mergedData), 'id');
|
211
209
|
|
212
210
|
if (showChecked) {
|
213
|
-
|
214
|
-
|
215
|
-
return id;
|
216
|
-
})
|
211
|
+
var nextCheckedIds = Array.from(new Set(value.concat(targetIds)));
|
212
|
+
var changedIds = nextCheckedIds.filter(function (id) {
|
213
|
+
return !value.includes(id);
|
214
|
+
});
|
215
|
+
var changedItems = allData.filter(function (_ref3) {
|
216
|
+
var id = _ref3.id;
|
217
|
+
return changedIds.includes(id);
|
218
|
+
});
|
219
|
+
tryChangeValue(nextCheckedIds, changedItems, showChecked);
|
217
220
|
} else {
|
218
|
-
|
221
|
+
var _nextCheckedIds = value.filter(function (id) {
|
222
|
+
return !targetIds.includes(id);
|
223
|
+
});
|
224
|
+
|
225
|
+
var _changedIds = value.filter(function (id) {
|
226
|
+
return !_nextCheckedIds.includes(id);
|
227
|
+
});
|
228
|
+
|
229
|
+
var _changedItems = allData.filter(function (_ref4) {
|
230
|
+
var id = _ref4.id;
|
231
|
+
return _changedIds.includes(id);
|
232
|
+
}); // items
|
233
|
+
|
234
|
+
|
235
|
+
tryChangeValue(_nextCheckedIds, _changedItems, showChecked);
|
219
236
|
}
|
220
|
-
}, [dropdownItems, mergedData,
|
237
|
+
}, [dropdownItems, mergedData, valueLatestRef, tryChangeValue]);
|
221
238
|
|
222
239
|
var renderDefaultFooter = function renderDefaultFooter() {
|
223
240
|
var extra = renderExtraFooter ? renderExtraFooter() : null;
|
@@ -235,6 +252,7 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
235
252
|
return extra;
|
236
253
|
};
|
237
254
|
|
255
|
+
var expandedViewRef = useRef('normal');
|
238
256
|
var cls = cx(prefixCls, className, prefixCls + "--" + (menuVisible ? 'open' : 'closed'));
|
239
257
|
return /*#__PURE__*/React.createElement(CheckSelectProvider, {
|
240
258
|
value: context
|
@@ -243,16 +261,8 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
243
261
|
className: cls
|
244
262
|
}, rootProps, {
|
245
263
|
visible: menuVisible,
|
246
|
-
onOpen: function onOpen() {
|
247
|
-
if (showOnlyShowChecked) {
|
248
|
-
if (filterItems) {
|
249
|
-
setFilterItems(null);
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
menuVisibleAction.on();
|
254
|
-
},
|
255
264
|
disabled: disabled,
|
265
|
+
onOpen: menuVisibleAction.on,
|
256
266
|
onClose: menuVisibleAction.off,
|
257
267
|
searchable: searchable,
|
258
268
|
onSearch: callAllFuncs(onSearchProp, onSearch),
|
@@ -271,16 +281,49 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
271
281
|
onChange: tryChangeValue,
|
272
282
|
data: mergedData,
|
273
283
|
invalid: invalid,
|
274
|
-
|
275
|
-
if (showOnlyShowChecked)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
284
|
+
onClick: function onClick(evt) {
|
285
|
+
if (!showOnlyShowChecked) return;
|
286
|
+
if (disabled) return; // 阻止 Picker 调用 onOpen/onClose
|
287
|
+
|
288
|
+
evt.preventDefault();
|
289
|
+
|
290
|
+
if (filterItems) {
|
291
|
+
setFilterItems(null);
|
292
|
+
}
|
293
|
+
|
294
|
+
if (menuVisible) {
|
295
|
+
if (expandedViewRef.current === 'normal') {
|
296
|
+
menuVisibleAction.off();
|
297
|
+
}
|
298
|
+
} else {
|
299
|
+
menuVisibleAction.on();
|
300
|
+
}
|
301
|
+
|
302
|
+
expandedViewRef.current = 'normal';
|
303
|
+
},
|
304
|
+
expandable: showOnlyShowChecked,
|
305
|
+
activeExpandable: activeExpandable,
|
306
|
+
onExpand: function onExpand(evt) {
|
307
|
+
if (!showOnlyShowChecked) return;
|
308
|
+
if (disabled) return; // 阻止冒泡触发外层 onClick
|
309
|
+
|
310
|
+
evt.stopPropagation();
|
311
|
+
evt.preventDefault();
|
312
|
+
setFilterItems(function () {
|
313
|
+
return mergedData.filter(function (item) {
|
314
|
+
return value.includes(item.id);
|
280
315
|
});
|
316
|
+
});
|
317
|
+
|
318
|
+
if (menuVisible) {
|
319
|
+
if (expandedViewRef.current !== 'normal') {
|
320
|
+
menuVisibleAction.off();
|
321
|
+
}
|
322
|
+
} else {
|
323
|
+
menuVisibleAction.on();
|
281
324
|
}
|
282
325
|
|
283
|
-
|
326
|
+
expandedViewRef.current = 'onlyChecked';
|
284
327
|
}
|
285
328
|
})
|
286
329
|
}), isArrayNonEmpty(dropdownItems) ? /*#__PURE__*/React.createElement(VirtualList, {
|
@@ -408,4 +451,3 @@ var renderIndent = function renderIndent(prefixCls, depth) {
|
|
408
451
|
};
|
409
452
|
|
410
453
|
export { CheckSelect, CheckSelectOption, CheckSelectOptionGroup };
|
411
|
-
//# sourceMappingURL=CheckSelect.js.map
|
package/lib/esm/context.js
CHANGED
package/lib/esm/index.js
CHANGED
@@ -7,11 +7,9 @@
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
|
-
|
11
|
-
|
12
|
-
var __styleInject__ = require('style-inject/dist/style-inject.es.js')["default"];
|
10
|
+
import __styleInject__ from 'inject-head-style';
|
11
|
+
var css_248z = ".hi-v4-check-select-option {margin-top: var(--hi-v4-spacing-2, 4px);margin-bottom: var(--hi-v4-spacing-2, 4px);-webkit-box-sizing: border-box;box-sizing: border-box;width: 100%;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;position: relative;border-radius: var(--hi-v4-border-radius-md, 4px);cursor: pointer;font-size: var(--hi-v4-text-size-md, 0.875rem);font-weight: var(--hi-v4-text-weight-normal, 400);color: var(--hi-v4-color-gray-700, #1f2733);line-height: var(--hi-v4-text-lineheight-sm, 1.25rem); }.hi-v4-check-select-option__indent {display: inline-block;width: 16px;height: 100%; }.hi-v4-check-select-option__title {display: inline-block;-webkit-box-sizing: border-box;box-sizing: border-box;width: 100%;padding: var(--hi-v4-spacing-3, 6px);font-size: inherit;font-weight: inherit;color: inherit;line-height: inherit; }.hi-v4-check-select-option:hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-check-select-option--focused {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-check-select-option--disabled {cursor: not-allowed;color: var(--hi-v4-color-gray-500, #929aa6); }.hi-v4-check-select-option-group {display: inline-block;margin-top: var(--hi-v4-spacing-6, 12px);margin-bottom: var(--hi-v4-spacing-2, 4px);padding: var(--hi-v4-spacing-3, 6px) 0 var(--hi-v4-spacing-3, 6px) var(--hi-v4-spacing-3, 6px);font-size: var(--hi-v4-text-size-md, 0.875rem);font-weight: var(--hi-v4-text-weight-normal, 400);color: var(--hi-v4-color-gray-500, #929aa6);line-height: var(--hi-v4-text-lineheight-sm, 1.25rem); }.hi-v4-check-select-option-group:first-child {margin-top: var(--hi-v4-spacing-2, 4px); }";
|
13
12
|
|
14
13
|
__styleInject__(css_248z);
|
15
14
|
|
16
|
-
export default
|
17
|
-
//# sourceMappingURL=index.scss.js.map
|
15
|
+
export { css_248z as default };
|
@@ -8,9 +8,9 @@
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
10
|
import { __rest } from 'tslib';
|
11
|
-
import { useRef, useCallback } from 'react';
|
11
|
+
import { useRef, useState, useCallback } from 'react';
|
12
12
|
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
|
13
|
-
import { uniqBy } from '
|
13
|
+
import { uniqBy } from '@hi-ui/array-utils';
|
14
14
|
import { useCheck } from '@hi-ui/use-check';
|
15
15
|
import { useLatestRef, useLatestCallback } from '@hi-ui/use-latest';
|
16
16
|
import { useData } from './hooks/use-data.js';
|
@@ -49,33 +49,34 @@ var useCheckSelect = function useCheckSelect(_a) {
|
|
49
49
|
tryChangeValue = _useUncontrolledState[1];
|
50
50
|
|
51
51
|
var onSelectLatest = useLatestCallback(onSelect);
|
52
|
-
var
|
52
|
+
var usedItemsRef = useRef([]); // 扁平化的选中数据,可能包括异步临时选中缓存数据
|
53
|
+
|
54
|
+
var _useState = useState([]),
|
55
|
+
checkedItems = _useState[0],
|
56
|
+
setCheckedItems = _useState[1];
|
57
|
+
|
53
58
|
var proxyTryChangeValue = useCallback(function (value, item, shouldChecked) {
|
54
59
|
var changedItems = item;
|
55
60
|
|
56
61
|
if (!Array.isArray(item)) {
|
57
62
|
changedItems = [item];
|
58
|
-
|
59
|
-
if (shouldChecked) {
|
60
|
-
selectedItemsRef.current.push(item);
|
61
|
-
}
|
62
|
-
|
63
63
|
onSelectLatest(value, item, shouldChecked);
|
64
64
|
}
|
65
65
|
|
66
|
-
var
|
66
|
+
var usedItems = uniqBy([].concat(changedItems, usedItemsRef.current, flattedDataRef.current), 'id');
|
67
|
+
usedItemsRef.current = usedItems; // 使用最新的value
|
67
68
|
|
68
|
-
var
|
69
|
-
.filter(function (item) {
|
69
|
+
var nextCheckedItems = usedItems.filter(function (item) {
|
70
70
|
return value.includes(item.id);
|
71
|
-
}).map(function (item) {
|
72
|
-
return 'raw' in item ? item.raw : item;
|
73
71
|
});
|
74
|
-
|
72
|
+
setCheckedItems(nextCheckedItems);
|
73
|
+
tryChangeValue(value, // 处理脏数据
|
75
74
|
changedItems.map(function (item) {
|
76
75
|
return 'raw' in item ? item.raw : item;
|
77
|
-
}),
|
78
|
-
|
76
|
+
}), nextCheckedItems.map(function (item) {
|
77
|
+
return 'raw' in item ? item.raw : item;
|
78
|
+
}));
|
79
|
+
}, [tryChangeValue, onSelectLatest, flattedDataRef, usedItemsRef]);
|
79
80
|
|
80
81
|
var _useCheckDefault = useCheck({
|
81
82
|
disabled: disabled,
|
@@ -93,7 +94,8 @@ var useCheckSelect = function useCheckSelect(_a) {
|
|
93
94
|
value: value,
|
94
95
|
tryChangeValue: proxyTryChangeValue,
|
95
96
|
onSelect: onOptionCheck,
|
96
|
-
isCheckedId: isCheckedId
|
97
|
+
isCheckedId: isCheckedId,
|
98
|
+
checkedItems: checkedItems
|
97
99
|
};
|
98
100
|
};
|
99
101
|
|
@@ -102,4 +104,3 @@ var allowCheck = function allowCheck(option) {
|
|
102
104
|
};
|
103
105
|
|
104
106
|
export { useCheckSelect };
|
105
|
-
//# sourceMappingURL=use-check-select.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { UseCheckSelectProps } from './use-check-select';
|
3
|
-
import type {
|
4
|
-
import { CheckSelectDataItem,
|
3
|
+
import type { HiBaseHTMLProps } from '@hi-ui/core';
|
4
|
+
import { CheckSelectAppearanceEnum, CheckSelectDataItem, CheckSelectItemEventData, CheckSelectMergedItem } from './types';
|
5
5
|
import { PickerProps } from '@hi-ui/picker';
|
6
6
|
import { UseDataSource } from '@hi-ui/use-data-source';
|
7
7
|
/**
|
@@ -31,10 +31,6 @@ export interface CheckSelectProps extends Omit<PickerProps, 'trigger'>, UseCheck
|
|
31
31
|
* 是否可清空
|
32
32
|
*/
|
33
33
|
clearable?: boolean;
|
34
|
-
/**
|
35
|
-
* 是否开启换行全展示
|
36
|
-
*/
|
37
|
-
wrap?: boolean;
|
38
34
|
/**
|
39
35
|
* 是否点击清理 tags
|
40
36
|
*/
|
@@ -46,11 +42,11 @@ export interface CheckSelectProps extends Omit<PickerProps, 'trigger'>, UseCheck
|
|
46
42
|
/**
|
47
43
|
* 自定义渲染节点的 title 内容
|
48
44
|
*/
|
49
|
-
render?: (item:
|
45
|
+
render?: (item: CheckSelectItemEventData) => React.ReactNode;
|
50
46
|
/**
|
51
47
|
* 自定义选择后触发器所展示的内容,只在 title 为字符串时有效
|
52
48
|
*/
|
53
|
-
displayRender?: (option:
|
49
|
+
displayRender?: (option: CheckSelectItemEventData) => React.ReactNode;
|
54
50
|
/**
|
55
51
|
* 触发器输入框占位符
|
56
52
|
*/
|
@@ -58,7 +54,7 @@ export interface CheckSelectProps extends Omit<PickerProps, 'trigger'>, UseCheck
|
|
58
54
|
/**
|
59
55
|
* 设置展现形式
|
60
56
|
*/
|
61
|
-
appearance?:
|
57
|
+
appearance?: CheckSelectAppearanceEnum;
|
62
58
|
/**
|
63
59
|
* 节点搜索模式,仅在mode=normal模式下生效
|
64
60
|
*/
|
@@ -72,7 +68,7 @@ export interface CheckSelectProps extends Omit<PickerProps, 'trigger'>, UseCheck
|
|
72
68
|
/**
|
73
69
|
* 异步加载数据
|
74
70
|
*/
|
75
|
-
dataSource?: UseDataSource<
|
71
|
+
dataSource?: UseDataSource<CheckSelectMergedItem[]>;
|
76
72
|
/**
|
77
73
|
* 自定义下拉菜单底部渲染
|
78
74
|
*/
|
package/lib/types/context.d.ts
CHANGED
@@ -4,16 +4,18 @@ export declare const CheckSelectProvider: import("react").Provider<Omit<{
|
|
4
4
|
data: any[];
|
5
5
|
flattedData: import("packages/utils/tree-utils/lib/types/types").BaseFlattedTreeNodeData<any, any>[];
|
6
6
|
value: import("react").ReactText[];
|
7
|
-
tryChangeValue: (value: import("react").ReactText[], item: import("./types").
|
7
|
+
tryChangeValue: (value: import("react").ReactText[], item: import("./types").CheckSelectItemEventData | import("./types").CheckSelectItemEventData[], shouldChecked: boolean) => void;
|
8
8
|
onSelect: (targetItem: import("packages/hooks/use-check/lib/types").UseCheckItem, shouldChecked: boolean) => void;
|
9
9
|
isCheckedId: (id: import("react").ReactText) => boolean;
|
10
|
+
checkedItems: import("./types").CheckSelectItemEventData[];
|
10
11
|
}, "rootProps"> | null>;
|
11
12
|
export declare const useCheckSelectContext: () => Omit<{
|
12
13
|
rootProps: {};
|
13
14
|
data: any[];
|
14
15
|
flattedData: import("packages/utils/tree-utils/lib/types/types").BaseFlattedTreeNodeData<any, any>[];
|
15
16
|
value: import("react").ReactText[];
|
16
|
-
tryChangeValue: (value: import("react").ReactText[], item: import("./types").
|
17
|
+
tryChangeValue: (value: import("react").ReactText[], item: import("./types").CheckSelectItemEventData | import("./types").CheckSelectItemEventData[], shouldChecked: boolean) => void;
|
17
18
|
onSelect: (targetItem: import("packages/hooks/use-check/lib/types").UseCheckItem, shouldChecked: boolean) => void;
|
18
19
|
isCheckedId: (id: import("react").ReactText) => boolean;
|
20
|
+
checkedItems: import("./types").CheckSelectItemEventData[];
|
19
21
|
}, "rootProps">;
|
package/lib/types/types.d.ts
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
import React from 'react';
|
2
|
+
import type { HiBaseAppearanceEnum } from '@hi-ui/core';
|
2
3
|
export interface CheckSelectDataItem {
|
3
4
|
/**
|
4
|
-
*
|
5
|
+
* 选择项值,唯一 id
|
5
6
|
*/
|
6
7
|
id?: React.ReactText;
|
7
8
|
/**
|
8
|
-
*
|
9
|
+
* 选项标题
|
9
10
|
*/
|
10
11
|
title?: React.ReactNode;
|
11
12
|
/**
|
12
|
-
*
|
13
|
+
* 是否禁用该选项
|
13
14
|
*/
|
14
15
|
disabled?: boolean;
|
15
16
|
}
|
16
17
|
export interface CheckSelectGroupDataItem {
|
17
18
|
/**
|
18
|
-
*
|
19
|
+
* 选项组标题
|
19
20
|
*/
|
20
21
|
groupTitle?: React.ReactNode;
|
21
22
|
/**
|
22
|
-
*
|
23
|
+
* 组选项列表
|
23
24
|
*/
|
24
25
|
children?: CheckSelectDataItem[];
|
25
26
|
}
|
26
|
-
export declare type CheckSelectMergedItem = CheckSelectDataItem
|
27
|
+
export declare type CheckSelectMergedItem = CheckSelectDataItem | CheckSelectGroupDataItem;
|
27
28
|
export interface CheckSelectRequiredProps {
|
28
29
|
checked: boolean;
|
29
30
|
focused: boolean;
|
@@ -46,5 +47,6 @@ export interface FlattedCheckSelectDataItem extends CheckSelectDataItem {
|
|
46
47
|
*/
|
47
48
|
parent?: FlattedCheckSelectDataItem;
|
48
49
|
}
|
49
|
-
export interface
|
50
|
+
export interface CheckSelectItemEventData extends FlattedCheckSelectDataItem, CheckSelectRequiredProps {
|
50
51
|
}
|
52
|
+
export declare type CheckSelectAppearanceEnum = HiBaseAppearanceEnum | undefined;
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { CheckSelectDataItem,
|
3
|
-
import { HiBaseFieldNames } from '@hi-ui/core';
|
2
|
+
import { CheckSelectDataItem, CheckSelectItemEventData, CheckSelectMergedItem } from './types';
|
4
3
|
export declare const useCheckSelect: ({ data: dataProp, children, disabled, value: valueProp, defaultValue, onChange: onChangeProp, onSelect, fieldNames, ...rest }: UseCheckSelectProps) => {
|
5
4
|
rootProps: {};
|
6
5
|
data: any[];
|
7
6
|
flattedData: import("packages/utils/tree-utils/lib/types/types").BaseFlattedTreeNodeData<any, any>[];
|
8
7
|
value: React.ReactText[];
|
9
|
-
tryChangeValue: (value: React.ReactText[], item:
|
8
|
+
tryChangeValue: (value: React.ReactText[], item: CheckSelectItemEventData | CheckSelectItemEventData[], shouldChecked: boolean) => void;
|
10
9
|
onSelect: (targetItem: import("@hi-ui/use-check").UseCheckItem, shouldChecked: boolean) => void;
|
11
10
|
isCheckedId: (id: React.ReactText) => boolean;
|
11
|
+
checkedItems: CheckSelectItemEventData[];
|
12
12
|
};
|
13
13
|
export interface UseCheckSelectProps {
|
14
14
|
/**
|
@@ -25,12 +25,12 @@ export interface UseCheckSelectProps {
|
|
25
25
|
* changedItems: 变更的选项集合
|
26
26
|
* checkedItems:所有选中项的选项集合
|
27
27
|
*/
|
28
|
-
onChange?: (value: React.ReactText[], changedItems
|
28
|
+
onChange?: (value: React.ReactText[], changedItems: CheckSelectDataItem[], checkedItems: CheckSelectDataItem[]) => void;
|
29
29
|
/**
|
30
30
|
* 选中值时回调。暂不对外暴露
|
31
31
|
* @private
|
32
32
|
*/
|
33
|
-
onSelect?: (value: React.ReactText[], targetOption:
|
33
|
+
onSelect?: (value: React.ReactText[], targetOption: CheckSelectItemEventData, shouldChecked: boolean) => void;
|
34
34
|
/**
|
35
35
|
* 是否禁止使用
|
36
36
|
*/
|
@@ -38,7 +38,7 @@ export interface UseCheckSelectProps {
|
|
38
38
|
/**
|
39
39
|
* 选项数据
|
40
40
|
*/
|
41
|
-
data?:
|
41
|
+
data?: CheckSelectMergedItem[];
|
42
42
|
/**
|
43
43
|
* JSX 子节点
|
44
44
|
*/
|
@@ -46,6 +46,6 @@ export interface UseCheckSelectProps {
|
|
46
46
|
/**
|
47
47
|
* 设置 data 中 id, title, disabled, children 对应的 key
|
48
48
|
*/
|
49
|
-
fieldNames?:
|
49
|
+
fieldNames?: Record<string, string>;
|
50
50
|
}
|
51
51
|
export declare type UseSelectReturn = ReturnType<typeof useCheckSelect>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hi-ui/check-select",
|
3
|
-
"version": "4.0.0-beta.
|
3
|
+
"version": "4.0.0-beta.32",
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
5
5
|
"keywords": [],
|
6
6
|
"author": "HIUI <mi-hiui@xiaomi.com>",
|
@@ -43,40 +43,40 @@
|
|
43
43
|
"url": "https://github.com/XiaoMi/hiui/issues"
|
44
44
|
},
|
45
45
|
"dependencies": {
|
46
|
-
"@hi-ui/
|
46
|
+
"@hi-ui/array-utils": "^4.0.0-beta.8",
|
47
|
+
"@hi-ui/checkbox": "^4.0.0-beta.13",
|
47
48
|
"@hi-ui/classname": "^4.0.0-beta.0",
|
48
|
-
"@hi-ui/core": "^4.0.0-beta.
|
49
|
-
"@hi-ui/core-css": "^4.0.0-beta.
|
50
|
-
"@hi-ui/env": "^4.0.0-beta.
|
51
|
-
"@hi-ui/func-utils": "^4.0.0-beta.
|
52
|
-
"@hi-ui/highlighter": "^4.0.0-beta.
|
53
|
-
"@hi-ui/icons": "^4.0.0-beta.
|
54
|
-
"@hi-ui/input": "^4.0.0-beta.
|
55
|
-
"@hi-ui/locale-context": "^4.0.0-beta.
|
56
|
-
"@hi-ui/picker": "^4.0.0-beta.
|
57
|
-
"@hi-ui/popper": "^4.0.0-beta.
|
58
|
-
"@hi-ui/tag-input": "^4.0.0-beta.
|
59
|
-
"@hi-ui/times": "^4.0.0-beta.
|
60
|
-
"@hi-ui/tree-utils": "^4.0.0-beta.
|
61
|
-
"@hi-ui/type-assertion": "^4.0.0-beta.
|
62
|
-
"@hi-ui/use-check": "^4.0.0-beta.
|
63
|
-
"@hi-ui/use-children": "^4.0.0-beta.
|
64
|
-
"@hi-ui/use-data-source": "^4.0.0-beta.
|
65
|
-
"@hi-ui/use-latest": "^4.0.0-beta.
|
66
|
-
"@hi-ui/use-search-mode": "^4.0.0-beta.
|
67
|
-
"@hi-ui/use-toggle": "^4.0.0-beta.
|
68
|
-
"@hi-ui/use-uncontrolled-state": "^4.0.0-beta.
|
69
|
-
"
|
70
|
-
"rc-virtual-list": "^3.4.1"
|
49
|
+
"@hi-ui/core": "^4.0.0-beta.9",
|
50
|
+
"@hi-ui/core-css": "^4.0.0-beta.5",
|
51
|
+
"@hi-ui/env": "^4.0.0-beta.1",
|
52
|
+
"@hi-ui/func-utils": "^4.0.0-beta.13",
|
53
|
+
"@hi-ui/highlighter": "^4.0.0-beta.10",
|
54
|
+
"@hi-ui/icons": "^4.0.0-beta.11",
|
55
|
+
"@hi-ui/input": "^4.0.0-beta.16",
|
56
|
+
"@hi-ui/locale-context": "^4.0.0-beta.19",
|
57
|
+
"@hi-ui/picker": "^4.0.0-beta.25",
|
58
|
+
"@hi-ui/popper": "^4.0.0-beta.15",
|
59
|
+
"@hi-ui/tag-input": "^4.0.0-beta.19",
|
60
|
+
"@hi-ui/times": "^4.0.0-beta.6",
|
61
|
+
"@hi-ui/tree-utils": "^4.0.0-beta.5",
|
62
|
+
"@hi-ui/type-assertion": "^4.0.0-beta.5",
|
63
|
+
"@hi-ui/use-check": "^4.0.0-beta.5",
|
64
|
+
"@hi-ui/use-children": "^4.0.0-beta.5",
|
65
|
+
"@hi-ui/use-data-source": "^4.0.0-beta.6",
|
66
|
+
"@hi-ui/use-latest": "^4.0.0-beta.5",
|
67
|
+
"@hi-ui/use-search-mode": "^4.0.0-beta.20",
|
68
|
+
"@hi-ui/use-toggle": "^4.0.0-beta.5",
|
69
|
+
"@hi-ui/use-uncontrolled-state": "^4.0.0-beta.5",
|
70
|
+
"rc-virtual-list": "^3.4.7"
|
71
71
|
},
|
72
72
|
"peerDependencies": {
|
73
73
|
"react": ">=16.8.6",
|
74
74
|
"react-dom": ">=16.8.6"
|
75
75
|
},
|
76
76
|
"devDependencies": {
|
77
|
-
"@hi-ui/hi-build": "^4.0.0-beta.
|
77
|
+
"@hi-ui/hi-build": "^4.0.0-beta.5",
|
78
78
|
"react": "^17.0.1",
|
79
79
|
"react-dom": "^17.0.1"
|
80
80
|
},
|
81
|
-
"gitHead": "
|
81
|
+
"gitHead": "ef96654e009a72c3445d8df4a4182973631d00e9"
|
82
82
|
}
|