@hi-ui/check-select 4.0.0-beta.4 → 4.0.0-beta.42
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 +131 -80
- 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 +117 -66
- 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/index.d.ts +1 -0
- 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
|
-
import VirtualList from '
|
21
|
+
import VirtualList, { useCheckInVirtual } from '@hi-ui/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,9 @@ 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
|
+
visible = _a.visible,
|
64
|
+
onOpen = _a.onOpen,
|
65
|
+
onClose = _a.onClose,
|
63
66
|
appearance = _a.appearance,
|
64
67
|
invalid = _a.invalid,
|
65
68
|
dataSource = _a.dataSource,
|
@@ -70,14 +73,19 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
70
73
|
onSearchProp = _a.onSearch,
|
71
74
|
_a$fieldNames = _a.fieldNames,
|
72
75
|
fieldNames = _a$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _a$fieldNames,
|
73
|
-
rest = __rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "
|
76
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "showCheckAll", "showOnlyShowChecked", "placeholder", "displayRender", "onSelect", "height", "itemHeight", "virtual", "visible", "onOpen", "onClose", "appearance", "invalid", "dataSource", "filterOption", "searchable", "render", "renderExtraFooter", "onSearch", "fieldNames"]);
|
74
77
|
|
75
78
|
var i18n = useLocaleContext();
|
76
79
|
var placeholder = isUndef(placeholderProp) ? i18n.get('checkSelect.placeholder') : placeholderProp; // ************************** Picker ************************* //
|
77
80
|
|
78
|
-
var
|
79
|
-
|
80
|
-
|
81
|
+
var _useUncontrolledToggl = useUncontrolledToggle({
|
82
|
+
visible: visible,
|
83
|
+
disabled: disabled,
|
84
|
+
onOpen: onOpen,
|
85
|
+
onClose: onClose
|
86
|
+
}),
|
87
|
+
menuVisible = _useUncontrolledToggl[0],
|
88
|
+
menuVisibleAction = _useUncontrolledToggl[1];
|
81
89
|
|
82
90
|
var displayRender = useCallback(function (item) {
|
83
91
|
if (isFunction(displayRenderProp)) {
|
@@ -85,34 +93,20 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
85
93
|
}
|
86
94
|
|
87
95
|
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
|
-
});
|
96
|
+
}, [displayRenderProp]);
|
104
97
|
|
105
98
|
var _b = useCheckSelect(Object.assign(Object.assign({}, rest), {
|
106
99
|
children: children,
|
107
100
|
fieldNames: fieldNames,
|
108
|
-
onSelect:
|
101
|
+
onSelect: onSelectProp
|
109
102
|
})),
|
110
103
|
rootProps = _b.rootProps,
|
111
104
|
context = __rest(_b, ["rootProps"]);
|
112
105
|
|
113
106
|
var value = context.value,
|
114
107
|
tryChangeValue = context.tryChangeValue,
|
115
|
-
flattedData = context.flattedData
|
108
|
+
flattedData = context.flattedData,
|
109
|
+
checkedItems = context.checkedItems; // ************************** 搜索 ************************* //
|
116
110
|
|
117
111
|
var _c = useAsyncSearch({
|
118
112
|
dataSource: dataSource,
|
@@ -168,18 +162,19 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
168
162
|
var shouldUseSearch = !!searchValue && !hasError;
|
169
163
|
var showData = useMemo(function () {
|
170
164
|
return shouldUseSearch ? stateInSearch.data : flattedData;
|
171
|
-
}, [shouldUseSearch, flattedData, stateInSearch.data]); //
|
165
|
+
}, [shouldUseSearch, flattedData, stateInSearch.data]); // 根据 id 进行合并,注意必须是扁平数据
|
172
166
|
|
173
167
|
var mergedData = useMemo(function () {
|
174
|
-
var nextData =
|
168
|
+
var nextData = checkedItems.concat(flattedData);
|
175
169
|
return uniqBy(nextData, 'id');
|
176
|
-
}, [
|
170
|
+
}, [checkedItems, flattedData]);
|
177
171
|
|
178
|
-
var
|
179
|
-
filterItems =
|
180
|
-
setFilterItems =
|
172
|
+
var _useState = useState(null),
|
173
|
+
filterItems = _useState[0],
|
174
|
+
setFilterItems = _useState[1];
|
181
175
|
|
182
176
|
var dropdownItems = filterItems || showData;
|
177
|
+
var activeExpandable = showOnlyShowChecked && !!filterItems && menuVisible;
|
183
178
|
|
184
179
|
var _useMemo = useMemo(function () {
|
185
180
|
var dropdownIds = dropdownItems.filter(function (item) {
|
@@ -201,23 +196,47 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
201
196
|
allChecked = _useMemo[0],
|
202
197
|
indeterminate = _useMemo[1];
|
203
198
|
|
199
|
+
var valueLatestRef = useLatestRef(value);
|
204
200
|
var toggleCheckAll = useCallback(function (showChecked) {
|
205
|
-
var
|
206
|
-
|
207
|
-
});
|
201
|
+
var value = valueLatestRef.current; // 当前页的数据选项
|
202
|
+
|
208
203
|
var items = dropdownItems.filter(function (item) {
|
209
204
|
return !('groupTitle' in item);
|
210
205
|
});
|
206
|
+
var targetIds = items.map(function (_ref2) {
|
207
|
+
var id = _ref2.id;
|
208
|
+
return id;
|
209
|
+
});
|
210
|
+
var allData = uniqBy(items.concat(mergedData), 'id');
|
211
211
|
|
212
212
|
if (showChecked) {
|
213
|
-
|
214
|
-
|
215
|
-
return id;
|
216
|
-
})
|
213
|
+
var nextCheckedIds = Array.from(new Set(value.concat(targetIds)));
|
214
|
+
var changedIds = nextCheckedIds.filter(function (id) {
|
215
|
+
return !value.includes(id);
|
216
|
+
});
|
217
|
+
var changedItems = allData.filter(function (_ref3) {
|
218
|
+
var id = _ref3.id;
|
219
|
+
return changedIds.includes(id);
|
220
|
+
});
|
221
|
+
tryChangeValue(nextCheckedIds, changedItems, showChecked);
|
217
222
|
} else {
|
218
|
-
|
223
|
+
var _nextCheckedIds = value.filter(function (id) {
|
224
|
+
return !targetIds.includes(id);
|
225
|
+
});
|
226
|
+
|
227
|
+
var _changedIds = value.filter(function (id) {
|
228
|
+
return !_nextCheckedIds.includes(id);
|
229
|
+
});
|
230
|
+
|
231
|
+
var _changedItems = allData.filter(function (_ref4) {
|
232
|
+
var id = _ref4.id;
|
233
|
+
return _changedIds.includes(id);
|
234
|
+
}); // items
|
235
|
+
|
236
|
+
|
237
|
+
tryChangeValue(_nextCheckedIds, _changedItems, showChecked);
|
219
238
|
}
|
220
|
-
}, [dropdownItems, mergedData,
|
239
|
+
}, [dropdownItems, mergedData, valueLatestRef, tryChangeValue]);
|
221
240
|
|
222
241
|
var renderDefaultFooter = function renderDefaultFooter() {
|
223
242
|
var extra = renderExtraFooter ? renderExtraFooter() : null;
|
@@ -235,6 +254,17 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
235
254
|
return extra;
|
236
255
|
};
|
237
256
|
|
257
|
+
var expandedViewRef = useRef('normal');
|
258
|
+
var virtualListProps = {
|
259
|
+
height: height,
|
260
|
+
itemHeight: itemHeight,
|
261
|
+
virtual: virtual,
|
262
|
+
data: dropdownItems
|
263
|
+
};
|
264
|
+
|
265
|
+
var _useCheckInVirtual = useCheckInVirtual(virtualListProps),
|
266
|
+
inVirtual = _useCheckInVirtual.inVirtual;
|
267
|
+
|
238
268
|
var cls = cx(prefixCls, className, prefixCls + "--" + (menuVisible ? 'open' : 'closed'));
|
239
269
|
return /*#__PURE__*/React.createElement(CheckSelectProvider, {
|
240
270
|
value: context
|
@@ -243,18 +273,11 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
243
273
|
className: cls
|
244
274
|
}, rootProps, {
|
245
275
|
visible: menuVisible,
|
246
|
-
onOpen: function onOpen() {
|
247
|
-
if (showOnlyShowChecked) {
|
248
|
-
if (filterItems) {
|
249
|
-
setFilterItems(null);
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
menuVisibleAction.on();
|
254
|
-
},
|
255
276
|
disabled: disabled,
|
277
|
+
onOpen: menuVisibleAction.on,
|
256
278
|
onClose: menuVisibleAction.off,
|
257
279
|
searchable: searchable,
|
280
|
+
scrollable: !inVirtual,
|
258
281
|
onSearch: callAllFuncs(onSearchProp, onSearch),
|
259
282
|
loading: loading,
|
260
283
|
footer: renderDefaultFooter(),
|
@@ -271,26 +294,55 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
271
294
|
onChange: tryChangeValue,
|
272
295
|
data: mergedData,
|
273
296
|
invalid: invalid,
|
274
|
-
|
275
|
-
if (showOnlyShowChecked)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
297
|
+
onClick: function onClick(evt) {
|
298
|
+
if (!showOnlyShowChecked) return;
|
299
|
+
if (disabled) return; // 阻止 Picker 调用 onOpen/onClose
|
300
|
+
|
301
|
+
evt.preventDefault();
|
302
|
+
|
303
|
+
if (filterItems) {
|
304
|
+
setFilterItems(null);
|
305
|
+
}
|
306
|
+
|
307
|
+
if (menuVisible) {
|
308
|
+
if (expandedViewRef.current === 'normal') {
|
309
|
+
menuVisibleAction.off();
|
310
|
+
}
|
311
|
+
} else {
|
312
|
+
menuVisibleAction.on();
|
313
|
+
}
|
314
|
+
|
315
|
+
expandedViewRef.current = 'normal';
|
316
|
+
},
|
317
|
+
expandable: showOnlyShowChecked,
|
318
|
+
activeExpandable: activeExpandable,
|
319
|
+
onExpand: function onExpand(evt) {
|
320
|
+
if (!showOnlyShowChecked) return;
|
321
|
+
if (disabled) return; // 阻止冒泡触发外层 onClick
|
322
|
+
|
323
|
+
evt.stopPropagation();
|
324
|
+
evt.preventDefault();
|
325
|
+
setFilterItems(function () {
|
326
|
+
return mergedData.filter(function (item) {
|
327
|
+
return value.includes(item.id);
|
280
328
|
});
|
329
|
+
});
|
330
|
+
|
331
|
+
if (menuVisible) {
|
332
|
+
if (expandedViewRef.current !== 'normal') {
|
333
|
+
menuVisibleAction.off();
|
334
|
+
}
|
335
|
+
} else {
|
336
|
+
menuVisibleAction.on();
|
281
337
|
}
|
282
338
|
|
283
|
-
|
339
|
+
expandedViewRef.current = 'onlyChecked';
|
284
340
|
}
|
285
341
|
})
|
286
|
-
}), isArrayNonEmpty(dropdownItems) ? /*#__PURE__*/React.createElement(VirtualList, {
|
342
|
+
}), isArrayNonEmpty(dropdownItems) ? /*#__PURE__*/React.createElement(VirtualList, Object.assign({
|
287
343
|
itemKey: "id",
|
288
|
-
fullHeight: false
|
289
|
-
|
290
|
-
itemHeight: itemHeight,
|
291
|
-
virtual: virtual,
|
292
|
-
data: dropdownItems
|
293
|
-
}, function (node) {
|
344
|
+
fullHeight: false
|
345
|
+
}, virtualListProps), function (node) {
|
294
346
|
/* 反向 map,搜索删选数据时会对数据进行处理 */
|
295
347
|
return 'groupTitle' in node ? /*#__PURE__*/React.createElement(CheckSelectOptionGroup, {
|
296
348
|
label: node.groupTitle
|
@@ -408,4 +460,3 @@ var renderIndent = function renderIndent(prefixCls, depth) {
|
|
408
460
|
};
|
409
461
|
|
410
462
|
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/index.d.ts
CHANGED
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>;
|