@hi-ui/cascader 4.0.0-beta.7 → 4.0.0
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/lib/cjs/Cascader.js +51 -151
- package/lib/cjs/CascaderMenuList.js +172 -0
- package/lib/cjs/context.js +1 -2
- package/lib/cjs/hooks/use-async-switch.js +5 -6
- package/lib/cjs/hooks/use-cache/lib/esm/index.js +2 -3
- package/lib/cjs/hooks/use-select.js +1 -2
- package/lib/cjs/icons/index.js +4 -5
- package/lib/cjs/index.js +1 -4
- package/lib/cjs/styles/index.scss.js +3 -4
- package/lib/cjs/use-cascader.js +3 -3
- package/lib/cjs/utils/index.js +30 -2
- package/lib/esm/Cascader.js +38 -140
- package/lib/esm/CascaderMenuList.js +146 -0
- package/lib/esm/context.js +1 -2
- package/lib/esm/hooks/use-async-switch.js +1 -2
- package/lib/esm/hooks/use-cache/lib/esm/index.js +2 -3
- package/lib/esm/hooks/use-select.js +1 -2
- package/lib/esm/icons/index.js +1 -2
- package/lib/esm/index.js +2 -3
- package/lib/esm/styles/index.scss.js +4 -6
- package/lib/esm/use-cascader.js +3 -3
- package/lib/esm/utils/index.js +30 -3
- package/lib/types/Cascader.d.ts +6 -12
- package/lib/types/CascaderMenuList.d.ts +13 -0
- package/lib/types/context.d.ts +7 -7
- package/lib/types/hooks/use-select.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/types.d.ts +15 -18
- package/lib/types/use-cascader.d.ts +6 -7
- package/lib/types/utils/index.d.ts +8 -7
- package/package.json +25 -22
- package/lib/cjs/Cascader.js.map +0 -1
- package/lib/cjs/context.js.map +0 -1
- package/lib/cjs/hooks/use-async-switch.js.map +0 -1
- package/lib/cjs/hooks/use-cache/lib/esm/index.js.map +0 -1
- package/lib/cjs/hooks/use-select.js.map +0 -1
- package/lib/cjs/icons/index.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-cascader.js.map +0 -1
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/esm/Cascader.js.map +0 -1
- package/lib/esm/context.js.map +0 -1
- package/lib/esm/hooks/use-async-switch.js.map +0 -1
- package/lib/esm/hooks/use-cache/lib/esm/index.js.map +0 -1
- package/lib/esm/hooks/use-select.js.map +0 -1
- package/lib/esm/icons/index.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-cascader.js.map +0 -1
- package/lib/esm/utils/index.js.map +0 -1
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -12,11 +12,10 @@
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
var css_248z = "
|
15
|
+
var css_248z = ".hi-v4-cascader__popper .hi-v4-picker__body {padding-left: 0;padding-right: 0;overflow-y: hidden; }.hi-v4-cascader__popper .hi-v4-picker__loading, .hi-v4-cascader__popper .hi-v4-picker__empty {padding: var(--hi-v4-spacing-5, 10px) var(--hi-v4-spacing-8, 16px); }.hi-v4-cascader-panel {white-space: nowrap;-webkit-box-sizing: border-box;box-sizing: border-box;font-size: var(--hi-v4-text-size-md, 0.875rem);color: var(--hi-v4-color-gray-700, #1f2733); }.hi-v4-cascader-search {-webkit-box-sizing: border-box;box-sizing: border-box;padding: 0 10px 10px;position: relative; }.hi-v4-cascader-search .hi-v4-input__prefix {font-size: 16px;padding-left: 0; }.hi-v4-cascader-search__empty {display: inline-block;margin-top: 20px;font-size: 14px;font-weight: 400;color: #999;line-height: 20px; }.hi-v4-cascader-menu-list {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-sizing: border-box;box-sizing: border-box;overflow-x: auto; }.hi-v4-cascader-menu-list--flatted .hi-v4-cascader-menu {-ms-flex-preferred-size: 100%;flex-basis: 100%; }.hi-v4-cascader-menu {-webkit-box-sizing: border-box;box-sizing: border-box;margin: 0;padding: 0;border: none;outline: none;font-size: var(--hi-v4-text-size-md, 0.875rem);vertical-align: middle;list-style: none;width: auto;box-sizing: border-box;-ms-flex-negative: 0;flex-shrink: 0;display: inline-block;min-width: 140px;max-height: 260px;overflow: auto;padding: 4px 8px;border-right: var(--hi-v4-border-size-normal, 1px solid) var(--hi-v4-color-gray-200, #ebedf0); }.hi-v4-cascader-menu:last-of-type {border: none; }.hi-v4-cascader-menu-item {width: 100%;padding: var(--hi-v4-spacing-2, 4px) 0;position: relative;cursor: pointer;display: -webkit-box;display: -ms-flexbox;display: flex; }.hi-v4-cascader-menu-option {padding: 0 var(--hi-v4-spacing-4, 8px);-webkit-box-sizing: border-box;box-sizing: border-box;height: 32px;width: 100%;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;position: relative;-webkit-box-pack: justify;-ms-flex-pack: justify;justify-content: space-between;border-radius: var(--hi-v4-border-radius-md, 4px); }.hi-v4-cascader-menu-option:hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--selected {background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe));color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--selected .hi-v4-cascader-menu-switcher {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-cascader-menu-option--focused {background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-cascader-menu-option--checked {font-weight: 700; }.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--disabled {cursor: not-allowed;color: var(--hi-v4-color-gray-500, #929aa6);background: transparent; }.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--disabled .hi-v4-cascader-menu-switcher {color: var(--hi-v4-color-gray-400, #c9ced6); }.hi-v4-cascader-menu .title__text {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1; }.hi-v4-cascader-menu .title__text--cols {display: block;width: 100%;-webkit-box-sizing: border-box;box-sizing: border-box;margin: 0;padding: 0;border: none;outline: none;font-size: var(--hi-v4-text-size-md, 0.875rem);vertical-align: middle;list-style: none; }.hi-v4-cascader-menu .title__text--col {display: inline-block; }.hi-v4-cascader-menu .title__text--col::after {content: '\\00a0/\\00a0'; }.hi-v4-cascader-menu .title__text--col:last-child::after {content: none; }.hi-v4-cascader-menu .title__text--matched {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-cascader-menu-switcher {-ms-flex-negative: 0;flex-shrink: 0;font-size: 16px;color: var(--hi-v4-color-gray-500, #929aa6); }.hi-v4-cascader-menu-switcher--loading {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-cascader-menu-switcher--arrow {-webkit-transform: rotate(-90deg);transform: rotate(-90deg); }.hi-v4-cascader__icon--loading {display: inline-block;width: 1em;height: 1em;stroke: none;cursor: default;fill: currentColor; }.hi-v4-cascader__icon--loading svg {-webkit-animation-name: hi-rotate;animation-name: hi-rotate;-webkit-animation-duration: 2s;animation-duration: 2s;-webkit-animation-iteration-count: infinite;animation-iteration-count: infinite; }@-webkit-keyframes rotate {to {-webkit-transform: rotate(360deg);transform: rotate(360deg); } }@keyframes rotate {to {-webkit-transform: rotate(360deg);transform: rotate(360deg); } }";
|
16
16
|
|
17
|
-
var __styleInject__ = require('
|
17
|
+
var __styleInject__ = require('inject-head-style')["default"];
|
18
18
|
|
19
19
|
__styleInject__(css_248z);
|
20
20
|
|
21
21
|
exports["default"] = css_248z;
|
22
|
-
//# sourceMappingURL=index.scss.js.map
|
package/lib/cjs/use-cascader.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -105,12 +105,13 @@ var useCascader = function useCascader(_a) {
|
|
105
105
|
var id = _ref3.id,
|
106
106
|
depth = _ref3.depth;
|
107
107
|
return {
|
108
|
+
active: value[depth] === id,
|
108
109
|
selected: flatted ? selectedId === id : selectedIds[depth] === id,
|
109
110
|
loading: isLoadingId(id),
|
110
111
|
// TODO: 表示聚焦状态,添加快捷键时可以一起处理
|
111
112
|
focused: false
|
112
113
|
};
|
113
|
-
}, [flatted, selectedId, selectedIds, isLoadingId]);
|
114
|
+
}, [flatted, selectedId, selectedIds, isLoadingId, value]);
|
114
115
|
var reset = React.useCallback(function () {
|
115
116
|
setSelectedId(value[value.length - 1]);
|
116
117
|
}, [setSelectedId, value]);
|
@@ -132,4 +133,3 @@ var useCascader = function useCascader(_a) {
|
|
132
133
|
};
|
133
134
|
|
134
135
|
exports.useCascader = useCascader;
|
135
|
-
//# sourceMappingURL=use-cascader.js.map
|
package/lib/cjs/utils/index.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -110,10 +110,38 @@ function getItemEventData(node, requiredProps) {
|
|
110
110
|
return Object.assign(Object.assign({}, node), requiredProps);
|
111
111
|
}
|
112
112
|
|
113
|
+
var getFilteredMenuList = function getFilteredMenuList(menuList, searchedData) {
|
114
|
+
var result = [];
|
115
|
+
searchedData.forEach(function (item) {
|
116
|
+
while (item && item.depth >= 0) {
|
117
|
+
var depth = item.depth;
|
118
|
+
var depthResult = result[depth];
|
119
|
+
|
120
|
+
if (!depthResult) {
|
121
|
+
depthResult = new Map();
|
122
|
+
result[depth] = depthResult;
|
123
|
+
}
|
124
|
+
|
125
|
+
depthResult.set(item.id, item);
|
126
|
+
item = item.parent;
|
127
|
+
}
|
128
|
+
});
|
129
|
+
return menuList.map(function (depthItems, depth) {
|
130
|
+
var depthSavedMp = result[depth];
|
131
|
+
if (!depthSavedMp) return depthItems;
|
132
|
+
return depthItems.filter(function (item) {
|
133
|
+
var depthSavedMp = result[item.depth];
|
134
|
+
if (!depthSavedMp) return true;
|
135
|
+
if (depthSavedMp.has(item.id)) return true;
|
136
|
+
return false;
|
137
|
+
});
|
138
|
+
});
|
139
|
+
};
|
140
|
+
|
113
141
|
exports.checkCanLoadChildren = checkCanLoadChildren;
|
114
142
|
exports.flattenTreeData = flattenTreeData;
|
115
143
|
exports.getActiveMenus = getActiveMenus;
|
116
144
|
exports.getActiveNodePaths = getActiveNodePaths;
|
145
|
+
exports.getFilteredMenuList = getFilteredMenuList;
|
117
146
|
exports.getFlattedMenus = getFlattedMenus;
|
118
147
|
exports.getItemEventData = getItemEventData;
|
119
|
-
//# sourceMappingURL=index.js.map
|
package/lib/esm/Cascader.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -15,16 +15,18 @@ import { useUncontrolledToggle } from '@hi-ui/use-toggle';
|
|
15
15
|
import { useCascader } from './use-cascader.js';
|
16
16
|
import { MockInput } from '@hi-ui/input';
|
17
17
|
import { UpOutlined, DownOutlined } from '@hi-ui/icons';
|
18
|
-
import {
|
19
|
-
import {
|
20
|
-
import { CascaderProvider, useCascaderContext } from './context.js';
|
18
|
+
import { flattenTreeData, getFilteredMenuList, getItemEventData } from './utils/index.js';
|
19
|
+
import { CascaderProvider } from './context.js';
|
21
20
|
import { getTopDownAncestors, getNodeAncestorsWithMe } from '@hi-ui/tree-utils';
|
22
21
|
import { isUndef, isArrayNonEmpty, isFunction } from '@hi-ui/type-assertion';
|
23
22
|
import { Picker } from '@hi-ui/picker';
|
24
23
|
import { useTreeCustomSearch, useTreeUpMatchSearch, useSearchMode } from '@hi-ui/use-search-mode';
|
25
24
|
import { uniqBy } from '@hi-ui/array-utils';
|
26
25
|
import { useCache } from './hooks/use-cache/lib/esm/index.js';
|
27
|
-
import { useLocaleContext } from '@hi-ui/
|
26
|
+
import { useLocaleContext } from '@hi-ui/core';
|
27
|
+
import { callAllFuncs } from '@hi-ui/func-utils';
|
28
|
+
import { CascaderMenuList } from './CascaderMenuList.js';
|
29
|
+
import Highlighter from '@hi-ui/highlighter';
|
28
30
|
|
29
31
|
var _prefix = getPrefixCls('cascader');
|
30
32
|
|
@@ -55,19 +57,23 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
55
57
|
invalid = props.invalid,
|
56
58
|
filterOption = props.filterOption,
|
57
59
|
searchableProp = props.searchable,
|
60
|
+
onSearchProp = props.onSearch,
|
58
61
|
titleRender = props.render,
|
59
62
|
overlayClassName = props.overlayClassName,
|
60
63
|
_props$data = props.data,
|
61
64
|
data = _props$data === void 0 ? NOOP_ARRAY : _props$data,
|
65
|
+
_props$flattedSearchR = props.flattedSearchResult,
|
66
|
+
flattedSearchResult = _props$flattedSearchR === void 0 ? true : _props$flattedSearchR,
|
67
|
+
visible = props.visible,
|
62
68
|
onOpen = props.onOpen,
|
63
69
|
onClose = props.onClose,
|
64
|
-
rest = __rest(props, ["prefixCls", "className", "placeholder", "disabled", "clearable", "type", "fieldNames", "expandTrigger", "displayRender", "onSelect", "onLoadChildren", "appearance", "invalid", "filterOption", "searchable", "render", "overlayClassName", "data", "onOpen", "onClose"]);
|
70
|
+
rest = __rest(props, ["prefixCls", "className", "placeholder", "disabled", "clearable", "type", "fieldNames", "expandTrigger", "displayRender", "onSelect", "onLoadChildren", "appearance", "invalid", "filterOption", "searchable", "onSearch", "render", "overlayClassName", "data", "flattedSearchResult", "visible", "onOpen", "onClose"]);
|
65
71
|
|
66
72
|
var i18n = useLocaleContext();
|
67
73
|
var placeholder = isUndef(placeholderProp) ? i18n.get('cascader.placeholder') : placeholderProp;
|
68
|
-
var flatted = type === 'flatted';
|
69
74
|
|
70
75
|
var _useUncontrolledToggl = useUncontrolledToggle({
|
76
|
+
visible: visible,
|
71
77
|
disabled: disabled,
|
72
78
|
onOpen: onOpen,
|
73
79
|
onClose: onClose
|
@@ -93,7 +99,7 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
93
99
|
var highlight = !!searchValue && searchMode === 'upMatch';
|
94
100
|
|
95
101
|
if (highlight) {
|
96
|
-
return renderHighlightTitle(searchValue, node, titleRender);
|
102
|
+
return flattedSearchResult ? renderHighlightTitles(searchValue, node, titleRender) : renderHighlightTitle(searchValue, node, titleRender);
|
97
103
|
}
|
98
104
|
|
99
105
|
return isFunction(titleRender) ? titleRender(node) : true;
|
@@ -116,9 +122,12 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
116
122
|
data: cascaderData,
|
117
123
|
flattedData: flattedData,
|
118
124
|
enabled: searchableProp,
|
119
|
-
exclude: function exclude(
|
120
|
-
return
|
121
|
-
}
|
125
|
+
exclude: function exclude(node) {
|
126
|
+
return node.disabled;
|
127
|
+
} // exclude: (option: FlattedCascaderDataItem) => {
|
128
|
+
// return checkCanLoadChildren(option, onLoadChildren)
|
129
|
+
// },
|
130
|
+
|
122
131
|
});
|
123
132
|
|
124
133
|
var _useSearchMode = useSearchMode({
|
@@ -156,11 +165,14 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
156
165
|
}, mergedTitle);
|
157
166
|
};
|
158
167
|
|
168
|
+
var shouldUseSearch = !!searchValue; // 搜索的结果列表也采用 flatted 模式进行展示
|
169
|
+
|
170
|
+
var flatted = shouldUseSearch ? flattedSearchResult : type === 'flatted';
|
171
|
+
|
159
172
|
var _a = useCascader(Object.assign(Object.assign({}, rest), {
|
160
173
|
disabled: disabled,
|
161
174
|
fieldNames: fieldNames,
|
162
|
-
|
163
|
-
flatted: flatted || !!searchValue,
|
175
|
+
flatted: flatted,
|
164
176
|
onSelect: onSelect,
|
165
177
|
onLoadChildren: onLoadChildren,
|
166
178
|
data: data,
|
@@ -177,14 +189,17 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
177
189
|
reset = context.reset,
|
178
190
|
menuList = context.menuList,
|
179
191
|
getItemRequiredProps = context.getItemRequiredProps;
|
180
|
-
var shouldUseSearch = !!searchValue;
|
181
192
|
var showData = useMemo(function () {
|
182
193
|
if (shouldUseSearch) {
|
194
|
+
if (!flattedSearchResult) {
|
195
|
+
return getFilteredMenuList(menuList, stateInSearch.data);
|
196
|
+
}
|
197
|
+
|
183
198
|
return isArrayNonEmpty(stateInSearch.data) ? [stateInSearch.data] : [];
|
184
199
|
}
|
185
200
|
|
186
201
|
return menuList;
|
187
|
-
}, [shouldUseSearch, stateInSearch.data, menuList]);
|
202
|
+
}, [shouldUseSearch, flattedSearchResult, stateInSearch.data, menuList]);
|
188
203
|
useEffect(function () {
|
189
204
|
// 关闭展示后,重置展开要高亮的选项
|
190
205
|
if (!menuVisible) {
|
@@ -221,7 +236,7 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
221
236
|
onOpen: menuVisibleAction.on,
|
222
237
|
onClose: menuVisibleAction.off,
|
223
238
|
searchable: searchable,
|
224
|
-
onSearch: onSearch,
|
239
|
+
onSearch: callAllFuncs(onSearchProp, onSearch),
|
225
240
|
trigger: /*#__PURE__*/React.createElement(MockInput, {
|
226
241
|
clearable: clearable,
|
227
242
|
placeholder: placeholder,
|
@@ -243,133 +258,17 @@ if (__DEV__) {
|
|
243
258
|
Cascader.displayName = 'Cascader';
|
244
259
|
}
|
245
260
|
|
246
|
-
var
|
247
|
-
var CascaderMenuList = /*#__PURE__*/forwardRef(function (_a, ref) {
|
248
|
-
var _a$prefixCls = _a.prefixCls,
|
249
|
-
prefixCls = _a$prefixCls === void 0 ? menuListPrefix : _a$prefixCls,
|
250
|
-
className = _a.className,
|
251
|
-
rest = __rest(_a, ["prefixCls", "className"]);
|
252
|
-
|
253
|
-
var _useCascaderContext = useCascaderContext(),
|
254
|
-
flatted = _useCascaderContext.flatted,
|
255
|
-
menuList = _useCascaderContext.menuList;
|
256
|
-
|
257
|
-
var cls = cx(prefixCls, className, flatted && prefixCls + "--flatted");
|
258
|
-
return /*#__PURE__*/React.createElement("div", Object.assign({
|
259
|
-
ref: ref,
|
260
|
-
className: cls
|
261
|
-
}, rest), menuList.map(function (menu, menuIndex) {
|
262
|
-
// @ts-ignore
|
263
|
-
return isArrayNonEmpty(menu) ? /*#__PURE__*/React.createElement(CascaderMenu, {
|
264
|
-
key: menuIndex,
|
265
|
-
data: menu
|
266
|
-
}) : null;
|
267
|
-
}));
|
268
|
-
});
|
269
|
-
|
270
|
-
if (__DEV__) {
|
271
|
-
CascaderMenuList.displayName = 'CascaderMenuList';
|
272
|
-
}
|
273
|
-
|
274
|
-
var menuPrefix = getPrefixCls('cascader-menu');
|
275
|
-
|
276
|
-
var CascaderMenu = function CascaderMenu(_ref2) {
|
277
|
-
var _ref2$prefixCls = _ref2.prefixCls,
|
278
|
-
prefixCls = _ref2$prefixCls === void 0 ? menuPrefix : _ref2$prefixCls,
|
279
|
-
_ref2$role = _ref2.role,
|
280
|
-
role = _ref2$role === void 0 ? 'menu' : _ref2$role,
|
281
|
-
className = _ref2.className,
|
282
|
-
menu = _ref2.data;
|
283
|
-
|
284
|
-
var _useCascaderContext2 = useCascaderContext(),
|
285
|
-
flatted = _useCascaderContext2.flatted,
|
286
|
-
disabledContext = _useCascaderContext2.disabled,
|
287
|
-
expandTrigger = _useCascaderContext2.expandTrigger,
|
288
|
-
onItemClick = _useCascaderContext2.onItemClick,
|
289
|
-
onItemHover = _useCascaderContext2.onItemHover,
|
290
|
-
titleRender = _useCascaderContext2.titleRender,
|
291
|
-
onLoadChildren = _useCascaderContext2.onLoadChildren,
|
292
|
-
getItemRequiredProps = _useCascaderContext2.getItemRequiredProps;
|
293
|
-
|
294
|
-
var cls = cx(prefixCls, className);
|
295
|
-
return /*#__PURE__*/React.createElement("ul", {
|
296
|
-
className: cls,
|
297
|
-
role: role
|
298
|
-
}, menu.map(function (option) {
|
299
|
-
var eventOption = getItemEventData(option, getItemRequiredProps(option));
|
300
|
-
var selected = eventOption.selected,
|
301
|
-
loading = eventOption.loading;
|
302
|
-
var disabled = disabledContext || option.disabled;
|
303
|
-
var optionCls = cx(prefixCls + "-option", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
|
304
|
-
return /*#__PURE__*/React.createElement("li", {
|
305
|
-
key: option.id,
|
306
|
-
role: "menu-item",
|
307
|
-
className: prefixCls + "-item"
|
308
|
-
}, /*#__PURE__*/React.createElement("div", {
|
309
|
-
className: optionCls,
|
310
|
-
onClick: function onClick() {
|
311
|
-
if (disabled) return;
|
312
|
-
onItemClick(eventOption);
|
313
|
-
},
|
314
|
-
onMouseEnter: function onMouseEnter() {
|
315
|
-
if (disabled) return;
|
316
|
-
|
317
|
-
if (expandTrigger === 'hover') {
|
318
|
-
onItemHover(eventOption);
|
319
|
-
}
|
320
|
-
}
|
321
|
-
}, flatted ? renderFlattedTitle(eventOption, titleRender) : /*#__PURE__*/React.createElement(React.Fragment, null, renderDefaultTitle(eventOption, titleRender), renderSuffix(prefixCls, option, loading, onLoadChildren))));
|
322
|
-
}));
|
323
|
-
};
|
324
|
-
/**
|
325
|
-
* 渲染菜单子项的展开提示图标
|
326
|
-
*/
|
327
|
-
|
328
|
-
|
329
|
-
var renderSuffix = function renderSuffix(prefixCls, item, loading, onLoadChildren) {
|
330
|
-
if (loading) {
|
331
|
-
return /*#__PURE__*/React.createElement("span", {
|
332
|
-
className: cx(prefixCls + "-switcher", prefixCls + "-switcher--loading")
|
333
|
-
}, defaultLoadingIcon);
|
334
|
-
}
|
335
|
-
|
336
|
-
var canLoadChildren = checkCanLoadChildren(item, onLoadChildren);
|
337
|
-
|
338
|
-
if (canLoadChildren) {
|
339
|
-
return /*#__PURE__*/React.createElement("span", {
|
340
|
-
className: cx(prefixCls + "-switcher", prefixCls + "-switcher--arrow")
|
341
|
-
}, defaultSuffixIcon);
|
342
|
-
}
|
343
|
-
|
344
|
-
return /*#__PURE__*/React.createElement("span", {
|
345
|
-
className: cx(prefixCls + "-switcher", prefixCls + "-switcher--noop")
|
346
|
-
}, defaultLeafIcon);
|
347
|
-
};
|
348
|
-
|
349
|
-
var renderFlattedTitle = function renderFlattedTitle(option, titleRender) {
|
350
|
-
// 如果 titleRender 返回 `true`,则使用默认 title
|
351
|
-
var title = titleRender ? titleRender(option) : true;
|
352
|
-
if (title !== true) return title;
|
353
|
-
return /*#__PURE__*/React.createElement("span", {
|
354
|
-
className: "title__text title__text--cols"
|
355
|
-
}, getTopDownAncestors(option).map(function (item) {
|
356
|
-
return /*#__PURE__*/React.createElement("span", {
|
357
|
-
key: item.id,
|
358
|
-
className: "title__text--col"
|
359
|
-
}, item.title);
|
360
|
-
}));
|
361
|
-
};
|
362
|
-
|
363
|
-
var renderDefaultTitle = function renderDefaultTitle(option, titleRender) {
|
261
|
+
var renderHighlightTitle = function renderHighlightTitle(keyword, option, titleRender) {
|
364
262
|
// 如果 titleRender 返回 `true`,则使用默认 title
|
365
|
-
var title = titleRender ? titleRender(option) : true;
|
263
|
+
var title = titleRender ? titleRender(option, keyword) : true;
|
366
264
|
if (title !== true) return title;
|
367
|
-
return /*#__PURE__*/React.createElement(
|
368
|
-
|
265
|
+
return /*#__PURE__*/React.createElement(Highlighter, {
|
266
|
+
key: option.id,
|
267
|
+
keyword: keyword
|
369
268
|
}, option.title);
|
370
269
|
};
|
371
270
|
|
372
|
-
var
|
271
|
+
var renderHighlightTitles = function renderHighlightTitles(keyword, option, titleRender) {
|
373
272
|
// 如果 titleRender 返回 `true`,则使用默认 title
|
374
273
|
var title = titleRender ? titleRender(option, keyword) : true;
|
375
274
|
if (title !== true) return title;
|
@@ -405,5 +304,4 @@ var renderHighlightTitle = function renderHighlightTitle(keyword, option, titleR
|
|
405
304
|
}).reverse());
|
406
305
|
};
|
407
306
|
|
408
|
-
export { Cascader
|
409
|
-
//# sourceMappingURL=Cascader.js.map
|
307
|
+
export { Cascader };
|
@@ -0,0 +1,146 @@
|
|
1
|
+
/** @LICENSE
|
2
|
+
* @hi-ui/cascader
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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
|
+
import { __rest } from 'tslib';
|
11
|
+
import React, { forwardRef } from 'react';
|
12
|
+
import { getPrefixCls, cx } from '@hi-ui/classname';
|
13
|
+
import { __DEV__ } from '@hi-ui/env';
|
14
|
+
import { defaultLoadingIcon, defaultSuffixIcon, defaultLeafIcon } from './icons/index.js';
|
15
|
+
import { getItemEventData, checkCanLoadChildren } from './utils/index.js';
|
16
|
+
import { useCascaderContext } from './context.js';
|
17
|
+
import { getTopDownAncestors } from '@hi-ui/tree-utils';
|
18
|
+
import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
19
|
+
var menuListPrefix = getPrefixCls('cascader-menu-list');
|
20
|
+
var CascaderMenuList = /*#__PURE__*/forwardRef(function (_a, ref) {
|
21
|
+
var _a$prefixCls = _a.prefixCls,
|
22
|
+
prefixCls = _a$prefixCls === void 0 ? menuListPrefix : _a$prefixCls,
|
23
|
+
className = _a.className,
|
24
|
+
rest = __rest(_a, ["prefixCls", "className"]);
|
25
|
+
|
26
|
+
var _useCascaderContext = useCascaderContext(),
|
27
|
+
flatted = _useCascaderContext.flatted,
|
28
|
+
menuList = _useCascaderContext.menuList;
|
29
|
+
|
30
|
+
var cls = cx(prefixCls, className, flatted && prefixCls + "--flatted");
|
31
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
32
|
+
ref: ref,
|
33
|
+
className: cls
|
34
|
+
}, rest), menuList.map(function (menu, menuIndex) {
|
35
|
+
// @ts-ignore
|
36
|
+
return isArrayNonEmpty(menu) ? /*#__PURE__*/React.createElement(CascaderMenu, {
|
37
|
+
key: menuIndex,
|
38
|
+
data: menu
|
39
|
+
}) : null;
|
40
|
+
}));
|
41
|
+
});
|
42
|
+
|
43
|
+
if (__DEV__) {
|
44
|
+
CascaderMenuList.displayName = 'CascaderMenuList';
|
45
|
+
}
|
46
|
+
|
47
|
+
var menuPrefix = getPrefixCls('cascader-menu');
|
48
|
+
|
49
|
+
var CascaderMenu = function CascaderMenu(_ref) {
|
50
|
+
var _ref$prefixCls = _ref.prefixCls,
|
51
|
+
prefixCls = _ref$prefixCls === void 0 ? menuPrefix : _ref$prefixCls,
|
52
|
+
_ref$role = _ref.role,
|
53
|
+
role = _ref$role === void 0 ? 'menu' : _ref$role,
|
54
|
+
className = _ref.className,
|
55
|
+
menu = _ref.data;
|
56
|
+
|
57
|
+
var _useCascaderContext2 = useCascaderContext(),
|
58
|
+
flatted = _useCascaderContext2.flatted,
|
59
|
+
disabledContext = _useCascaderContext2.disabled,
|
60
|
+
expandTrigger = _useCascaderContext2.expandTrigger,
|
61
|
+
onItemClick = _useCascaderContext2.onItemClick,
|
62
|
+
onItemHover = _useCascaderContext2.onItemHover,
|
63
|
+
titleRender = _useCascaderContext2.titleRender,
|
64
|
+
onLoadChildren = _useCascaderContext2.onLoadChildren,
|
65
|
+
getItemRequiredProps = _useCascaderContext2.getItemRequiredProps;
|
66
|
+
|
67
|
+
var cls = cx(prefixCls, className);
|
68
|
+
return /*#__PURE__*/React.createElement("ul", {
|
69
|
+
className: cls,
|
70
|
+
role: role
|
71
|
+
}, menu.map(function (option) {
|
72
|
+
var eventOption = getItemEventData(option, getItemRequiredProps(option));
|
73
|
+
var selected = eventOption.selected,
|
74
|
+
loading = eventOption.loading,
|
75
|
+
active = eventOption.active;
|
76
|
+
var disabled = disabledContext || option.disabled;
|
77
|
+
var optionCls = cx(prefixCls + "-option", active && prefixCls + "-option--active", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
|
78
|
+
return /*#__PURE__*/React.createElement("li", {
|
79
|
+
key: option.id,
|
80
|
+
role: "menu-item",
|
81
|
+
className: prefixCls + "-item"
|
82
|
+
}, /*#__PURE__*/React.createElement("div", {
|
83
|
+
className: optionCls,
|
84
|
+
onClick: function onClick() {
|
85
|
+
if (disabled) return;
|
86
|
+
onItemClick(eventOption);
|
87
|
+
},
|
88
|
+
onMouseEnter: function onMouseEnter() {
|
89
|
+
if (disabled) return;
|
90
|
+
|
91
|
+
if (expandTrigger === 'hover') {
|
92
|
+
onItemHover(eventOption);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}, flatted ? renderFlattedTitle(eventOption, titleRender) : /*#__PURE__*/React.createElement(React.Fragment, null, renderDefaultTitle(eventOption, titleRender), renderSuffix(prefixCls, option, loading, onLoadChildren))));
|
96
|
+
}));
|
97
|
+
};
|
98
|
+
/**
|
99
|
+
* 渲染菜单子项的展开提示图标
|
100
|
+
*/
|
101
|
+
|
102
|
+
|
103
|
+
var renderSuffix = function renderSuffix(prefixCls, item, loading, onLoadChildren) {
|
104
|
+
if (loading) {
|
105
|
+
return /*#__PURE__*/React.createElement("span", {
|
106
|
+
className: cx(prefixCls + "-switcher", prefixCls + "-switcher--loading")
|
107
|
+
}, defaultLoadingIcon);
|
108
|
+
}
|
109
|
+
|
110
|
+
var canLoadChildren = checkCanLoadChildren(item, onLoadChildren);
|
111
|
+
|
112
|
+
if (canLoadChildren) {
|
113
|
+
return /*#__PURE__*/React.createElement("span", {
|
114
|
+
className: cx(prefixCls + "-switcher", prefixCls + "-switcher--arrow")
|
115
|
+
}, defaultSuffixIcon);
|
116
|
+
}
|
117
|
+
|
118
|
+
return /*#__PURE__*/React.createElement("span", {
|
119
|
+
className: cx(prefixCls + "-switcher", prefixCls + "-switcher--noop")
|
120
|
+
}, defaultLeafIcon);
|
121
|
+
};
|
122
|
+
|
123
|
+
var renderFlattedTitle = function renderFlattedTitle(option, titleRender) {
|
124
|
+
// 如果 titleRender 返回 `true`,则使用默认 title
|
125
|
+
var title = titleRender ? titleRender(option) : true;
|
126
|
+
if (title !== true) return title;
|
127
|
+
return /*#__PURE__*/React.createElement("span", {
|
128
|
+
className: "title__text title__text--cols"
|
129
|
+
}, getTopDownAncestors(option).map(function (item) {
|
130
|
+
return /*#__PURE__*/React.createElement("span", {
|
131
|
+
key: item.id,
|
132
|
+
className: "title__text--col"
|
133
|
+
}, item.title);
|
134
|
+
}));
|
135
|
+
};
|
136
|
+
|
137
|
+
var renderDefaultTitle = function renderDefaultTitle(option, titleRender) {
|
138
|
+
// 如果 titleRender 返回 `true`,则使用默认 title
|
139
|
+
var title = titleRender ? titleRender(option) : true;
|
140
|
+
if (title !== true) return title;
|
141
|
+
return /*#__PURE__*/React.createElement("span", {
|
142
|
+
className: "title__text"
|
143
|
+
}, option.title);
|
144
|
+
};
|
145
|
+
|
146
|
+
export { CascaderMenu, CascaderMenuList };
|
package/lib/esm/context.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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 useCascaderContext = function useCascaderContext() {
|
|
22
22
|
};
|
23
23
|
|
24
24
|
export { CascaderProvider, useCascaderContext };
|
25
|
-
//# sourceMappingURL=context.js.map
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -119,4 +119,3 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
|
|
119
119
|
};
|
120
120
|
|
121
121
|
export { useAsyncSwitch };
|
122
|
-
//# sourceMappingURL=use-async-switch.js.map
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -12,7 +12,7 @@ import { useState, useEffect } from 'react';
|
|
12
12
|
* @hi-ui/use-cache
|
13
13
|
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-cache#readme
|
14
14
|
*
|
15
|
-
* Copyright (c)
|
15
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
16
16
|
*
|
17
17
|
* This source code is licensed under the MIT license found in the
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
@@ -34,4 +34,3 @@ var useCache = function useCache(data) {
|
|
34
34
|
};
|
35
35
|
|
36
36
|
export { useCache };
|
37
|
-
//# sourceMappingURL=index.js.map
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -55,4 +55,3 @@ var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChi
|
|
55
55
|
};
|
56
56
|
|
57
57
|
export { useSelect };
|
58
|
-
//# sourceMappingURL=use-select.js.map
|
package/lib/esm/icons/index.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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.
|
@@ -19,4 +19,3 @@ var defaultLeafIcon = /*#__PURE__*/React.createElement("span", {
|
|
19
19
|
});
|
20
20
|
var defaultLoadingIcon = /*#__PURE__*/React.createElement(Spinner, null);
|
21
21
|
export { defaultLeafIcon, defaultLoadingIcon, defaultSuffixIcon };
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
* @hi-ui/cascader
|
3
3
|
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/cascader#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
|
-
export { Cascader,
|
12
|
-
//# sourceMappingURL=index.js.map
|
11
|
+
export { Cascader, Cascader as default } from './Cascader.js';
|