@hi-ui/check-select 5.0.0-canary.1 → 5.0.0-canary.3
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/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# @hi-ui/check-select
|
2
2
|
|
3
|
+
## 5.0.0-canary.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- df3615e78: <br>
|
8
|
+
- style(tag-input): 间距调整 (5.0)
|
9
|
+
- style(select): 选择类组件选项圆角改为 4px (5.0)
|
10
|
+
- style(picker): 搜索框样式调整 (5.0)
|
11
|
+
- Updated dependencies [3cb3377dc]
|
12
|
+
- Updated dependencies [df3615e78]
|
13
|
+
- @hi-ui/picker@5.0.0-canary.3
|
14
|
+
- @hi-ui/tag-input@5.0.0-canary.4
|
15
|
+
|
16
|
+
## 5.0.0-canary.2
|
17
|
+
|
18
|
+
### Minor Changes
|
19
|
+
|
20
|
+
- d621cf2b7: feat(select): 增加 creatableInSearch、createTitle 参数,支持在搜索无结果时可创建选项 (5.0)
|
21
|
+
|
22
|
+
### Patch Changes
|
23
|
+
|
24
|
+
- Updated dependencies [2451ab789]
|
25
|
+
- Updated dependencies [d621cf2b7]
|
26
|
+
- @hi-ui/popper@5.0.0-canary.1
|
27
|
+
- @hi-ui/picker@5.0.0-canary.2
|
28
|
+
|
3
29
|
## 5.0.0-canary.1
|
4
30
|
|
5
31
|
### Minor Changes
|
package/lib/cjs/CheckSelect.js
CHANGED
@@ -36,6 +36,7 @@ var useSearchMode = require('@hi-ui/use-search-mode');
|
|
36
36
|
require('@hi-ui/use-children');
|
37
37
|
var useFlattenData = require('./hooks/use-flatten-data.js');
|
38
38
|
var index = require('./utils/index.js');
|
39
|
+
var useId = require('@hi-ui/use-id');
|
39
40
|
function _interopDefaultCompat(e) {
|
40
41
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
41
42
|
'default': e
|
@@ -85,6 +86,8 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
85
86
|
titleRender = _a.render,
|
86
87
|
renderExtraFooter = _a.renderExtraFooter,
|
87
88
|
onSearchProp = _a.onSearch,
|
89
|
+
onItemCreate = _a.onItemCreate,
|
90
|
+
creatableInSearch = _a.creatableInSearch,
|
88
91
|
_a$fieldNames = _a.fieldNames,
|
89
92
|
fieldNames = _a$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _a$fieldNames,
|
90
93
|
_a$checkedOnEntered = _a.checkedOnEntered,
|
@@ -98,10 +101,11 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
98
101
|
onKeyDownProp = _a.onKeyDown,
|
99
102
|
keywordProp = _a.keyword,
|
100
103
|
label = _a.label,
|
101
|
-
rest = tslib.__rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "showCheckAll", "showOnlyShowChecked", "placeholder", "displayRender", "onSelect", "height", "itemHeight", "virtual", "visible", "onOpen", "onClose", "onClear", "appearance", "invalid", "dataSource", "searchOnInit", "filterOption", "searchable", "render", "renderExtraFooter", "onSearch", "fieldNames", "checkedOnEntered", "customRender", "tagInputProps", "size", "prefix", "suffix", "onKeyDown", "keyword", "label"]);
|
104
|
+
rest = tslib.__rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "showCheckAll", "showOnlyShowChecked", "placeholder", "displayRender", "onSelect", "height", "itemHeight", "virtual", "visible", "onOpen", "onClose", "onClear", "appearance", "invalid", "dataSource", "searchOnInit", "filterOption", "searchable", "render", "renderExtraFooter", "onSearch", "onItemCreate", "creatableInSearch", "fieldNames", "checkedOnEntered", "customRender", "tagInputProps", "size", "prefix", "suffix", "onKeyDown", "keyword", "label"]);
|
102
105
|
var i18n = core.useLocaleContext();
|
103
106
|
var placeholder = typeAssertion.isUndef(placeholderProp) ? i18n.get('checkSelect.placeholder') : placeholderProp;
|
104
107
|
// ************************** Picker ************************* //
|
108
|
+
var innerRef = React.useRef(null);
|
105
109
|
var _useUncontrolledToggl = useToggle.useUncontrolledToggle({
|
106
110
|
visible: visible,
|
107
111
|
disabled: disabled,
|
@@ -260,12 +264,29 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
260
264
|
var handleKeyDown = useLatest.useLatestCallback(function (evt) {
|
261
265
|
var key = evt.key;
|
262
266
|
if (key === 'Enter' && checkedOnEntered) {
|
267
|
+
if (creatableInSearch && showData.length === 0) {
|
268
|
+
handleCreate(searchValue);
|
269
|
+
return;
|
270
|
+
}
|
263
271
|
var focusedItem = showData[focusedIndex];
|
264
272
|
if (focusedItem) {
|
265
273
|
onSelect(focusedItem, !isCheckedId(focusedItem.id));
|
266
274
|
}
|
267
275
|
}
|
268
276
|
});
|
277
|
+
var handleCreate = useLatest.useLatestCallback(function (keyword) {
|
278
|
+
var _a;
|
279
|
+
var id = keyword + "-" + useId.uuid();
|
280
|
+
var createdItem = {
|
281
|
+
id: id,
|
282
|
+
title: keyword
|
283
|
+
};
|
284
|
+
onSelect(createdItem, true);
|
285
|
+
onItemCreate === null || onItemCreate === void 0 ? void 0 : onItemCreate(createdItem);
|
286
|
+
// 创建后重置搜索和关闭弹窗
|
287
|
+
(_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.resetSearch();
|
288
|
+
menuVisibleAction.off();
|
289
|
+
});
|
269
290
|
// 更新 focused 索引
|
270
291
|
React.useEffect(function () {
|
271
292
|
setFocusedIndex(defaultIndex);
|
@@ -303,6 +324,7 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
303
324
|
value: context$1
|
304
325
|
}, /*#__PURE__*/React__default["default"].createElement(picker.Picker, Object.assign({
|
305
326
|
ref: ref,
|
327
|
+
innerRef: innerRef,
|
306
328
|
className: cls
|
307
329
|
}, rootProps, {
|
308
330
|
visible: menuVisible,
|
@@ -316,6 +338,8 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
316
338
|
onSearch: funcUtils.callAllFuncs(onSearchProp, onSearch),
|
317
339
|
loading: rest.loading !== undefined ? rest.loading : loading,
|
318
340
|
footer: renderDefaultFooter(),
|
341
|
+
creatableInSearch: creatableInSearch,
|
342
|
+
onCreate: handleCreate,
|
319
343
|
trigger: customRender ? typeof customRender === 'function' ? customRender(mergedCheckedItems) : customRender : ( /*#__PURE__*/React__default["default"].createElement(tagInput.TagInputMock, Object.assign({
|
320
344
|
style: {
|
321
345
|
maxWidth: appearance === 'contained' ? '360px' : undefined
|
@@ -12,7 +12,7 @@
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
var css_248z = ".hi-v5-check-select-option {-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-v5-border-radius-
|
15
|
+
var css_248z = ".hi-v5-check-select-option {-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-v5-border-radius-md, 4px);cursor: pointer;font-size: var(--hi-v5-text-size-md, 0.875rem);font-weight: var(--hi-v5-text-weight-normal, 400);color: var(--hi-v5-color-gray-700, #1a1d26);line-height: var(--hi-v5-text-lineheight-sm, 1.25rem);}.hi-v5-check-select-option__indent {display: inline-block;width: 16px;height: 100%;}.hi-v5-check-select-option__title {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;-webkit-box-sizing: border-box;box-sizing: border-box;width: 100%;padding: var(--hi-v5-spacing-3, 6px) var(--hi-v5-spacing-3, 6px);font-size: inherit;-webkit-text-size-adjust: none;-moz-text-size-adjust: none;-ms-text-size-adjust: none;text-size-adjust: none;font-weight: inherit;color: inherit;line-height: inherit;}.hi-v5-check-select-option:hover {background-color: var(--hi-v5-color-gray-100, #ebeff5);}.hi-v5-check-select-option--focused {background-color: var(--hi-v5-color-gray-100, #ebeff5);}.hi-v5-check-select-option--disabled {cursor: not-allowed;color: var(--hi-v5-color-gray-500, #737680);}.hi-v5-check-select-option-group {display: inline-block;margin-top: var(--hi-v5-spacing-6, 12px);margin-bottom: var(--hi-v5-spacing-2, 4px);padding: var(--hi-v5-spacing-3, 6px) 0 var(--hi-v5-spacing-3, 6px) var(--hi-v5-spacing-3, 6px);font-size: var(--hi-v5-text-size-md, 0.875rem);font-weight: var(--hi-v5-text-weight-normal, 400);color: var(--hi-v5-color-gray-500, #737680);line-height: var(--hi-v5-text-lineheight-sm, 1.25rem);}.hi-v5-check-select-option-group:first-child {margin-top: var(--hi-v5-spacing-2, 4px);}";
|
16
16
|
var __styleInject__ = require('@hi-ui/style-inject')["default"];
|
17
17
|
__styleInject__(css_248z);
|
18
18
|
exports["default"] = css_248z;
|
package/lib/esm/CheckSelect.js
CHANGED
@@ -8,7 +8,7 @@
|
|
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, useMemo, useState, useEffect
|
11
|
+
import React, { forwardRef, useRef, useCallback, useMemo, useState, useEffect } 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';
|
@@ -30,6 +30,7 @@ import { useAsyncSearch, useTreeCustomSearch, useFilterSearch, useSearchMode } f
|
|
30
30
|
import '@hi-ui/use-children';
|
31
31
|
import { flattenData } from './hooks/use-flatten-data.js';
|
32
32
|
import { getAllCheckedStatus, isCheckableOption, isOption } from './utils/index.js';
|
33
|
+
import { uuid } from '@hi-ui/use-id';
|
33
34
|
var _role = 'check-select';
|
34
35
|
var _prefix = getPrefixCls(_role);
|
35
36
|
var DEFAULT_FIELD_NAMES = {};
|
@@ -71,6 +72,8 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
71
72
|
titleRender = _a.render,
|
72
73
|
renderExtraFooter = _a.renderExtraFooter,
|
73
74
|
onSearchProp = _a.onSearch,
|
75
|
+
onItemCreate = _a.onItemCreate,
|
76
|
+
creatableInSearch = _a.creatableInSearch,
|
74
77
|
_a$fieldNames = _a.fieldNames,
|
75
78
|
fieldNames = _a$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _a$fieldNames,
|
76
79
|
_a$checkedOnEntered = _a.checkedOnEntered,
|
@@ -84,10 +87,11 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
84
87
|
onKeyDownProp = _a.onKeyDown,
|
85
88
|
keywordProp = _a.keyword,
|
86
89
|
label = _a.label,
|
87
|
-
rest = __rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "showCheckAll", "showOnlyShowChecked", "placeholder", "displayRender", "onSelect", "height", "itemHeight", "virtual", "visible", "onOpen", "onClose", "onClear", "appearance", "invalid", "dataSource", "searchOnInit", "filterOption", "searchable", "render", "renderExtraFooter", "onSearch", "fieldNames", "checkedOnEntered", "customRender", "tagInputProps", "size", "prefix", "suffix", "onKeyDown", "keyword", "label"]);
|
90
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "children", "disabled", "clearable", "showCheckAll", "showOnlyShowChecked", "placeholder", "displayRender", "onSelect", "height", "itemHeight", "virtual", "visible", "onOpen", "onClose", "onClear", "appearance", "invalid", "dataSource", "searchOnInit", "filterOption", "searchable", "render", "renderExtraFooter", "onSearch", "onItemCreate", "creatableInSearch", "fieldNames", "checkedOnEntered", "customRender", "tagInputProps", "size", "prefix", "suffix", "onKeyDown", "keyword", "label"]);
|
88
91
|
var i18n = useLocaleContext();
|
89
92
|
var placeholder = isUndef(placeholderProp) ? i18n.get('checkSelect.placeholder') : placeholderProp;
|
90
93
|
// ************************** Picker ************************* //
|
94
|
+
var innerRef = useRef(null);
|
91
95
|
var _useUncontrolledToggl = useUncontrolledToggle({
|
92
96
|
visible: visible,
|
93
97
|
disabled: disabled,
|
@@ -246,12 +250,29 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
246
250
|
var handleKeyDown = useLatestCallback(function (evt) {
|
247
251
|
var key = evt.key;
|
248
252
|
if (key === 'Enter' && checkedOnEntered) {
|
253
|
+
if (creatableInSearch && showData.length === 0) {
|
254
|
+
handleCreate(searchValue);
|
255
|
+
return;
|
256
|
+
}
|
249
257
|
var focusedItem = showData[focusedIndex];
|
250
258
|
if (focusedItem) {
|
251
259
|
onSelect(focusedItem, !isCheckedId(focusedItem.id));
|
252
260
|
}
|
253
261
|
}
|
254
262
|
});
|
263
|
+
var handleCreate = useLatestCallback(function (keyword) {
|
264
|
+
var _a;
|
265
|
+
var id = keyword + "-" + uuid();
|
266
|
+
var createdItem = {
|
267
|
+
id: id,
|
268
|
+
title: keyword
|
269
|
+
};
|
270
|
+
onSelect(createdItem, true);
|
271
|
+
onItemCreate === null || onItemCreate === void 0 ? void 0 : onItemCreate(createdItem);
|
272
|
+
// 创建后重置搜索和关闭弹窗
|
273
|
+
(_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.resetSearch();
|
274
|
+
menuVisibleAction.off();
|
275
|
+
});
|
255
276
|
// 更新 focused 索引
|
256
277
|
useEffect(function () {
|
257
278
|
setFocusedIndex(defaultIndex);
|
@@ -289,6 +310,7 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
289
310
|
value: context
|
290
311
|
}, /*#__PURE__*/React.createElement(Picker, Object.assign({
|
291
312
|
ref: ref,
|
313
|
+
innerRef: innerRef,
|
292
314
|
className: cls
|
293
315
|
}, rootProps, {
|
294
316
|
visible: menuVisible,
|
@@ -302,6 +324,8 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
302
324
|
onSearch: callAllFuncs(onSearchProp, onSearch),
|
303
325
|
loading: rest.loading !== undefined ? rest.loading : loading,
|
304
326
|
footer: renderDefaultFooter(),
|
327
|
+
creatableInSearch: creatableInSearch,
|
328
|
+
onCreate: handleCreate,
|
305
329
|
trigger: customRender ? typeof customRender === 'function' ? customRender(mergedCheckedItems) : customRender : ( /*#__PURE__*/React.createElement(TagInputMock, Object.assign({
|
306
330
|
style: {
|
307
331
|
maxWidth: appearance === 'contained' ? '360px' : undefined
|
@@ -8,6 +8,6 @@
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
9
9
|
*/
|
10
10
|
import __styleInject__ from '@hi-ui/style-inject';
|
11
|
-
var css_248z = ".hi-v5-check-select-option {-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-v5-border-radius-
|
11
|
+
var css_248z = ".hi-v5-check-select-option {-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-v5-border-radius-md, 4px);cursor: pointer;font-size: var(--hi-v5-text-size-md, 0.875rem);font-weight: var(--hi-v5-text-weight-normal, 400);color: var(--hi-v5-color-gray-700, #1a1d26);line-height: var(--hi-v5-text-lineheight-sm, 1.25rem);}.hi-v5-check-select-option__indent {display: inline-block;width: 16px;height: 100%;}.hi-v5-check-select-option__title {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;-webkit-box-sizing: border-box;box-sizing: border-box;width: 100%;padding: var(--hi-v5-spacing-3, 6px) var(--hi-v5-spacing-3, 6px);font-size: inherit;-webkit-text-size-adjust: none;-moz-text-size-adjust: none;-ms-text-size-adjust: none;text-size-adjust: none;font-weight: inherit;color: inherit;line-height: inherit;}.hi-v5-check-select-option:hover {background-color: var(--hi-v5-color-gray-100, #ebeff5);}.hi-v5-check-select-option--focused {background-color: var(--hi-v5-color-gray-100, #ebeff5);}.hi-v5-check-select-option--disabled {cursor: not-allowed;color: var(--hi-v5-color-gray-500, #737680);}.hi-v5-check-select-option-group {display: inline-block;margin-top: var(--hi-v5-spacing-6, 12px);margin-bottom: var(--hi-v5-spacing-2, 4px);padding: var(--hi-v5-spacing-3, 6px) 0 var(--hi-v5-spacing-3, 6px) var(--hi-v5-spacing-3, 6px);font-size: var(--hi-v5-text-size-md, 0.875rem);font-weight: var(--hi-v5-text-weight-normal, 400);color: var(--hi-v5-color-gray-500, #737680);line-height: var(--hi-v5-text-lineheight-sm, 1.25rem);}.hi-v5-check-select-option-group:first-child {margin-top: var(--hi-v5-spacing-2, 4px);}";
|
12
12
|
__styleInject__(css_248z);
|
13
13
|
export { css_248z as default };
|
@@ -122,6 +122,14 @@ export interface CheckSelectProps extends Omit<PickerProps, 'trigger' | 'scrolla
|
|
122
122
|
* TagInput 参数设置
|
123
123
|
*/
|
124
124
|
tagInputProps?: TagInputMockProps;
|
125
|
+
/**
|
126
|
+
* 是否开启创建选项
|
127
|
+
*/
|
128
|
+
creatableInSearch?: boolean;
|
129
|
+
/**
|
130
|
+
* 创建选项时触发
|
131
|
+
*/
|
132
|
+
onItemCreate?: (item: CheckSelectMergedItem) => void;
|
125
133
|
}
|
126
134
|
export declare const CheckSelectOption: React.ForwardRefExoticComponent<Pick<CheckSelectOptionProps, string | number> & React.RefAttributes<HTMLDivElement | null>>;
|
127
135
|
export interface CheckSelectOptionProps extends HiBaseHTMLProps {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hi-ui/check-select",
|
3
|
-
"version": "5.0.0-canary.
|
3
|
+
"version": "5.0.0-canary.3",
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
5
5
|
"keywords": [],
|
6
6
|
"author": "HiUI <mi-hiui@xiaomi.com>",
|
@@ -53,15 +53,16 @@
|
|
53
53
|
"@hi-ui/highlighter": "^5.0.0-canary.0",
|
54
54
|
"@hi-ui/icons": "^5.0.0-canary.0",
|
55
55
|
"@hi-ui/input": "^5.0.0-canary.2",
|
56
|
-
"@hi-ui/picker": "^5.0.0-canary.
|
57
|
-
"@hi-ui/popper": "^5.0.0-canary.
|
58
|
-
"@hi-ui/tag-input": "^5.0.0-canary.
|
56
|
+
"@hi-ui/picker": "^5.0.0-canary.3",
|
57
|
+
"@hi-ui/popper": "^5.0.0-canary.1",
|
58
|
+
"@hi-ui/tag-input": "^5.0.0-canary.4",
|
59
59
|
"@hi-ui/times": "^5.0.0-canary.0",
|
60
60
|
"@hi-ui/tree-utils": "^5.0.0-canary.0",
|
61
61
|
"@hi-ui/type-assertion": "^5.0.0-canary.0",
|
62
62
|
"@hi-ui/use-check": "^5.0.0-canary.0",
|
63
63
|
"@hi-ui/use-children": "^5.0.0-canary.0",
|
64
64
|
"@hi-ui/use-data-source": "^5.0.0-canary.0",
|
65
|
+
"@hi-ui/use-id": "^5.0.0-canary.0",
|
65
66
|
"@hi-ui/use-latest": "^5.0.0-canary.0",
|
66
67
|
"@hi-ui/use-search-mode": "^5.0.0-canary.0",
|
67
68
|
"@hi-ui/use-toggle": "^5.0.0-canary.0",
|
@@ -75,7 +76,7 @@
|
|
75
76
|
},
|
76
77
|
"devDependencies": {
|
77
78
|
"@hi-ui/core": "^5.0.0-canary.0",
|
78
|
-
"@hi-ui/core-css": "^5.0.0-canary.
|
79
|
+
"@hi-ui/core-css": "^5.0.0-canary.2",
|
79
80
|
"react": "^17.0.1",
|
80
81
|
"react-dom": "^17.0.1"
|
81
82
|
}
|