@hi-ui/check-select 4.0.0-beta.8 → 4.0.1
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 +106 -93
- package/lib/cjs/context.js +1 -2
- package/lib/cjs/hooks/use-data.js +1 -2
- package/lib/cjs/hooks/use-flatten-data.js +1 -2
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/styles/index.scss.js +3 -4
- package/lib/cjs/use-check-select.js +18 -17
- package/lib/cjs/utils/index.js +52 -0
- package/lib/esm/CheckSelect.js +91 -78
- package/lib/esm/context.js +1 -2
- package/lib/esm/hooks/use-data.js +1 -2
- package/lib/esm/hooks/use-flatten-data.js +1 -2
- package/lib/esm/index.js +1 -2
- package/lib/esm/styles/index.scss.js +4 -6
- package/lib/esm/use-check-select.js +19 -18
- package/lib/esm/utils/index.js +45 -0
- package/lib/types/CheckSelect.d.ts +8 -12
- 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/lib/types/utils/index.d.ts +10 -0
- package/package.json +29 -29
- 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
@@ -0,0 +1,52 @@
|
|
1
|
+
/** @LICENSE
|
2
|
+
* @hi-ui/check-select
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
|
+
*
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
|
+
*
|
7
|
+
* This source code is licensed under the MIT license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
'use strict';
|
11
|
+
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
13
|
+
value: true
|
14
|
+
});
|
15
|
+
/**
|
16
|
+
* 判断选项是否进行可选操作
|
17
|
+
*/
|
18
|
+
|
19
|
+
var isCheckableOption = function isCheckableOption(item) {
|
20
|
+
if ('groupTitle' in item) return false;
|
21
|
+
if (item.disabled) return false;
|
22
|
+
return true;
|
23
|
+
};
|
24
|
+
/**
|
25
|
+
* 判断选项为
|
26
|
+
*/
|
27
|
+
|
28
|
+
|
29
|
+
var isOption = function isOption(item) {
|
30
|
+
if ('groupTitle' in item) return false;
|
31
|
+
return true;
|
32
|
+
};
|
33
|
+
|
34
|
+
var getAllCheckedStatus = function getAllCheckedStatus(dropdownItems, values, filterFunc) {
|
35
|
+
var dropdownIds = dropdownItems.filter(filterFunc).map(function (_ref) {
|
36
|
+
var id = _ref.id;
|
37
|
+
return id;
|
38
|
+
});
|
39
|
+
var dropdownIdsSet = new Set(dropdownIds);
|
40
|
+
var hasValue = false;
|
41
|
+
values.forEach(function (id) {
|
42
|
+
if (dropdownIdsSet.has(id)) {
|
43
|
+
hasValue = true;
|
44
|
+
dropdownIdsSet["delete"](id);
|
45
|
+
}
|
46
|
+
});
|
47
|
+
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
48
|
+
};
|
49
|
+
|
50
|
+
exports.getAllCheckedStatus = getAllCheckedStatus;
|
51
|
+
exports.isCheckableOption = isCheckableOption;
|
52
|
+
exports.isOption = isOption;
|
package/lib/esm/CheckSelect.js
CHANGED
@@ -2,33 +2,33 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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
10
|
import { __rest } from 'tslib';
|
11
|
-
import React, { forwardRef, useCallback,
|
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 '@hi-ui/array-utils';
|
23
|
+
import { uniqBy, times } from '@hi-ui/array-utils';
|
24
24
|
import { Highlighter } from '@hi-ui/highlighter';
|
25
|
-
import {
|
26
|
-
import { times } from '@hi-ui/times';
|
25
|
+
import { useUncontrolledToggle } from '@hi-ui/use-toggle';
|
27
26
|
import { callAllFuncs } from '@hi-ui/func-utils';
|
28
|
-
import { useLocaleContext } from '@hi-ui/
|
27
|
+
import { useLocaleContext } from '@hi-ui/core';
|
29
28
|
import { useAsyncSearch, useTreeCustomSearch, useFilterSearch, useSearchMode } from '@hi-ui/use-search-mode';
|
30
29
|
import '@hi-ui/use-children';
|
31
30
|
import { flattenData } from './hooks/use-flatten-data.js';
|
31
|
+
import { getAllCheckedStatus, isCheckableOption, isOption } from './utils/index.js';
|
32
32
|
var _role = 'check-select';
|
33
33
|
|
34
34
|
var _prefix = getPrefixCls(_role);
|
@@ -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,67 +162,79 @@ 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
|
-
|
186
|
-
return !('groupTitle' in item);
|
187
|
-
}).map(function (_ref) {
|
188
|
-
var id = _ref.id;
|
189
|
-
return id;
|
190
|
-
});
|
191
|
-
var dropdownIdsSet = new Set(dropdownIds);
|
192
|
-
var hasValue = false;
|
193
|
-
value.forEach(function (id) {
|
194
|
-
if (dropdownIdsSet.has(id)) {
|
195
|
-
hasValue = true;
|
196
|
-
dropdownIdsSet["delete"](id);
|
197
|
-
}
|
198
|
-
});
|
199
|
-
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
180
|
+
return getAllCheckedStatus(dropdownItems, value, isOption);
|
200
181
|
}, [dropdownItems, value]),
|
201
|
-
|
202
|
-
|
182
|
+
showAllChecked = _useMemo[0],
|
183
|
+
showIndeterminate = _useMemo[1];
|
203
184
|
|
204
|
-
var
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
var
|
209
|
-
|
185
|
+
var valueLatestRef = useLatestRef(value);
|
186
|
+
var toggleCheckAll = useCallback(function () {
|
187
|
+
var value = valueLatestRef.current;
|
188
|
+
|
189
|
+
var _getAllCheckedStatus = getAllCheckedStatus(dropdownItems, value, isCheckableOption),
|
190
|
+
currentAllChecked = _getAllCheckedStatus[0];
|
191
|
+
|
192
|
+
var shouldChecked = !currentAllChecked; // 当前页的数据选项
|
193
|
+
|
194
|
+
var items = dropdownItems.filter(isCheckableOption);
|
195
|
+
var targetIds = items.map(function (_ref) {
|
196
|
+
var id = _ref.id;
|
197
|
+
return id;
|
210
198
|
});
|
199
|
+
var allData = uniqBy(items.concat(mergedData), 'id');
|
211
200
|
|
212
|
-
if (
|
213
|
-
|
201
|
+
if (shouldChecked) {
|
202
|
+
var nextCheckedIds = Array.from(new Set(value.concat(targetIds)));
|
203
|
+
var changedIds = nextCheckedIds.filter(function (id) {
|
204
|
+
return !value.includes(id);
|
205
|
+
});
|
206
|
+
var changedItems = allData.filter(function (_ref2) {
|
214
207
|
var id = _ref2.id;
|
215
|
-
return id;
|
216
|
-
})
|
208
|
+
return changedIds.includes(id);
|
209
|
+
});
|
210
|
+
tryChangeValue(nextCheckedIds, changedItems, shouldChecked);
|
217
211
|
} else {
|
218
|
-
|
212
|
+
var _nextCheckedIds = value.filter(function (id) {
|
213
|
+
return !targetIds.includes(id);
|
214
|
+
});
|
215
|
+
|
216
|
+
var _changedIds = value.filter(function (id) {
|
217
|
+
return !_nextCheckedIds.includes(id);
|
218
|
+
});
|
219
|
+
|
220
|
+
var _changedItems = allData.filter(function (_ref3) {
|
221
|
+
var id = _ref3.id;
|
222
|
+
return _changedIds.includes(id);
|
223
|
+
}); // items
|
224
|
+
|
225
|
+
|
226
|
+
tryChangeValue(_nextCheckedIds, _changedItems, shouldChecked);
|
219
227
|
}
|
220
|
-
}, [dropdownItems, mergedData,
|
228
|
+
}, [dropdownItems, mergedData, valueLatestRef, tryChangeValue]);
|
221
229
|
|
222
230
|
var renderDefaultFooter = function renderDefaultFooter() {
|
223
231
|
var extra = renderExtraFooter ? renderExtraFooter() : null;
|
224
232
|
|
225
233
|
if (showCheckAll) {
|
226
234
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Checkbox, {
|
227
|
-
indeterminate:
|
228
|
-
checked:
|
229
|
-
onChange:
|
230
|
-
toggleCheckAll(evt.target.checked);
|
231
|
-
}
|
235
|
+
indeterminate: showIndeterminate,
|
236
|
+
checked: showAllChecked,
|
237
|
+
onChange: toggleCheckAll
|
232
238
|
}, i18n.get('checkSelect.checkAll')), extra);
|
233
239
|
}
|
234
240
|
|
@@ -236,6 +242,16 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
236
242
|
};
|
237
243
|
|
238
244
|
var expandedViewRef = useRef('normal');
|
245
|
+
var virtualListProps = {
|
246
|
+
height: height,
|
247
|
+
itemHeight: itemHeight,
|
248
|
+
virtual: virtual,
|
249
|
+
data: dropdownItems
|
250
|
+
};
|
251
|
+
|
252
|
+
var _useCheckInVirtual = useCheckInVirtual(virtualListProps),
|
253
|
+
inVirtual = _useCheckInVirtual.inVirtual;
|
254
|
+
|
239
255
|
var cls = cx(prefixCls, className, prefixCls + "--" + (menuVisible ? 'open' : 'closed'));
|
240
256
|
return /*#__PURE__*/React.createElement(CheckSelectProvider, {
|
241
257
|
value: context
|
@@ -248,6 +264,7 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
248
264
|
onOpen: menuVisibleAction.on,
|
249
265
|
onClose: menuVisibleAction.off,
|
250
266
|
searchable: searchable,
|
267
|
+
scrollable: !inVirtual,
|
251
268
|
onSearch: callAllFuncs(onSearchProp, onSearch),
|
252
269
|
loading: loading,
|
253
270
|
footer: renderDefaultFooter(),
|
@@ -285,6 +302,7 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
285
302
|
expandedViewRef.current = 'normal';
|
286
303
|
},
|
287
304
|
expandable: showOnlyShowChecked,
|
305
|
+
activeExpandable: activeExpandable,
|
288
306
|
onExpand: function onExpand(evt) {
|
289
307
|
if (!showOnlyShowChecked) return;
|
290
308
|
if (disabled) return; // 阻止冒泡触发外层 onClick
|
@@ -308,14 +326,10 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
308
326
|
expandedViewRef.current = 'onlyChecked';
|
309
327
|
}
|
310
328
|
})
|
311
|
-
}), isArrayNonEmpty(dropdownItems) ? /*#__PURE__*/React.createElement(VirtualList, {
|
329
|
+
}), isArrayNonEmpty(dropdownItems) ? /*#__PURE__*/React.createElement(VirtualList, Object.assign({
|
312
330
|
itemKey: "id",
|
313
|
-
fullHeight: false
|
314
|
-
|
315
|
-
itemHeight: itemHeight,
|
316
|
-
virtual: virtual,
|
317
|
-
data: dropdownItems
|
318
|
-
}, function (node) {
|
331
|
+
fullHeight: false
|
332
|
+
}, virtualListProps), function (node) {
|
319
333
|
/* 反向 map,搜索删选数据时会对数据进行处理 */
|
320
334
|
return 'groupTitle' in node ? /*#__PURE__*/React.createElement(CheckSelectOptionGroup, {
|
321
335
|
label: node.groupTitle
|
@@ -433,4 +447,3 @@ var renderIndent = function renderIndent(prefixCls, depth) {
|
|
433
447
|
};
|
434
448
|
|
435
449
|
export { CheckSelect, CheckSelectOption, CheckSelectOptionGroup };
|
436
|
-
//# sourceMappingURL=CheckSelect.js.map
|
package/lib/esm/context.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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.
|
@@ -22,4 +22,3 @@ var useCheckSelectContext = function useCheckSelectContext() {
|
|
22
22
|
};
|
23
23
|
|
24
24
|
export { CheckSelectProvider, useCheckSelectContext };
|
25
|
-
//# sourceMappingURL=context.js.map
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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.
|
@@ -91,4 +91,3 @@ var parseOptionGroup = function parseOptionGroup(node) {
|
|
91
91
|
};
|
92
92
|
|
93
93
|
export { parseChildren, useData };
|
94
|
-
//# sourceMappingURL=use-data.js.map
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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.
|
@@ -66,4 +66,3 @@ var flattenData = function flattenData(_ref2) {
|
|
66
66
|
};
|
67
67
|
|
68
68
|
export { flattenData, useFlattenData };
|
69
|
-
//# sourceMappingURL=use-flatten-data.js.map
|
package/lib/esm/index.js
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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
10
|
import './styles/index.scss.js';
|
11
11
|
export { CheckSelect, CheckSelectOption, CheckSelectOptionGroup, CheckSelect as default } from './CheckSelect.js';
|
12
|
-
//# sourceMappingURL=index.js.map
|
@@ -2,16 +2,14 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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 };
|
@@ -2,13 +2,13 @@
|
|
2
2
|
* @hi-ui/check-select
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
4
|
*
|
5
|
-
* Copyright (c)
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
6
|
*
|
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
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
13
|
import { uniqBy } from '@hi-ui/array-utils';
|
14
14
|
import { useCheck } from '@hi-ui/use-check';
|
@@ -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
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/** @LICENSE
|
2
|
+
* @hi-ui/check-select
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
|
+
*
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
6
|
+
*
|
7
|
+
* This source code is licensed under the MIT license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 判断选项是否进行可选操作
|
13
|
+
*/
|
14
|
+
var isCheckableOption = function isCheckableOption(item) {
|
15
|
+
if ('groupTitle' in item) return false;
|
16
|
+
if (item.disabled) return false;
|
17
|
+
return true;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* 判断选项为
|
21
|
+
*/
|
22
|
+
|
23
|
+
|
24
|
+
var isOption = function isOption(item) {
|
25
|
+
if ('groupTitle' in item) return false;
|
26
|
+
return true;
|
27
|
+
};
|
28
|
+
|
29
|
+
var getAllCheckedStatus = function getAllCheckedStatus(dropdownItems, values, filterFunc) {
|
30
|
+
var dropdownIds = dropdownItems.filter(filterFunc).map(function (_ref) {
|
31
|
+
var id = _ref.id;
|
32
|
+
return id;
|
33
|
+
});
|
34
|
+
var dropdownIdsSet = new Set(dropdownIds);
|
35
|
+
var hasValue = false;
|
36
|
+
values.forEach(function (id) {
|
37
|
+
if (dropdownIdsSet.has(id)) {
|
38
|
+
hasValue = true;
|
39
|
+
dropdownIdsSet["delete"](id);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
43
|
+
};
|
44
|
+
|
45
|
+
export { getAllCheckedStatus, isCheckableOption, isOption };
|
@@ -1,14 +1,14 @@
|
|
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
|
/**
|
8
8
|
* TODO: What is CheckSelect
|
9
9
|
*/
|
10
10
|
export declare const CheckSelect: React.ForwardRefExoticComponent<CheckSelectProps & React.RefAttributes<HTMLDivElement | null>>;
|
11
|
-
export interface CheckSelectProps extends Omit<PickerProps, 'trigger'>, UseCheckSelectProps {
|
11
|
+
export interface CheckSelectProps extends Omit<PickerProps, 'trigger' | 'scrollable'>, UseCheckSelectProps {
|
12
12
|
/**
|
13
13
|
* 设置虚拟滚动容器的可视高度。暂不对外暴露
|
14
14
|
* @private
|
@@ -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
|
*/
|
@@ -94,7 +90,7 @@ export interface CheckSelectProps extends Omit<PickerProps, 'trigger'>, UseCheck
|
|
94
90
|
*/
|
95
91
|
onClose?: () => void;
|
96
92
|
/**
|
97
|
-
*
|
93
|
+
* 是否开启全选功能,需要对数据全量操作。异步数据场景暂不支持,可自行渲染弹层底部实现
|
98
94
|
*/
|
99
95
|
showCheckAll?: boolean;
|
100
96
|
/**
|
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