@hi-ui/menu 4.3.1 → 5.0.0-alpha.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/CHANGELOG.md +83 -0
- package/lib/cjs/EnterIcon.js +44 -0
- package/lib/cjs/GroupMenu.js +96 -0
- package/lib/cjs/Menu.js +25 -11
- package/lib/cjs/MenuItem.js +4 -3
- package/lib/cjs/MenuSearch.js +322 -0
- package/lib/cjs/SideMenu.js +139 -0
- package/lib/cjs/button/lib/esm/Button.js +109 -0
- package/lib/cjs/button/lib/esm/ButtonGroup.js +56 -0
- package/lib/cjs/button/lib/esm/styles/index.scss.js +35 -0
- package/lib/cjs/index.js +8 -0
- package/lib/cjs/styles/index.scss.js +1 -1
- package/lib/cjs/util.js +95 -1
- package/lib/esm/EnterIcon.js +32 -0
- package/lib/esm/GroupMenu.js +83 -0
- package/lib/esm/Menu.js +26 -12
- package/lib/esm/MenuItem.js +4 -3
- package/lib/esm/MenuSearch.js +305 -0
- package/lib/esm/SideMenu.js +124 -0
- package/lib/esm/button/lib/esm/Button.js +97 -0
- package/lib/esm/button/lib/esm/ButtonGroup.js +44 -0
- package/lib/esm/button/lib/esm/styles/index.scss.js +23 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/styles/index.scss.js +1 -1
- package/lib/esm/util.js +95 -2
- package/lib/types/EnterIcon.d.ts +1 -0
- package/lib/types/GroupMenu.d.ts +29 -0
- package/lib/types/Menu.d.ts +4 -0
- package/lib/types/MenuSearch.d.ts +37 -0
- package/lib/types/SideMenu.d.ts +58 -0
- package/lib/types/context.d.ts +2 -1
- package/lib/types/index.d.ts +3 -0
- package/lib/types/util.d.ts +16 -0
- package/package.json +27 -19
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/menu
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#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, useState, useRef, useLayoutEffect, useCallback, useEffect, useImperativeHandle } from 'react';
|
|
12
|
+
import { useLocaleContext } from '@hi-ui/core';
|
|
13
|
+
import { __DEV__ } from '@hi-ui/env';
|
|
14
|
+
import { getPrefixCls, cx } from '@hi-ui/classname';
|
|
15
|
+
import { ArrowUpOutlined, ArrowDownOutlined, SearchOutlined, CloseOutlined } from '@hi-ui/icons';
|
|
16
|
+
import IconButton from '@hi-ui/icon-button';
|
|
17
|
+
import './button/lib/esm/styles/index.scss.js';
|
|
18
|
+
import { Button } from './button/lib/esm/Button.js';
|
|
19
|
+
import './button/lib/esm/ButtonGroup.js';
|
|
20
|
+
import Input from '@hi-ui/input';
|
|
21
|
+
import Highlighter from '@hi-ui/highlighter';
|
|
22
|
+
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
|
|
23
|
+
import { useUncontrolledToggle } from '@hi-ui/use-toggle';
|
|
24
|
+
import EllipsisTooltip from '@hi-ui/ellipsis-tooltip';
|
|
25
|
+
import { EnterIcon } from './EnterIcon.js';
|
|
26
|
+
import { searchMenuWithPath } from './util.js';
|
|
27
|
+
var _role = 'menu-search';
|
|
28
|
+
var _prefix = getPrefixCls(_role);
|
|
29
|
+
var MenuSearch = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
30
|
+
var _cx, _cx2;
|
|
31
|
+
var _b, _c;
|
|
32
|
+
var innerRef = _a.innerRef,
|
|
33
|
+
_a$prefixCls = _a.prefixCls,
|
|
34
|
+
prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
|
|
35
|
+
className = _a.className,
|
|
36
|
+
placeholder = _a.placeholder,
|
|
37
|
+
width = _a.width,
|
|
38
|
+
style = _a.style,
|
|
39
|
+
visibleProp = _a.visible,
|
|
40
|
+
data = _a.data,
|
|
41
|
+
_a$defaultValue = _a.defaultValue,
|
|
42
|
+
defaultValue = _a$defaultValue === void 0 ? '' : _a$defaultValue,
|
|
43
|
+
valueProp = _a.value,
|
|
44
|
+
onChange = _a.onChange,
|
|
45
|
+
onSelect = _a.onSelect,
|
|
46
|
+
onClear = _a.onClear,
|
|
47
|
+
onClose = _a.onClose,
|
|
48
|
+
onEsc = _a.onEsc;
|
|
49
|
+
__rest(_a, ["innerRef", "prefixCls", "className", "clearText", "placeholder", "notFoundContent", "width", "style", "visible", "data", "defaultValue", "value", "onChange", "onSearch", "onSelect", "onClear", "onClose", "onEsc"]);
|
|
50
|
+
var i18n = useLocaleContext();
|
|
51
|
+
var _useUncontrolledToggl = useUncontrolledToggle({
|
|
52
|
+
visible: visibleProp
|
|
53
|
+
}),
|
|
54
|
+
visible = _useUncontrolledToggl[0],
|
|
55
|
+
visibleAction = _useUncontrolledToggl[1];
|
|
56
|
+
var _useUncontrolledState = useUncontrolledState(defaultValue, valueProp, onChange),
|
|
57
|
+
value = _useUncontrolledState[0],
|
|
58
|
+
tryChangeValue = _useUncontrolledState[1];
|
|
59
|
+
var _useState = useState(-1),
|
|
60
|
+
currentIndex = _useState[0],
|
|
61
|
+
setCurrentIndex = _useState[1];
|
|
62
|
+
var listRef = useRef(null);
|
|
63
|
+
useLayoutEffect(function () {
|
|
64
|
+
if (currentIndex === -1 || !listRef.current) return;
|
|
65
|
+
var listContainer = listRef.current;
|
|
66
|
+
var selectedItem = listContainer.children[currentIndex];
|
|
67
|
+
if (!selectedItem) return;
|
|
68
|
+
var containerScrollTop = listContainer.scrollTop;
|
|
69
|
+
var containerHeight = listContainer.clientHeight;
|
|
70
|
+
var itemTop = selectedItem.offsetTop;
|
|
71
|
+
var itemHeight = selectedItem.offsetHeight;
|
|
72
|
+
// 计算元素的可见范围
|
|
73
|
+
var itemBottom = itemTop + itemHeight;
|
|
74
|
+
var visibleTop = containerScrollTop;
|
|
75
|
+
var visibleBottom = containerScrollTop + containerHeight;
|
|
76
|
+
// 判断是否需要滚动
|
|
77
|
+
var isItemAboveViewport = itemTop < visibleTop;
|
|
78
|
+
var isItemBelowViewport = itemBottom > visibleBottom;
|
|
79
|
+
if (isItemAboveViewport) {
|
|
80
|
+
// 如果元素在可视区域上方,滚动到元素顶部
|
|
81
|
+
listContainer.scrollTop = itemTop;
|
|
82
|
+
} else if (isItemBelowViewport) {
|
|
83
|
+
// 如果元素在可视区域下方,滚动到元素底部刚好可见
|
|
84
|
+
listContainer.scrollTop = itemBottom - containerHeight;
|
|
85
|
+
}
|
|
86
|
+
}, [currentIndex]);
|
|
87
|
+
var resultMemo = React.useMemo(function () {
|
|
88
|
+
if (!data || !value) return [];
|
|
89
|
+
// 使用新的搜索算法
|
|
90
|
+
var searchResults = searchMenuWithPath(data, value);
|
|
91
|
+
return searchResults.map(function (result) {
|
|
92
|
+
return Object.assign(Object.assign({}, result.node), {
|
|
93
|
+
level: result.level,
|
|
94
|
+
path: result.path,
|
|
95
|
+
// 添加路径信息用于显示
|
|
96
|
+
pathTitles: result.path.map(function (p) {
|
|
97
|
+
var _a;
|
|
98
|
+
return (_a = p.title) === null || _a === void 0 ? void 0 : _a.toString();
|
|
99
|
+
}).filter(Boolean)
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}, [data, value]);
|
|
103
|
+
var handleChange = useCallback(function (value) {
|
|
104
|
+
tryChangeValue(value);
|
|
105
|
+
}, [tryChangeValue]);
|
|
106
|
+
var handleSelect = useCallback(function (id, item, index) {
|
|
107
|
+
var _a;
|
|
108
|
+
setCurrentIndex(index);
|
|
109
|
+
visibleAction.off();
|
|
110
|
+
// 让列表容器获取焦点,确保键盘导航可用
|
|
111
|
+
(_a = listRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
112
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(id, item);
|
|
113
|
+
}, [onSelect, visibleAction]);
|
|
114
|
+
var handleMove = useCallback(function (direction) {
|
|
115
|
+
if (!resultMemo) return;
|
|
116
|
+
setCurrentIndex(function (prev) {
|
|
117
|
+
if (direction === 'up') {
|
|
118
|
+
return prev - 1 < 0 ? (resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.length) - 1 : prev - 1;
|
|
119
|
+
} else {
|
|
120
|
+
return prev + 1 > (resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.length) - 1 ? 0 : prev + 1;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}, [resultMemo]);
|
|
124
|
+
var handleEnter = useCallback(function () {
|
|
125
|
+
if (!resultMemo) return;
|
|
126
|
+
if (currentIndex === -1) {
|
|
127
|
+
setCurrentIndex(0);
|
|
128
|
+
}
|
|
129
|
+
visibleAction.off();
|
|
130
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(resultMemo[currentIndex].id, resultMemo[currentIndex]);
|
|
131
|
+
}, [resultMemo, currentIndex, onSelect, visibleAction]);
|
|
132
|
+
var handleClear = useCallback(function () {
|
|
133
|
+
tryChangeValue('');
|
|
134
|
+
setCurrentIndex(-1);
|
|
135
|
+
onClear === null || onClear === void 0 ? void 0 : onClear();
|
|
136
|
+
}, [onClear, tryChangeValue]);
|
|
137
|
+
var handleClose = useCallback(function () {
|
|
138
|
+
visibleAction.off();
|
|
139
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
140
|
+
}, [onClose, visibleAction]);
|
|
141
|
+
var handleEscape = useCallback(function () {
|
|
142
|
+
handleClose();
|
|
143
|
+
onEsc === null || onEsc === void 0 ? void 0 : onEsc();
|
|
144
|
+
}, [handleClose, onEsc]);
|
|
145
|
+
var handleKeyDown = useCallback(function (e) {
|
|
146
|
+
if (e.key === 'ArrowUp') {
|
|
147
|
+
handleMove('up');
|
|
148
|
+
}
|
|
149
|
+
if (e.key === 'ArrowDown') {
|
|
150
|
+
handleMove('down');
|
|
151
|
+
}
|
|
152
|
+
if (e.key === 'Enter') {
|
|
153
|
+
handleEnter();
|
|
154
|
+
}
|
|
155
|
+
if (e.key === 'Escape') {
|
|
156
|
+
handleEscape();
|
|
157
|
+
}
|
|
158
|
+
}, [handleEnter, handleMove, handleEscape]);
|
|
159
|
+
var _useState2 = useState(null),
|
|
160
|
+
inputRef = _useState2[0],
|
|
161
|
+
setInputRef = _useState2[1];
|
|
162
|
+
useEffect(function () {
|
|
163
|
+
if (!value || !inputRef) {
|
|
164
|
+
visibleAction.off();
|
|
165
|
+
} else {
|
|
166
|
+
visibleAction.on();
|
|
167
|
+
}
|
|
168
|
+
}, [inputRef, value, visibleAction]);
|
|
169
|
+
useImperativeHandle(innerRef, function () {
|
|
170
|
+
return {
|
|
171
|
+
show: function show() {
|
|
172
|
+
visibleAction.on();
|
|
173
|
+
},
|
|
174
|
+
hide: function hide() {
|
|
175
|
+
visibleAction.off();
|
|
176
|
+
},
|
|
177
|
+
focus: function focus() {
|
|
178
|
+
inputRef === null || inputRef === void 0 ? void 0 : inputRef.focus();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
var cls = cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--open"] = visible, _cx));
|
|
183
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
184
|
+
className: cls,
|
|
185
|
+
style: style
|
|
186
|
+
}, /*#__PURE__*/React.createElement(MenuSearchInput, {
|
|
187
|
+
width: width,
|
|
188
|
+
prefixCls: prefixCls,
|
|
189
|
+
placeholder: placeholder,
|
|
190
|
+
value: value,
|
|
191
|
+
onChange: handleChange,
|
|
192
|
+
onClear: handleClear,
|
|
193
|
+
onClose: handleClose,
|
|
194
|
+
onKeyDown: handleKeyDown,
|
|
195
|
+
inputRef: setInputRef
|
|
196
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
197
|
+
className: cx(prefixCls + "__content", (_cx2 = {}, _cx2[prefixCls + "__content--visible"] = visible, _cx2))
|
|
198
|
+
}, (resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.length) > 0 ? ( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
199
|
+
className: prefixCls + "__header"
|
|
200
|
+
}, /*#__PURE__*/React.createElement(Highlighter, {
|
|
201
|
+
keyword: String((_b = resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.length) !== null && _b !== void 0 ? _b : 0)
|
|
202
|
+
}, i18n.get('menuSearch.searchResult', {
|
|
203
|
+
count: (_c = resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.length) !== null && _c !== void 0 ? _c : 0,
|
|
204
|
+
keyword: value
|
|
205
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
206
|
+
className: prefixCls + "__list",
|
|
207
|
+
ref: listRef,
|
|
208
|
+
tabIndex: -1,
|
|
209
|
+
onKeyDown: handleKeyDown
|
|
210
|
+
}, resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.map(function (item, index) {
|
|
211
|
+
var _cx3;
|
|
212
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
213
|
+
key: item.id,
|
|
214
|
+
className: cx(prefixCls + "__list-item", (_cx3 = {}, _cx3[prefixCls + "__list-item--selected"] = currentIndex === index, _cx3)),
|
|
215
|
+
onClick: function onClick() {
|
|
216
|
+
return handleSelect(item.id, item, index);
|
|
217
|
+
}
|
|
218
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
219
|
+
className: prefixCls + "__list-item__title"
|
|
220
|
+
}, /*#__PURE__*/React.createElement(EllipsisTooltip, {
|
|
221
|
+
tooltipProps: {
|
|
222
|
+
style: {
|
|
223
|
+
maxWidth: 320
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, /*#__PURE__*/React.createElement(Highlighter, {
|
|
227
|
+
keyword: value
|
|
228
|
+
}, item.pathTitles.join('/')))));
|
|
229
|
+
})))) : ( /*#__PURE__*/React.createElement("div", {
|
|
230
|
+
className: prefixCls + "__empty"
|
|
231
|
+
}, /*#__PURE__*/React.createElement("div", null, i18n.menuSearch.searchEmptyResult)))), (resultMemo === null || resultMemo === void 0 ? void 0 : resultMemo.length) > 0 && ( /*#__PURE__*/React.createElement("div", {
|
|
232
|
+
className: prefixCls + "__footer"
|
|
233
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
234
|
+
className: prefixCls + "__footer-item"
|
|
235
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
236
|
+
className: prefixCls + "__footer-item__icon"
|
|
237
|
+
}, /*#__PURE__*/React.createElement(ArrowUpOutlined, null), /*#__PURE__*/React.createElement(ArrowDownOutlined, null)), /*#__PURE__*/React.createElement("span", {
|
|
238
|
+
className: prefixCls + "__footer-item__text"
|
|
239
|
+
}, i18n.menuSearch.moveCursor)), /*#__PURE__*/React.createElement("div", {
|
|
240
|
+
className: prefixCls + "__footer-item"
|
|
241
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
242
|
+
className: prefixCls + "__footer-item__icon"
|
|
243
|
+
}, /*#__PURE__*/React.createElement(EnterIcon, null)), /*#__PURE__*/React.createElement("span", {
|
|
244
|
+
className: prefixCls + "__footer-item__text"
|
|
245
|
+
}, i18n.menuSearch.confirmSelect)), /*#__PURE__*/React.createElement("div", {
|
|
246
|
+
className: prefixCls + "__footer-item"
|
|
247
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
248
|
+
className: prefixCls + "__footer-item__icon"
|
|
249
|
+
}, "esc"), /*#__PURE__*/React.createElement("span", {
|
|
250
|
+
className: prefixCls + "__footer-item__text"
|
|
251
|
+
}, i18n.menuSearch.hideWindow)))));
|
|
252
|
+
});
|
|
253
|
+
if (__DEV__) {
|
|
254
|
+
MenuSearch.displayName = 'MenuSearch';
|
|
255
|
+
}
|
|
256
|
+
var MenuSearchInput = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
257
|
+
var prefixCls = _a.prefixCls,
|
|
258
|
+
placeholder = _a.placeholder,
|
|
259
|
+
width = _a.width,
|
|
260
|
+
value = _a.value,
|
|
261
|
+
_onChange = _a.onChange,
|
|
262
|
+
onClear = _a.onClear,
|
|
263
|
+
onClose = _a.onClose,
|
|
264
|
+
onKeyDown = _a.onKeyDown,
|
|
265
|
+
inputRef = _a.inputRef,
|
|
266
|
+
rest = __rest(_a, ["prefixCls", "placeholder", "width", "value", "onChange", "onClear", "onClose", "onKeyDown", "inputRef"]);
|
|
267
|
+
var i18n = useLocaleContext();
|
|
268
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
269
|
+
ref: ref,
|
|
270
|
+
className: prefixCls + "__input-wrapper",
|
|
271
|
+
style: {
|
|
272
|
+
width: width
|
|
273
|
+
}
|
|
274
|
+
}, /*#__PURE__*/React.createElement(Input, Object.assign({
|
|
275
|
+
ref: inputRef,
|
|
276
|
+
className: prefixCls + "__input",
|
|
277
|
+
classNames: {
|
|
278
|
+
prefix: prefixCls + "__input-prefix"
|
|
279
|
+
},
|
|
280
|
+
appearance: "unset",
|
|
281
|
+
placeholder: placeholder,
|
|
282
|
+
prefix: /*#__PURE__*/React.createElement(SearchOutlined, null),
|
|
283
|
+
suffix: /*#__PURE__*/React.createElement(Button, {
|
|
284
|
+
className: prefixCls + "__input-clear",
|
|
285
|
+
appearance: "link",
|
|
286
|
+
size: "xs",
|
|
287
|
+
onClick: onClear
|
|
288
|
+
}, i18n.menuSearch.clear),
|
|
289
|
+
value: value,
|
|
290
|
+
onChange: function onChange(e) {
|
|
291
|
+
return _onChange === null || _onChange === void 0 ? void 0 : _onChange(e.target.value);
|
|
292
|
+
},
|
|
293
|
+
onKeyDown: onKeyDown
|
|
294
|
+
}, rest)), /*#__PURE__*/React.createElement("span", {
|
|
295
|
+
className: prefixCls + "__close"
|
|
296
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
297
|
+
icon: /*#__PURE__*/React.createElement(CloseOutlined, null),
|
|
298
|
+
effect: true,
|
|
299
|
+
onClick: onClose
|
|
300
|
+
})));
|
|
301
|
+
});
|
|
302
|
+
if (__DEV__) {
|
|
303
|
+
MenuSearchInput.displayName = 'MenuSearchInput';
|
|
304
|
+
}
|
|
305
|
+
export { MenuSearch, MenuSearchInput };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/menu
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#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 EllipsisTooltip from '@hi-ui/ellipsis-tooltip';
|
|
15
|
+
import { useLatestCallback } from '@hi-ui/use-latest';
|
|
16
|
+
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
|
|
17
|
+
import Scrollbar from '@hi-ui/scrollbar';
|
|
18
|
+
import { getAncestorIds } from './util.js';
|
|
19
|
+
var SIDE_MENU_PREFIX = getPrefixCls('side-menu');
|
|
20
|
+
/**
|
|
21
|
+
* 侧边菜单组件
|
|
22
|
+
*/
|
|
23
|
+
var SideMenu = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
24
|
+
var _cx;
|
|
25
|
+
var _a$prefixCls = _a.prefixCls,
|
|
26
|
+
prefixCls = _a$prefixCls === void 0 ? SIDE_MENU_PREFIX : _a$prefixCls,
|
|
27
|
+
_a$role = _a.role,
|
|
28
|
+
role = _a$role === void 0 ? 'side-menu' : _a$role,
|
|
29
|
+
className = _a.className,
|
|
30
|
+
_a$defaultActiveId = _a.defaultActiveId,
|
|
31
|
+
defaultActiveId = _a$defaultActiveId === void 0 ? null : _a$defaultActiveId,
|
|
32
|
+
activeIdProp = _a.activeId,
|
|
33
|
+
selectedIdProp = _a.selectedId,
|
|
34
|
+
_a$data = _a.data,
|
|
35
|
+
data = _a$data === void 0 ? [] : _a$data,
|
|
36
|
+
mini = _a.mini,
|
|
37
|
+
onClick = _a.onClick,
|
|
38
|
+
onMouseEnter = _a.onMouseEnter,
|
|
39
|
+
onMouseLeave = _a.onMouseLeave,
|
|
40
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "defaultActiveId", "activeId", "selectedId", "data", "mini", "childrenContainerRef", "onClick", "onMouseEnter", "onMouseLeave"]);
|
|
41
|
+
var cls = cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--mini"] = mini, _cx));
|
|
42
|
+
var _useUncontrolledState = useUncontrolledState(defaultActiveId, activeIdProp),
|
|
43
|
+
activeId = _useUncontrolledState[0],
|
|
44
|
+
tryChangeActiveId = _useUncontrolledState[1];
|
|
45
|
+
var handleClick = useLatestCallback(function (event, id, item) {
|
|
46
|
+
tryChangeActiveId(id);
|
|
47
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event, id, item);
|
|
48
|
+
});
|
|
49
|
+
var handleMouseEnter = useLatestCallback(function (event, id, item) {
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(event, id, item);
|
|
52
|
+
});
|
|
53
|
+
var handleMouseLeave = useLatestCallback(function (event, id, item) {
|
|
54
|
+
event.stopPropagation();
|
|
55
|
+
onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(event, id, item);
|
|
56
|
+
});
|
|
57
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
58
|
+
ref: ref,
|
|
59
|
+
role: role,
|
|
60
|
+
className: cls
|
|
61
|
+
}, rest), /*#__PURE__*/React.createElement(Scrollbar, {
|
|
62
|
+
onlyScrollVisible: true,
|
|
63
|
+
axes: "y"
|
|
64
|
+
}, data.map(function (item) {
|
|
65
|
+
var _cx2;
|
|
66
|
+
var id = item.id,
|
|
67
|
+
title = item.title,
|
|
68
|
+
icon = item.icon;
|
|
69
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
key: id,
|
|
71
|
+
className: cx(prefixCls + "-item-wrapper"),
|
|
72
|
+
onClick: function onClick(event) {
|
|
73
|
+
return handleClick(event, id, item);
|
|
74
|
+
},
|
|
75
|
+
onMouseEnter: function onMouseEnter(event) {
|
|
76
|
+
return handleMouseEnter(event, id, item);
|
|
77
|
+
},
|
|
78
|
+
onMouseLeave: function onMouseLeave(event) {
|
|
79
|
+
return handleMouseLeave(event, id, item);
|
|
80
|
+
}
|
|
81
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: cx(prefixCls + "-item", (_cx2 = {}, _cx2[prefixCls + "-item--active"] = activeId === id, _cx2[prefixCls + "-item--mini"] = mini, _cx2[prefixCls + "-item--selected"] = selectedIdProp === id, _cx2))
|
|
83
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
84
|
+
className: cx(prefixCls + "-item__icon")
|
|
85
|
+
}, icon), /*#__PURE__*/React.createElement("div", {
|
|
86
|
+
className: cx(prefixCls + "-item__title")
|
|
87
|
+
}, /*#__PURE__*/React.createElement(EllipsisTooltip, null, title))));
|
|
88
|
+
})));
|
|
89
|
+
});
|
|
90
|
+
if (__DEV__) {
|
|
91
|
+
SideMenu.displayName = 'SideMenu';
|
|
92
|
+
}
|
|
93
|
+
var useSideMenuCascade = function useSideMenuCascade(_ref) {
|
|
94
|
+
var data = _ref.data,
|
|
95
|
+
selectId = _ref.selectId,
|
|
96
|
+
activeId = _ref.activeId;
|
|
97
|
+
var activeParents = React.useMemo(function () {
|
|
98
|
+
return getAncestorIds(activeId, data);
|
|
99
|
+
}, [activeId, data]);
|
|
100
|
+
var selectParents = React.useMemo(function () {
|
|
101
|
+
return getAncestorIds(selectId, data);
|
|
102
|
+
}, [selectId, data]);
|
|
103
|
+
var selectParentId = React.useMemo(function () {
|
|
104
|
+
var _a;
|
|
105
|
+
return (_a = selectParents[selectParents.length - 1]) !== null && _a !== void 0 ? _a : selectId;
|
|
106
|
+
}, [selectId, selectParents]);
|
|
107
|
+
var activeParentId = React.useMemo(function () {
|
|
108
|
+
var _a;
|
|
109
|
+
return (_a = activeParents[activeParents.length - 1]) !== null && _a !== void 0 ? _a : activeId;
|
|
110
|
+
}, [activeId, activeParents]);
|
|
111
|
+
var submenuData = React.useMemo(function () {
|
|
112
|
+
var _a;
|
|
113
|
+
var parentId = selectParentId || activeParentId;
|
|
114
|
+
return ((_a = data.find(function (item) {
|
|
115
|
+
return item.id === parentId;
|
|
116
|
+
})) === null || _a === void 0 ? void 0 : _a.children) || [];
|
|
117
|
+
}, [selectParentId, activeParentId, data]);
|
|
118
|
+
return {
|
|
119
|
+
submenuData: submenuData,
|
|
120
|
+
selectParentId: selectParentId,
|
|
121
|
+
activeParentId: activeParentId
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export { SideMenu, useSideMenuCascade };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/menu
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#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
|
+
|
|
15
|
+
/** @LICENSE
|
|
16
|
+
* @hi-ui/button
|
|
17
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/button#readme
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
var _role = 'button';
|
|
25
|
+
var _prefix = getPrefixCls(_role);
|
|
26
|
+
/**
|
|
27
|
+
* 按钮
|
|
28
|
+
*/
|
|
29
|
+
var Button = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
30
|
+
var _a$prefixCls = _a.prefixCls,
|
|
31
|
+
prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
|
|
32
|
+
_a$role = _a.role,
|
|
33
|
+
role = _a$role === void 0 ? _role : _a$role,
|
|
34
|
+
className = _a.className,
|
|
35
|
+
children = _a.children,
|
|
36
|
+
_a$type = _a.type,
|
|
37
|
+
type = _a$type === void 0 ? 'default' : _a$type,
|
|
38
|
+
_a$size = _a.size,
|
|
39
|
+
size = _a$size === void 0 ? 'md' : _a$size,
|
|
40
|
+
_a$appearance = _a.appearance,
|
|
41
|
+
appearance = _a$appearance === void 0 ? 'filled' : _a$appearance,
|
|
42
|
+
_a$disabled = _a.disabled,
|
|
43
|
+
disabled = _a$disabled === void 0 ? false : _a$disabled,
|
|
44
|
+
_a$loading = _a.loading,
|
|
45
|
+
loading = _a$loading === void 0 ? false : _a$loading,
|
|
46
|
+
_a$icon = _a.icon,
|
|
47
|
+
icon = _a$icon === void 0 ? null : _a$icon,
|
|
48
|
+
_a$shape = _a.shape,
|
|
49
|
+
shape = _a$shape === void 0 ? 'square' : _a$shape,
|
|
50
|
+
href = _a.href,
|
|
51
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "children", "type", "size", "appearance", "disabled", "loading", "icon", "shape", "href"]);
|
|
52
|
+
var isEmptyChildren = !children || typeof children === 'string' && !children.trim();
|
|
53
|
+
var isNonInteractive = disabled || loading;
|
|
54
|
+
var prefix = loading ? ( /*#__PURE__*/React.createElement(IconLoading, {
|
|
55
|
+
className: prefixCls + "__icon " + prefixCls + "__icon--prefix"
|
|
56
|
+
})) : icon && (!Array.isArray(icon) || icon[0]) ? ( /*#__PURE__*/React.createElement("span", {
|
|
57
|
+
className: prefixCls + "__icon " + prefixCls + "__icon--prefix"
|
|
58
|
+
}, Array.isArray(icon) ? icon[0] : icon)) : null;
|
|
59
|
+
var suffix = Array.isArray(icon) && icon.length > 1 ? ( /*#__PURE__*/React.createElement("span", {
|
|
60
|
+
className: prefixCls + "__icon " + prefixCls + "__icon--suffix"
|
|
61
|
+
}, icon[1])) : null;
|
|
62
|
+
var cls = cx(prefixCls, className, prefixCls + "--appearance-" + appearance, prefixCls + "--size-" + size, prefixCls + "--type-" + type, prefixCls + "--shape-" + shape, isEmptyChildren && prefixCls + "--icon-only", disabled && prefixCls + "--disabled", loading && prefixCls + "--loading");
|
|
63
|
+
return !href ? ( /*#__PURE__*/React.createElement("button", Object.assign({
|
|
64
|
+
ref: ref,
|
|
65
|
+
role: role,
|
|
66
|
+
className: cls,
|
|
67
|
+
disabled: isNonInteractive,
|
|
68
|
+
type: "button"
|
|
69
|
+
}, rest), prefix, children, suffix)) : ( /*#__PURE__*/React.createElement("a", Object.assign({
|
|
70
|
+
ref: ref,
|
|
71
|
+
role: role,
|
|
72
|
+
href: href,
|
|
73
|
+
className: cls
|
|
74
|
+
}, rest), prefix, children, suffix));
|
|
75
|
+
});
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
Button.HiName = 'Button';
|
|
78
|
+
if (__DEV__) {
|
|
79
|
+
Button.displayName = 'Button';
|
|
80
|
+
}
|
|
81
|
+
function IconLoading(_ref) {
|
|
82
|
+
var _ref$className = _ref.className,
|
|
83
|
+
className = _ref$className === void 0 ? '' : _ref$className,
|
|
84
|
+
_ref$size = _ref.size,
|
|
85
|
+
size = _ref$size === void 0 ? '0.8em' : _ref$size;
|
|
86
|
+
return /*#__PURE__*/React.createElement("i", {
|
|
87
|
+
className: cx(className)
|
|
88
|
+
}, /*#__PURE__*/React.createElement("svg", {
|
|
89
|
+
viewBox: "0 0 18 18",
|
|
90
|
+
width: size,
|
|
91
|
+
height: size,
|
|
92
|
+
fill: "currentColor"
|
|
93
|
+
}, /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("path", {
|
|
94
|
+
d: "m15.547 2.8242c0.37904 0.40168 0.36068 1.0346-0.040996 1.4136-0.40168 0.37904-1.0346 0.36068-1.4136-0.040996-1.315-1.3935-3.1381-2.1969-5.0922-2.1969-3.866 0-7 3.134-7 7 0 0.55228-0.44772 1-1 1s-1-0.44772-1-1c0-4.9706 4.0294-9 9-9 2.5103 0 4.8578 1.0343 6.5468 2.8242z"
|
|
95
|
+
}))));
|
|
96
|
+
}
|
|
97
|
+
export { Button };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/menu
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#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
|
+
|
|
15
|
+
/** @LICENSE
|
|
16
|
+
* @hi-ui/button
|
|
17
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/button#readme
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
var _role = 'button-group';
|
|
25
|
+
var _prefix = getPrefixCls(_role);
|
|
26
|
+
var ButtonGroup = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
27
|
+
var _a$prefixCls = _a.prefixCls,
|
|
28
|
+
prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
|
|
29
|
+
_a$role = _a.role,
|
|
30
|
+
role = _a$role === void 0 ? _role : _a$role,
|
|
31
|
+
className = _a.className,
|
|
32
|
+
children = _a.children,
|
|
33
|
+
rest = __rest(_a, ["prefixCls", "role", "className", "children"]);
|
|
34
|
+
var cls = cx(prefixCls, className);
|
|
35
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
36
|
+
role: role,
|
|
37
|
+
className: cls,
|
|
38
|
+
ref: ref
|
|
39
|
+
}, rest), children);
|
|
40
|
+
});
|
|
41
|
+
if (__DEV__) {
|
|
42
|
+
ButtonGroup.displayName = 'ButtonGroup';
|
|
43
|
+
}
|
|
44
|
+
export { ButtonGroup };
|