@hi-ui/menu 4.0.0-beta.9 → 4.0.2

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.
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
package/lib/cjs/Menu.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
@@ -35,6 +35,18 @@ var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
35
35
 
36
36
  var Tooltip = require('@hi-ui/tooltip');
37
37
 
38
+ var useToggle = require('@hi-ui/use-toggle');
39
+
40
+ var treeUtils = require('@hi-ui/tree-utils');
41
+
42
+ var typeAssertion = require('@hi-ui/type-assertion');
43
+
44
+ var useResizeObserver = require('@hi-ui/use-resize-observer');
45
+
46
+ var useMergeRefs = require('@hi-ui/use-merge-refs');
47
+
48
+ var useId = require('@hi-ui/use-id');
49
+
38
50
  function _interopDefaultLegacy(e) {
39
51
  return e && _typeof(e) === 'object' && 'default' in e ? e : {
40
52
  'default': e
@@ -46,83 +58,193 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
46
58
  var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
47
59
 
48
60
  var MENU_PREFIX = classname.getPrefixCls('menu');
61
+ var DEFAULT_EXPANDED_IDS = [];
62
+ var NOOP_ARRAY = [];
63
+ var MIN_WIDTH = 56;
64
+ var MENU_MORE_ID = "MENU_MORE_" + useId.uuid();
49
65
  /**
50
66
  * TODO: What is Menu
51
67
  */
52
68
 
53
69
  var Menu = /*#__PURE__*/React.forwardRef(function (_a, ref) {
54
- var _cx;
55
-
56
70
  var _a$prefixCls = _a.prefixCls,
57
71
  prefixCls = _a$prefixCls === void 0 ? MENU_PREFIX : _a$prefixCls,
58
72
  _a$role = _a.role,
59
73
  role = _a$role === void 0 ? 'menu' : _a$role,
60
74
  className = _a.className,
61
- data = _a.data,
75
+ _a$data = _a.data,
76
+ data = _a$data === void 0 ? NOOP_ARRAY : _a$data,
62
77
  _a$placement = _a.placement,
63
78
  placement = _a$placement === void 0 ? 'vertical' : _a$placement,
64
- showCollapse = _a.showCollapse,
79
+ _a$showCollapse = _a.showCollapse,
80
+ showCollapse = _a$showCollapse === void 0 ? false : _a$showCollapse,
65
81
  _a$expandedType = _a.expandedType,
66
82
  expandedType = _a$expandedType === void 0 ? 'collapse' : _a$expandedType,
67
83
  _a$showAllSubMenus = _a.showAllSubMenus,
68
84
  showAllSubMenus = _a$showAllSubMenus === void 0 ? false : _a$showAllSubMenus,
69
- defaultExpandedIds = _a.defaultExpandedIds,
70
- defaultActiveId = _a.defaultActiveId,
71
- activeId = _a.activeId,
85
+ _a$defaultExpandAll = _a.defaultExpandAll,
86
+ defaultExpandAll = _a$defaultExpandAll === void 0 ? false : _a$defaultExpandAll,
87
+ _a$defaultExpandedIds = _a.defaultExpandedIds,
88
+ defaultExpandedIds = _a$defaultExpandedIds === void 0 ? DEFAULT_EXPANDED_IDS : _a$defaultExpandedIds,
89
+ expandedIdsProp = _a.expandedIds,
90
+ onExpand = _a.onExpand,
91
+ _a$defaultActiveId = _a.defaultActiveId,
92
+ defaultActiveId = _a$defaultActiveId === void 0 ? '' : _a$defaultActiveId,
93
+ activeIdProp = _a.activeId,
72
94
  onClickSubMenu = _a.onClickSubMenu,
95
+ collapsed = _a.collapsed,
96
+ _a$defaultCollapsed = _a.defaultCollapsed,
97
+ defaultCollapsed = _a$defaultCollapsed === void 0 ? false : _a$defaultCollapsed,
98
+ onCollapse = _a.onCollapse,
99
+ footerRender = _a.footerRender,
73
100
  onClick = _a.onClick,
74
- rest = tslib.__rest(_a, ["prefixCls", "role", "className", "data", "placement", "showCollapse", "expandedType", "showAllSubMenus", "defaultExpandedIds", "defaultActiveId", "activeId", "onClickSubMenu", "onClick"]);
101
+ rest = tslib.__rest(_a, ["prefixCls", "role", "className", "data", "placement", "showCollapse", "expandedType", "showAllSubMenus", "defaultExpandAll", "defaultExpandedIds", "expandedIds", "onExpand", "defaultActiveId", "activeId", "onClickSubMenu", "collapsed", "defaultCollapsed", "onCollapse", "footerRender", "onClick"]);
75
102
 
76
- var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultActiveId || '', activeId, onClick),
77
- _activeId = _useUncontrolledState[0],
103
+ var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultActiveId, activeIdProp, onClick),
104
+ activeId = _useUncontrolledState[0],
78
105
  updateActiveId = _useUncontrolledState[1];
79
106
 
80
- var _useState = React.useState(util.getAncestorIds(_activeId, data)),
107
+ var _useState = React.useState(function () {
108
+ return util.getAncestorIds(activeId, data);
109
+ }),
81
110
  activeParents = _useState[0],
82
111
  updateActiveParents = _useState[1];
83
112
 
84
113
  React.useEffect(function () {
85
- updateActiveParents(util.getAncestorIds(_activeId, data));
86
- }, [_activeId, data]);
114
+ updateActiveParents(util.getAncestorIds(activeId, data));
115
+ }, [activeId, data]);
87
116
 
88
- var _useState2 = React.useState(defaultExpandedIds || []),
89
- _expandedIds = _useState2[0],
90
- updateExpanedIds = _useState2[1];
117
+ var _useUncontrolledState2 = useUncontrolledState.useUncontrolledState(function () {
118
+ return defaultExpandAll ? treeUtils.getTreeNodesWithChildren(data).map(function (node) {
119
+ return node.id;
120
+ }) : defaultExpandedIds;
121
+ }, expandedIdsProp, onExpand),
122
+ expandedIds = _useUncontrolledState2[0],
123
+ updateExpandedIds = _useUncontrolledState2[1];
91
124
 
92
- var clickMenu = React.useCallback(function (id) {
93
- updateActiveId(id);
125
+ var clickMenu = React.useCallback(function (id, raw) {
126
+ updateActiveId(id, raw);
94
127
  }, [updateActiveId]);
95
128
  var clickSubMenu = React.useCallback(function (id) {
96
- var expandedIds = _expandedIds.includes(id) ? _expandedIds.filter(function (expandedId) {
129
+ var nextExpandedIds = expandedIds.includes(id) ? expandedIds.filter(function (expandedId) {
97
130
  return expandedId !== id;
98
- }) : _expandedIds.concat(id);
99
- updateExpanedIds(expandedIds);
131
+ }) : expandedIds.concat(id);
132
+ updateExpandedIds(nextExpandedIds);
100
133
 
101
134
  if (onClickSubMenu) {
102
- onClickSubMenu(id, expandedIds);
135
+ onClickSubMenu(id, nextExpandedIds);
103
136
  }
104
- }, [onClickSubMenu, _expandedIds]);
137
+ }, [onClickSubMenu, expandedIds, updateExpandedIds]);
105
138
  var closePopper = React.useCallback(function (id) {
106
- updateExpanedIds(_expandedIds.filter(function (expandedId) {
139
+ updateExpandedIds(expandedIds.filter(function (expandedId) {
107
140
  return expandedId !== id;
108
141
  }));
109
- }, [_expandedIds]);
142
+ }, [expandedIds, updateExpandedIds]);
110
143
  var closeAllPopper = React.useCallback(function () {
111
- updateExpanedIds([]);
112
- }, []);
113
-
114
- var _useState3 = React.useState(false),
115
- mini = _useState3[0],
116
- setMini = _useState3[1];
117
-
118
- var cls = classname.cx(prefixCls, className, prefixCls + "--" + placement, (_cx = {}, _cx[prefixCls + "--mini"] = mini, _cx[prefixCls + "--popup"] = expandedType === 'pop' || showAllSubMenus || mini, _cx));
119
- var onToggle = React.useCallback(function () {
120
- setMini(!mini);
121
- closeAllPopper();
122
- }, [mini, closeAllPopper]);
123
- var canToggle = placement === 'vertical' && showCollapse;
144
+ updateExpandedIds([]);
145
+ }, [updateExpandedIds]);
146
+
147
+ var _useUncontrolledToggl = useToggle.useUncontrolledToggle({
148
+ defaultVisible: defaultCollapsed,
149
+ visible: collapsed,
150
+ onToggle: onCollapse
151
+ }),
152
+ mini = _useUncontrolledToggl[0],
153
+ miniToggleAction = _useUncontrolledToggl[1];
154
+
155
+ var showVertical = placement === 'vertical';
156
+ var canToggle = showVertical && showCollapse;
157
+ var showMini = showVertical && mini;
158
+
159
+ var _useState2 = React.useState(null),
160
+ containerElement = _useState2[0],
161
+ setContainerElement = _useState2[1];
162
+
163
+ var _useState3 = React.useState(),
164
+ _useState3$ = _useState3[0],
165
+ containerWidth = _useState3$ === void 0 ? 0 : _useState3$,
166
+ setContainerWidth = _useState3[1];
167
+
168
+ useResizeObserver.useResizeObserver({
169
+ element: containerElement,
170
+ disabled: showVertical,
171
+ getSize: function getSize(element) {
172
+ var itemRect = element.getBoundingClientRect();
173
+ return itemRect.width;
174
+ },
175
+ onResize: function onResize(el, width) {
176
+ setContainerWidth(width);
177
+ }
178
+ });
179
+
180
+ var _useState4 = React.useState(0),
181
+ tagMaxCount = _useState4[0],
182
+ setTagMaxCount = _useState4[1];
183
+
184
+ var mergedTagList = React.useMemo(function () {
185
+ if (showVertical) return data;
186
+ if (containerWidth < MIN_WIDTH) return data;
187
+ return data.slice(0, Math.min(data.length, containerWidth / MIN_WIDTH));
188
+ }, [showVertical, data, containerWidth]);
189
+ var restTagList = React.useMemo(function () {
190
+ if (tagMaxCount > 0) return data.slice(tagMaxCount);
191
+ return [];
192
+ }, [data, tagMaxCount]);
193
+ var getTagWidth = React.useCallback(function (index) {
194
+ if (!containerElement) return MIN_WIDTH;
195
+ var elements = containerElement.getElementsByClassName('hi-v4-menu-item');
196
+ var element = elements && elements[index];
197
+ if (!element) return MIN_WIDTH;
198
+ return element.getBoundingClientRect().width;
199
+ }, [containerElement]);
200
+ React.useLayoutEffect(function () {
201
+ if (showVertical) return;
202
+ var tagMaxCount = 0;
203
+
204
+ if (typeAssertion.isArrayNonEmpty(mergedTagList)) {
205
+ var len = mergedTagList.length;
206
+ var lastIndex = len - 1;
207
+ var totalWidth = 72; // 更多
208
+
209
+ for (var i = 0; i < len; ++i) {
210
+ var currentTagWidth = getTagWidth(i);
211
+
212
+ if (currentTagWidth === undefined) {
213
+ break;
214
+ }
215
+
216
+ totalWidth += currentTagWidth;
217
+
218
+ if (lastIndex === 0 && totalWidth <= containerWidth || i === lastIndex - 1 && totalWidth + getTagWidth(lastIndex) <= containerWidth) {
219
+ tagMaxCount = lastIndex;
220
+ break;
221
+ } else if (totalWidth > containerWidth) {
222
+ tagMaxCount = i - 1;
223
+ break;
224
+ }
225
+ }
226
+ } else {
227
+ tagMaxCount = 0;
228
+ } // 保底要展示 1 个
229
+
230
+
231
+ setTagMaxCount(typeAssertion.isArrayNonEmpty(mergedTagList) && tagMaxCount < 1 ? 1 : tagMaxCount + 1);
232
+ }, [showVertical, getTagWidth, containerWidth, mergedTagList]);
233
+
234
+ var renderFooter = function renderFooter() {
235
+ var collapseNode = canToggle ? /*#__PURE__*/React__default["default"].createElement("div", {
236
+ className: classname.cx(prefixCls + "__toggle"),
237
+ onClick: miniToggleAction.not
238
+ }, mini ? /*#__PURE__*/React__default["default"].createElement(icons.MenuUnfoldOutlined, null) : /*#__PURE__*/React__default["default"].createElement(icons.MenuFoldOutlined, null)) : null;
239
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, typeAssertion.isFunction(footerRender) ? footerRender({
240
+ collapsed: showMini,
241
+ collapseNode: collapseNode
242
+ }) : collapseNode);
243
+ };
244
+
245
+ var cls = classname.cx(prefixCls, className, prefixCls + "--" + placement, mini && prefixCls + "--mini", (expandedType === 'pop' || showAllSubMenus || mini) && prefixCls + "--popup");
124
246
  return /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
125
- ref: ref,
247
+ ref: useMergeRefs.useMergeRefs(ref, setContainerElement),
126
248
  role: role,
127
249
  className: cls
128
250
  }, rest), /*#__PURE__*/React__default["default"].createElement(context["default"].Provider, {
@@ -136,30 +258,55 @@ var Menu = /*#__PURE__*/React.forwardRef(function (_a, ref) {
136
258
  closePopper: closePopper,
137
259
  closeAllPopper: closeAllPopper,
138
260
  activeParents: activeParents,
139
- activeId: _activeId,
140
- expandedIds: _expandedIds
261
+ activeId: activeId,
262
+ expandedIds: expandedIds
141
263
  }
142
264
  }, /*#__PURE__*/React__default["default"].createElement("ul", {
143
265
  className: classname.cx(prefixCls + "__wrapper")
144
- }, data.map(function (item) {
145
- return canToggle && mini ? /*#__PURE__*/React__default["default"].createElement(Tooltip__default["default"], {
266
+ }, mergedTagList.map(function (item, index) {
267
+ return showMini ? /*#__PURE__*/React__default["default"].createElement(Tooltip__default["default"], {
146
268
  title: item.title,
147
269
  key: item.id,
148
270
  placement: "right"
149
271
  }, /*#__PURE__*/React__default["default"].createElement(MenuItem.MenuItem, Object.assign({}, item, {
150
- level: 1
151
- }))) : /*#__PURE__*/React__default["default"].createElement(MenuItem.MenuItem, Object.assign({}, item, {
272
+ level: 1,
273
+ render: renderMenuItemMini,
274
+ raw: item
275
+ }))) : /*#__PURE__*/React__default["default"].createElement(MenuItem.MenuItem, Object.assign({
276
+ hidden: !showVertical && index >= tagMaxCount
277
+ }, item, {
152
278
  key: item.id,
153
- level: 1
279
+ level: 1,
280
+ raw: item
154
281
  }));
155
- })), canToggle ? /*#__PURE__*/React__default["default"].createElement("div", {
156
- className: classname.cx(prefixCls + "__toggle"),
157
- onClick: onToggle
158
- }, mini ? /*#__PURE__*/React__default["default"].createElement(icons.MenuUnfoldOutlined, null) : /*#__PURE__*/React__default["default"].createElement(icons.MenuFoldOutlined, null)) : null));
282
+ }), showVertical || restTagList.length === 0 ? null : /*#__PURE__*/React__default["default"].createElement(MenuItem.MenuItem, {
283
+ key: MENU_MORE_ID,
284
+ id: MENU_MORE_ID,
285
+ title: "\u66F4\u591A",
286
+ children: restTagList
287
+ })), /*#__PURE__*/React__default["default"].createElement("div", {
288
+ className: prefixCls + "__footer"
289
+ }, renderFooter())));
159
290
  });
160
291
 
161
292
  if (env.__DEV__) {
162
293
  Menu.displayName = 'Menu';
163
294
  }
295
+ /**
296
+ * Mini 模式下渲染 item
297
+ */
298
+
299
+
300
+ var renderMenuItemMini = function renderMenuItemMini(menu) {
301
+ if (typeof menu.icon !== 'undefined') {
302
+ return menu.icon;
303
+ }
304
+
305
+ if (typeof menu.title === 'string') {
306
+ return menu.title.substring(0, 1);
307
+ }
308
+
309
+ return menu.title;
310
+ };
164
311
 
165
312
  exports.Menu = Menu;
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
@@ -48,6 +48,12 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
48
48
  var Popper__default = /*#__PURE__*/_interopDefaultLegacy(Popper);
49
49
 
50
50
  var MENU_PREFIX = classname.getPrefixCls('menu');
51
+ var hiddenStyle = {
52
+ position: 'absolute',
53
+ opacity: 0,
54
+ order: 9999,
55
+ visibility: 'hidden'
56
+ };
51
57
  var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
52
58
  var _cx, _cx2;
53
59
 
@@ -62,7 +68,11 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
62
68
  level = _a$level === void 0 ? 1 : _a$level,
63
69
  children = _a.children,
64
70
  parentIds = _a.parentIds,
65
- rest = tslib.__rest(_a, ["prefixCls", "className", "icon", "title", "disabled", "id", "level", "children", "parentIds"]);
71
+ _a$hidden = _a.hidden,
72
+ hidden = _a$hidden === void 0 ? false : _a$hidden,
73
+ render = _a.render,
74
+ raw = _a.raw,
75
+ rest = tslib.__rest(_a, ["prefixCls", "className", "icon", "title", "disabled", "id", "level", "children", "parentIds", "hidden", "render", "raw"]);
66
76
 
67
77
  var itemRef = React.useRef(null);
68
78
 
@@ -85,7 +95,8 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
85
95
  var mergedRef = useMergeRefs.useMergeRefs(itemRef, ref);
86
96
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("li", Object.assign({
87
97
  ref: mergedRef,
88
- className: classname.cx(prefixCls + "-item", (_cx = {}, _cx[prefixCls + "-item__inner--mini"] = mini, _cx[prefixCls + "-item--disabled"] = disabled, _cx[prefixCls + "-item--active"] = placement === 'horizontal' && (activeId === id || (activeParents === null || activeParents === void 0 ? void 0 : activeParents.includes(id))) && level === 1, _cx), className)
98
+ className: classname.cx(prefixCls + "-item", (_cx = {}, _cx[prefixCls + "-item__inner--mini"] = mini, _cx[prefixCls + "-item--disabled"] = disabled, _cx[prefixCls + "-item--active"] = placement === 'horizontal' && (activeId === id || (activeParents === null || activeParents === void 0 ? void 0 : activeParents.includes(id))) && level === 1, _cx), className),
99
+ style: hidden ? hiddenStyle : undefined
89
100
  }, rest), /*#__PURE__*/React__default["default"].createElement("div", {
90
101
  className: classname.cx(prefixCls + "-item__inner", (_cx2 = {}, _cx2[prefixCls + "-item__inner--active"] = activeId === id, _cx2[prefixCls + "-item__inner--active-p"] = activeParents === null || activeParents === void 0 ? void 0 : activeParents.includes(id), _cx2[prefixCls + "-item__inner--expanded"] = expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id), _cx2)),
91
102
  onClick: function onClick() {
@@ -95,7 +106,8 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
95
106
  }
96
107
  } else {
97
108
  if (clickMenu) {
98
- clickMenu(id);
109
+ // @ts-ignore
110
+ clickMenu(id, raw);
99
111
  }
100
112
 
101
113
  if (closeAllPopper && !(placement === 'vertical' && expandedType === 'collapse' && mini === false)) {
@@ -110,7 +122,11 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
110
122
  className: prefixCls + "-item__icon"
111
123
  }, icon) : null, /*#__PURE__*/React__default["default"].createElement("span", {
112
124
  className: prefixCls + "-item__content"
113
- }, title), hasChildren && !mini && placement === 'vertical' && expandedType === 'collapse' && !showAllSubMenus && ((expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id)) ? /*#__PURE__*/React__default["default"].createElement(Arrow, {
125
+ }, typeAssertion.isFunction(render) ? render({
126
+ id: id,
127
+ icon: icon,
128
+ title: title
129
+ }) : title), hasChildren && !mini && placement === 'vertical' && expandedType === 'collapse' && !showAllSubMenus && ((expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id)) ? /*#__PURE__*/React__default["default"].createElement(Arrow, {
114
130
  prefixCls: prefixCls + "-item",
115
131
  direction: "up"
116
132
  }) : /*#__PURE__*/React__default["default"].createElement(Arrow, {
@@ -136,7 +152,8 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
136
152
  return /*#__PURE__*/React__default["default"].createElement(MenuItem, Object.assign({}, child, {
137
153
  key: child.id,
138
154
  level: level + 1,
139
- parentIds: _parentIds
155
+ parentIds: _parentIds,
156
+ raw: child
140
157
  }));
141
158
  }))) : null), hasChildren && placement === 'vertical' && mini && !showAllSubMenus && expandedType === 'collapse' && (level === 1 ? /*#__PURE__*/React__default["default"].createElement(Popper__default["default"], {
142
159
  visible: !!(expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id)),
@@ -236,7 +253,7 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
236
253
  return /*#__PURE__*/React__default["default"].createElement("div", {
237
254
  onClick: function onClick() {
238
255
  if (clickMenu) {
239
- clickMenu(item.id);
256
+ clickMenu(item.id, item);
240
257
  }
241
258
 
242
259
  if (closePopper) {
@@ -309,7 +326,7 @@ var MenuItem = /*#__PURE__*/React.forwardRef(function (_a, ref) {
309
326
  className: classname.cx(prefixCls + "-item", (_cx4 = {}, _cx4[prefixCls + "-item--active"] = activeId === item.id, _cx4)),
310
327
  onClick: function onClick() {
311
328
  if (clickMenu) {
312
- clickMenu(item.id);
329
+ clickMenu(item.id, item);
313
330
  }
314
331
 
315
332
  if (closePopper) {
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
package/lib/cjs/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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,9 +12,9 @@
12
12
  Object.defineProperty(exports, '__esModule', {
13
13
  value: true
14
14
  });
15
- var css_248z = "@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n.hi-v4-menu-fat-menu {\n background-color: var(--hi-v4-color-static-white, #fff);\n margin: 0;\n font-size: var(--hi-v4-text-size-normal, 0.875rem);\n padding: var(--hi-v4-spacing-4, 8px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n color: var(--hi-v4-color-gray-700, #1f2733);\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n -ms-flex-wrap: wrap;\n flex-wrap: wrap; }\n.hi-v4-menu-fat-menu__group:not(:last-of-type) {\n margin-right: var(--hi-v4-spacing-18, 36px); }\n.hi-v4-menu-fat-menu .hi-v4-menu-group-item {\n height: 40px;\n margin: 0;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding: 0 var(--hi-v4-spacing-6, 12px);\n color: var(--hi-v4-color-gray-500, #929aa6); }\n.hi-v4-menu-fat-menu .hi-v4-menu-item {\n height: 40px;\n margin: 0;\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px); }\n.hi-v4-menu-fat-menu .hi-v4-menu-item--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));\n background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }\n.hi-v4-menu-fat-menu .hi-v4-menu-item:not(.hi-v4-menu-item--active):hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu-fat-menu ul {\n padding: 0;\n margin: 0; }\n.hi-v4-menu-fat-menu ul li {\n list-style-type: none; }\n.hi-v4-menu-popmenu {\n background-color: var(--hi-v4-color-static-white, #fff);\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n margin: 0;\n font-size: var(--hi-v4-text-size-normal, 0.875rem);\n padding: var(--hi-v4-spacing-4, 8px);\n color: var(--hi-v4-color-gray-700, #1f2733);\n width: 216px;\n -webkit-box-sizing: border-box;\n box-sizing: border-box; }\n.hi-v4-menu-popmenu .hi-v4-menu-item {\n height: 40px;\n margin: 0; }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n height: 40px;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n margin-bottom: var(--hi-v4-spacing-4, 8px);\n padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);\n border-radius: var(--hi-v4-border-radius-normal, 4px); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));\n background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active-p {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner--expanded {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__content {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n max-width: 100%;\n padding-right: var(--hi-v4-spacing-4, 8px); }\n.hi-v4-menu {\n background-color: var(--hi-v4-color-static-white, #fff);\n color: var(--hi-v4-color-gray-700, #1f2733);\n font-size: var(--hi-v4-text-size-normal, 0.875rem);\n line-height: var(--hi-v4-text-lineheight-normal, 1.375rem);\n -webkit-box-sizing: border-box;\n box-sizing: border-box; }\n.hi-v4-menu ul {\n margin: 0;\n padding: 0; }\n.hi-v4-menu-item {\n list-style: none;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n cursor: pointer;\n -webkit-transition: all 0.3s;\n transition: all 0.3s; }\n.hi-v4-menu-item__icon {\n color: var(--hi-v4-color-gray-500, #929aa6);\n -webkit-margin-end: var(--hi-v4-spacing-4, 8px);\n margin-inline-end: var(--hi-v4-spacing-4, 8px); }\n.hi-v4-menu-item__icon svg[class^=hi-v4-icon] {\n font-size: var(--hi-v4-text-size-lg, 1rem); }\n.hi-v4-menu-item__arrow {\n color: var(--hi-v4-color-gray-500, #929aa6);\n font-size: var(--hi-v4-text-size-lg, 1rem); }\n.hi-v4-menu-item__indent {\n display: inline-block;\n width: 24px;\n height: 100%;\n -ms-flex-negative: 0;\n flex-shrink: 0; }\n.hi-v4-menu__wrapper {\n padding: 0;\n margin: 0; }\n.hi-v4-menu--horizontal {\n width: 100%;\n overflow-x: auto; }\n.hi-v4-menu--horizontal .hi-v4-menu__wrapper {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n overflow: visible;\n width: -webkit-max-content;\n width: -moz-max-content;\n width: max-content;\n -webkit-box-sizing: border-box;\n box-sizing: border-box; }\n.hi-v4-menu--horizontal .hi-v4-menu-item {\n margin: 0 var(--hi-v4-spacing-10, 20px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n height: 56px;\n border: none;\n font-size: var(--hi-v4-text-size-lg, 1rem); }\n.hi-v4-menu--horizontal .hi-v4-menu-item__arrow {\n -webkit-margin-start: var(--hi-v4-spacing-2, 4px);\n margin-inline-start: var(--hi-v4-spacing-2, 4px); }\n.hi-v4-menu--horizontal .hi-v4-menu-item:hover {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item:hover .hi-v4-menu-item__inner {\n border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__inner {\n border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active-p {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active-p .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item__inner {\n height: 100%;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n border-bottom: 2px solid transparent; }\n.hi-v4-menu--horizontal .hi-v4-menu-item__inner--expanded {\n border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item__content {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n white-space: nowrap;\n max-width: none; }\n.hi-v4-menu--vertical {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-orient: vertical;\n -webkit-box-direction: normal;\n -ms-flex-direction: column;\n flex-direction: column;\n padding: var(--hi-v4-spacing-4, 8px);\n width: 216px;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n height: 100%;\n -webkit-transition: width 0.3s;\n transition: width 0.3s; }\n.hi-v4-menu--vertical .hi-v4-menu__wrapper {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n overflow: auto; }\n.hi-v4-menu--vertical.hi-v4-menu--mini {\n width: 56px;\n overflow-x: hidden; }\n.hi-v4-menu--vertical.hi-v4-menu--popup .hi-v4-menu-item__inner--expanded {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu--vertical .hi-v4-menu__toggle {\n width: 40px;\n cursor: pointer;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n color: var(--hi-v4-color-gray-500, #929aa6);\n height: 40px; }\n.hi-v4-menu--vertical .hi-v4-menu__toggle:hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n height: 40px;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n margin-bottom: var(--hi-v4-spacing-4, 8px);\n padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n -webkit-transition: all 0.3s;\n transition: all 0.3s; }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));\n background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu--vertical .hi-v4-menu-item__content {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n text-indent: 0.5px; }\n";
15
+ var css_248z = ".hi-v4-menu-fat-menu {background-color: var(--hi-v4-color-static-white, #fff);margin: 0;font-size: var(--hi-v4-text-size-md, 0.875rem);padding: var(--hi-v4-spacing-4, 8px);display: -webkit-box;display: -ms-flexbox;display: flex;color: var(--hi-v4-color-gray-700, #1f2733);border-radius: var(--hi-v4-border-radius-md, 4px);-ms-flex-wrap: wrap;flex-wrap: wrap; }.hi-v4-menu-fat-menu__group:not(:last-of-type) {margin-right: var(--hi-v4-spacing-18, 36px); }.hi-v4-menu-fat-menu .hi-v4-menu-group-item {height: 40px;margin: 0;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;padding: 0 var(--hi-v4-spacing-6, 12px);color: var(--hi-v4-color-gray-500, #929aa6); }.hi-v4-menu-fat-menu .hi-v4-menu-item {height: 40px;margin: 0;border-radius: var(--hi-v4-border-radius-md, 4px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px); }.hi-v4-menu-fat-menu .hi-v4-menu-item--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-menu-fat-menu .hi-v4-menu-item:not(.hi-v4-menu-item--active):hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu-fat-menu ul {padding: 0;margin: 0; }.hi-v4-menu-fat-menu ul li {list-style-type: none; }.hi-v4-menu-popmenu {background-color: var(--hi-v4-color-static-white, #fff);border-radius: var(--hi-v4-border-radius-md, 4px);margin: 0;font-size: var(--hi-v4-text-size-md, 0.875rem);padding: var(--hi-v4-spacing-4, 8px);color: var(--hi-v4-color-gray-700, #1f2733);width: 216px;-webkit-box-sizing: border-box;box-sizing: border-box; }.hi-v4-menu-popmenu .hi-v4-menu-item {height: 40px;margin: 0; }.hi-v4-menu-popmenu .hi-v4-menu-item__inner {-webkit-box-sizing: border-box;box-sizing: border-box;height: 40px;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;margin-bottom: var(--hi-v4-spacing-4, 8px);padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);border-radius: var(--hi-v4-border-radius-md, 4px); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active-p {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner--expanded {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu-popmenu .hi-v4-menu-item__content {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width: 100%;padding-right: var(--hi-v4-spacing-4, 8px); }.hi-v4-menu {background-color: var(--hi-v4-color-static-white, #fff);color: var(--hi-v4-color-gray-700, #1f2733);font-size: var(--hi-v4-text-size-md, 0.875rem);line-height: var(--hi-v4-text-lineheight-md, 1.375rem);-webkit-box-sizing: border-box;box-sizing: border-box; }.hi-v4-menu ul {margin: 0;padding: 0; }.hi-v4-menu-item {list-style: none;-webkit-box-sizing: border-box;box-sizing: border-box;cursor: pointer;-webkit-transition: all 0.3s;transition: all 0.3s; }.hi-v4-menu-item__icon {color: var(--hi-v4-color-gray-500, #929aa6);-webkit-margin-end: var(--hi-v4-spacing-4, 8px);margin-inline-end: var(--hi-v4-spacing-4, 8px); }.hi-v4-menu-item__icon svg[class^=hi-v4-icon] {font-size: var(--hi-v4-text-size-lg, 1rem); }.hi-v4-menu-item__arrow {color: var(--hi-v4-color-gray-500, #929aa6);font-size: var(--hi-v4-text-size-lg, 1rem); }.hi-v4-menu-item__indent {display: inline-block;width: 24px;height: 100%;-ms-flex-negative: 0;flex-shrink: 0; }.hi-v4-menu__wrapper {padding: 0;margin: 0; }.hi-v4-menu--horizontal {width: 100%;overflow: hidden; }.hi-v4-menu--horizontal .hi-v4-menu__wrapper {display: -webkit-box;display: -ms-flexbox;display: flex;overflow: visible;width: -webkit-max-content;width: -moz-max-content;width: max-content;-webkit-box-sizing: border-box;box-sizing: border-box; }.hi-v4-menu--horizontal .hi-v4-menu-item {padding: 0 var(--hi-v4-spacing-10, 20px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;-webkit-box-align: center;-ms-flex-align: center;align-items: center;height: 56px;border: none;font-size: var(--hi-v4-text-size-lg, 1rem); }.hi-v4-menu--horizontal .hi-v4-menu-item__arrow {-webkit-margin-start: var(--hi-v4-spacing-2, 4px);margin-inline-start: var(--hi-v4-spacing-2, 4px); }.hi-v4-menu--horizontal .hi-v4-menu-item:hover {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item:hover .hi-v4-menu-item__inner {border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__inner {border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active-p {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active-p .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item__inner {height: 100%;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;border-bottom: 2px solid transparent; }.hi-v4-menu--horizontal .hi-v4-menu-item__inner--expanded {border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item__content {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;white-space: nowrap;max-width: none; }.hi-v4-menu--vertical {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;padding: var(--hi-v4-spacing-4, 8px);width: 216px;-webkit-box-sizing: border-box;box-sizing: border-box;height: 100%;-webkit-transition: width 0.3s;transition: width 0.3s; }.hi-v4-menu--vertical .hi-v4-menu__wrapper {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;overflow: auto; }.hi-v4-menu--vertical.hi-v4-menu--mini {width: 56px;overflow-x: hidden; }.hi-v4-menu--vertical.hi-v4-menu--popup .hi-v4-menu-item__inner--expanded {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu--vertical .hi-v4-menu__toggle {width: 40px;cursor: pointer;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;border-radius: var(--hi-v4-border-radius-md, 4px);color: var(--hi-v4-color-gray-500, #929aa6);height: 40px;-ms-flex-negative: 0;flex-shrink: 0;-webkit-transition-duration: var(--hi-v4-motion-duration-normal, 200ms);transition-duration: var(--hi-v4-motion-duration-normal, 200ms);-webkit-transition-timing-function: var(--hi-v4-motion-bezier-easing, cubic-bezier(0.37, 0.02, 0.34, 1));transition-timing-function: var(--hi-v4-motion-bezier-easing, cubic-bezier(0.37, 0.02, 0.34, 1));-webkit-transition-property: background-color;transition-property: background-color; }.hi-v4-menu--vertical .hi-v4-menu__toggle:hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu--vertical .hi-v4-menu-item__inner {-webkit-box-sizing: border-box;box-sizing: border-box;height: 40px;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;margin-bottom: var(--hi-v4-spacing-4, 8px);padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);border-radius: var(--hi-v4-border-radius-md, 4px);-webkit-transition: all 0.3s;transition: all 0.3s; }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu--vertical .hi-v4-menu-item__content {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;text-indent: 0.5px; }";
16
16
 
17
- var __styleInject__ = require('style-inject/dist/style-inject.es.js')["default"];
17
+ var __styleInject__ = require('inject-head-style')["default"];
18
18
 
19
19
  __styleInject__(css_248z);
20
20
 
package/lib/cjs/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
package/lib/esm/Menu.js CHANGED
@@ -2,13 +2,13 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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, useState, useEffect, useCallback } from 'react';
11
+ import React, { forwardRef, useState, useEffect, useCallback, useMemo, useLayoutEffect } from 'react';
12
12
  import { getPrefixCls, cx } from '@hi-ui/classname';
13
13
  import { MenuUnfoldOutlined, MenuFoldOutlined } from '@hi-ui/icons';
14
14
  import { __DEV__ } from '@hi-ui/env';
@@ -17,84 +17,200 @@ import MenuContext from './context.js';
17
17
  import { getAncestorIds } from './util.js';
18
18
  import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
19
19
  import Tooltip from '@hi-ui/tooltip';
20
+ import { useUncontrolledToggle } from '@hi-ui/use-toggle';
21
+ import { getTreeNodesWithChildren } from '@hi-ui/tree-utils';
22
+ import { isArrayNonEmpty, isFunction } from '@hi-ui/type-assertion';
23
+ import { useResizeObserver } from '@hi-ui/use-resize-observer';
24
+ import { useMergeRefs } from '@hi-ui/use-merge-refs';
25
+ import { uuid } from '@hi-ui/use-id';
20
26
  var MENU_PREFIX = getPrefixCls('menu');
27
+ var DEFAULT_EXPANDED_IDS = [];
28
+ var NOOP_ARRAY = [];
29
+ var MIN_WIDTH = 56;
30
+ var MENU_MORE_ID = "MENU_MORE_" + uuid();
21
31
  /**
22
32
  * TODO: What is Menu
23
33
  */
24
34
 
25
35
  var Menu = /*#__PURE__*/forwardRef(function (_a, ref) {
26
- var _cx;
27
-
28
36
  var _a$prefixCls = _a.prefixCls,
29
37
  prefixCls = _a$prefixCls === void 0 ? MENU_PREFIX : _a$prefixCls,
30
38
  _a$role = _a.role,
31
39
  role = _a$role === void 0 ? 'menu' : _a$role,
32
40
  className = _a.className,
33
- data = _a.data,
41
+ _a$data = _a.data,
42
+ data = _a$data === void 0 ? NOOP_ARRAY : _a$data,
34
43
  _a$placement = _a.placement,
35
44
  placement = _a$placement === void 0 ? 'vertical' : _a$placement,
36
- showCollapse = _a.showCollapse,
45
+ _a$showCollapse = _a.showCollapse,
46
+ showCollapse = _a$showCollapse === void 0 ? false : _a$showCollapse,
37
47
  _a$expandedType = _a.expandedType,
38
48
  expandedType = _a$expandedType === void 0 ? 'collapse' : _a$expandedType,
39
49
  _a$showAllSubMenus = _a.showAllSubMenus,
40
50
  showAllSubMenus = _a$showAllSubMenus === void 0 ? false : _a$showAllSubMenus,
41
- defaultExpandedIds = _a.defaultExpandedIds,
42
- defaultActiveId = _a.defaultActiveId,
43
- activeId = _a.activeId,
51
+ _a$defaultExpandAll = _a.defaultExpandAll,
52
+ defaultExpandAll = _a$defaultExpandAll === void 0 ? false : _a$defaultExpandAll,
53
+ _a$defaultExpandedIds = _a.defaultExpandedIds,
54
+ defaultExpandedIds = _a$defaultExpandedIds === void 0 ? DEFAULT_EXPANDED_IDS : _a$defaultExpandedIds,
55
+ expandedIdsProp = _a.expandedIds,
56
+ onExpand = _a.onExpand,
57
+ _a$defaultActiveId = _a.defaultActiveId,
58
+ defaultActiveId = _a$defaultActiveId === void 0 ? '' : _a$defaultActiveId,
59
+ activeIdProp = _a.activeId,
44
60
  onClickSubMenu = _a.onClickSubMenu,
61
+ collapsed = _a.collapsed,
62
+ _a$defaultCollapsed = _a.defaultCollapsed,
63
+ defaultCollapsed = _a$defaultCollapsed === void 0 ? false : _a$defaultCollapsed,
64
+ onCollapse = _a.onCollapse,
65
+ footerRender = _a.footerRender,
45
66
  onClick = _a.onClick,
46
- rest = __rest(_a, ["prefixCls", "role", "className", "data", "placement", "showCollapse", "expandedType", "showAllSubMenus", "defaultExpandedIds", "defaultActiveId", "activeId", "onClickSubMenu", "onClick"]);
67
+ rest = __rest(_a, ["prefixCls", "role", "className", "data", "placement", "showCollapse", "expandedType", "showAllSubMenus", "defaultExpandAll", "defaultExpandedIds", "expandedIds", "onExpand", "defaultActiveId", "activeId", "onClickSubMenu", "collapsed", "defaultCollapsed", "onCollapse", "footerRender", "onClick"]);
47
68
 
48
- var _useUncontrolledState = useUncontrolledState(defaultActiveId || '', activeId, onClick),
49
- _activeId = _useUncontrolledState[0],
69
+ var _useUncontrolledState = useUncontrolledState(defaultActiveId, activeIdProp, onClick),
70
+ activeId = _useUncontrolledState[0],
50
71
  updateActiveId = _useUncontrolledState[1];
51
72
 
52
- var _useState = useState(getAncestorIds(_activeId, data)),
73
+ var _useState = useState(function () {
74
+ return getAncestorIds(activeId, data);
75
+ }),
53
76
  activeParents = _useState[0],
54
77
  updateActiveParents = _useState[1];
55
78
 
56
79
  useEffect(function () {
57
- updateActiveParents(getAncestorIds(_activeId, data));
58
- }, [_activeId, data]);
80
+ updateActiveParents(getAncestorIds(activeId, data));
81
+ }, [activeId, data]);
59
82
 
60
- var _useState2 = useState(defaultExpandedIds || []),
61
- _expandedIds = _useState2[0],
62
- updateExpanedIds = _useState2[1];
83
+ var _useUncontrolledState2 = useUncontrolledState(function () {
84
+ return defaultExpandAll ? getTreeNodesWithChildren(data).map(function (node) {
85
+ return node.id;
86
+ }) : defaultExpandedIds;
87
+ }, expandedIdsProp, onExpand),
88
+ expandedIds = _useUncontrolledState2[0],
89
+ updateExpandedIds = _useUncontrolledState2[1];
63
90
 
64
- var clickMenu = useCallback(function (id) {
65
- updateActiveId(id);
91
+ var clickMenu = useCallback(function (id, raw) {
92
+ updateActiveId(id, raw);
66
93
  }, [updateActiveId]);
67
94
  var clickSubMenu = useCallback(function (id) {
68
- var expandedIds = _expandedIds.includes(id) ? _expandedIds.filter(function (expandedId) {
95
+ var nextExpandedIds = expandedIds.includes(id) ? expandedIds.filter(function (expandedId) {
69
96
  return expandedId !== id;
70
- }) : _expandedIds.concat(id);
71
- updateExpanedIds(expandedIds);
97
+ }) : expandedIds.concat(id);
98
+ updateExpandedIds(nextExpandedIds);
72
99
 
73
100
  if (onClickSubMenu) {
74
- onClickSubMenu(id, expandedIds);
101
+ onClickSubMenu(id, nextExpandedIds);
75
102
  }
76
- }, [onClickSubMenu, _expandedIds]);
103
+ }, [onClickSubMenu, expandedIds, updateExpandedIds]);
77
104
  var closePopper = useCallback(function (id) {
78
- updateExpanedIds(_expandedIds.filter(function (expandedId) {
105
+ updateExpandedIds(expandedIds.filter(function (expandedId) {
79
106
  return expandedId !== id;
80
107
  }));
81
- }, [_expandedIds]);
108
+ }, [expandedIds, updateExpandedIds]);
82
109
  var closeAllPopper = useCallback(function () {
83
- updateExpanedIds([]);
84
- }, []);
85
-
86
- var _useState3 = useState(false),
87
- mini = _useState3[0],
88
- setMini = _useState3[1];
89
-
90
- var cls = cx(prefixCls, className, prefixCls + "--" + placement, (_cx = {}, _cx[prefixCls + "--mini"] = mini, _cx[prefixCls + "--popup"] = expandedType === 'pop' || showAllSubMenus || mini, _cx));
91
- var onToggle = useCallback(function () {
92
- setMini(!mini);
93
- closeAllPopper();
94
- }, [mini, closeAllPopper]);
95
- var canToggle = placement === 'vertical' && showCollapse;
110
+ updateExpandedIds([]);
111
+ }, [updateExpandedIds]);
112
+
113
+ var _useUncontrolledToggl = useUncontrolledToggle({
114
+ defaultVisible: defaultCollapsed,
115
+ visible: collapsed,
116
+ onToggle: onCollapse
117
+ }),
118
+ mini = _useUncontrolledToggl[0],
119
+ miniToggleAction = _useUncontrolledToggl[1];
120
+
121
+ var showVertical = placement === 'vertical';
122
+ var canToggle = showVertical && showCollapse;
123
+ var showMini = showVertical && mini;
124
+
125
+ var _useState2 = useState(null),
126
+ containerElement = _useState2[0],
127
+ setContainerElement = _useState2[1];
128
+
129
+ var _useState3 = useState(),
130
+ _useState3$ = _useState3[0],
131
+ containerWidth = _useState3$ === void 0 ? 0 : _useState3$,
132
+ setContainerWidth = _useState3[1];
133
+
134
+ useResizeObserver({
135
+ element: containerElement,
136
+ disabled: showVertical,
137
+ getSize: function getSize(element) {
138
+ var itemRect = element.getBoundingClientRect();
139
+ return itemRect.width;
140
+ },
141
+ onResize: function onResize(el, width) {
142
+ setContainerWidth(width);
143
+ }
144
+ });
145
+
146
+ var _useState4 = useState(0),
147
+ tagMaxCount = _useState4[0],
148
+ setTagMaxCount = _useState4[1];
149
+
150
+ var mergedTagList = useMemo(function () {
151
+ if (showVertical) return data;
152
+ if (containerWidth < MIN_WIDTH) return data;
153
+ return data.slice(0, Math.min(data.length, containerWidth / MIN_WIDTH));
154
+ }, [showVertical, data, containerWidth]);
155
+ var restTagList = useMemo(function () {
156
+ if (tagMaxCount > 0) return data.slice(tagMaxCount);
157
+ return [];
158
+ }, [data, tagMaxCount]);
159
+ var getTagWidth = useCallback(function (index) {
160
+ if (!containerElement) return MIN_WIDTH;
161
+ var elements = containerElement.getElementsByClassName('hi-v4-menu-item');
162
+ var element = elements && elements[index];
163
+ if (!element) return MIN_WIDTH;
164
+ return element.getBoundingClientRect().width;
165
+ }, [containerElement]);
166
+ useLayoutEffect(function () {
167
+ if (showVertical) return;
168
+ var tagMaxCount = 0;
169
+
170
+ if (isArrayNonEmpty(mergedTagList)) {
171
+ var len = mergedTagList.length;
172
+ var lastIndex = len - 1;
173
+ var totalWidth = 72; // 更多
174
+
175
+ for (var i = 0; i < len; ++i) {
176
+ var currentTagWidth = getTagWidth(i);
177
+
178
+ if (currentTagWidth === undefined) {
179
+ break;
180
+ }
181
+
182
+ totalWidth += currentTagWidth;
183
+
184
+ if (lastIndex === 0 && totalWidth <= containerWidth || i === lastIndex - 1 && totalWidth + getTagWidth(lastIndex) <= containerWidth) {
185
+ tagMaxCount = lastIndex;
186
+ break;
187
+ } else if (totalWidth > containerWidth) {
188
+ tagMaxCount = i - 1;
189
+ break;
190
+ }
191
+ }
192
+ } else {
193
+ tagMaxCount = 0;
194
+ } // 保底要展示 1 个
195
+
196
+
197
+ setTagMaxCount(isArrayNonEmpty(mergedTagList) && tagMaxCount < 1 ? 1 : tagMaxCount + 1);
198
+ }, [showVertical, getTagWidth, containerWidth, mergedTagList]);
199
+
200
+ var renderFooter = function renderFooter() {
201
+ var collapseNode = canToggle ? /*#__PURE__*/React.createElement("div", {
202
+ className: cx(prefixCls + "__toggle"),
203
+ onClick: miniToggleAction.not
204
+ }, mini ? /*#__PURE__*/React.createElement(MenuUnfoldOutlined, null) : /*#__PURE__*/React.createElement(MenuFoldOutlined, null)) : null;
205
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isFunction(footerRender) ? footerRender({
206
+ collapsed: showMini,
207
+ collapseNode: collapseNode
208
+ }) : collapseNode);
209
+ };
210
+
211
+ var cls = cx(prefixCls, className, prefixCls + "--" + placement, mini && prefixCls + "--mini", (expandedType === 'pop' || showAllSubMenus || mini) && prefixCls + "--popup");
96
212
  return /*#__PURE__*/React.createElement("div", Object.assign({
97
- ref: ref,
213
+ ref: useMergeRefs(ref, setContainerElement),
98
214
  role: role,
99
215
  className: cls
100
216
  }, rest), /*#__PURE__*/React.createElement(MenuContext.Provider, {
@@ -108,30 +224,55 @@ var Menu = /*#__PURE__*/forwardRef(function (_a, ref) {
108
224
  closePopper: closePopper,
109
225
  closeAllPopper: closeAllPopper,
110
226
  activeParents: activeParents,
111
- activeId: _activeId,
112
- expandedIds: _expandedIds
227
+ activeId: activeId,
228
+ expandedIds: expandedIds
113
229
  }
114
230
  }, /*#__PURE__*/React.createElement("ul", {
115
231
  className: cx(prefixCls + "__wrapper")
116
- }, data.map(function (item) {
117
- return canToggle && mini ? /*#__PURE__*/React.createElement(Tooltip, {
232
+ }, mergedTagList.map(function (item, index) {
233
+ return showMini ? /*#__PURE__*/React.createElement(Tooltip, {
118
234
  title: item.title,
119
235
  key: item.id,
120
236
  placement: "right"
121
237
  }, /*#__PURE__*/React.createElement(MenuItem, Object.assign({}, item, {
122
- level: 1
123
- }))) : /*#__PURE__*/React.createElement(MenuItem, Object.assign({}, item, {
238
+ level: 1,
239
+ render: renderMenuItemMini,
240
+ raw: item
241
+ }))) : /*#__PURE__*/React.createElement(MenuItem, Object.assign({
242
+ hidden: !showVertical && index >= tagMaxCount
243
+ }, item, {
124
244
  key: item.id,
125
- level: 1
245
+ level: 1,
246
+ raw: item
126
247
  }));
127
- })), canToggle ? /*#__PURE__*/React.createElement("div", {
128
- className: cx(prefixCls + "__toggle"),
129
- onClick: onToggle
130
- }, mini ? /*#__PURE__*/React.createElement(MenuUnfoldOutlined, null) : /*#__PURE__*/React.createElement(MenuFoldOutlined, null)) : null));
248
+ }), showVertical || restTagList.length === 0 ? null : /*#__PURE__*/React.createElement(MenuItem, {
249
+ key: MENU_MORE_ID,
250
+ id: MENU_MORE_ID,
251
+ title: "\u66F4\u591A",
252
+ children: restTagList
253
+ })), /*#__PURE__*/React.createElement("div", {
254
+ className: prefixCls + "__footer"
255
+ }, renderFooter())));
131
256
  });
132
257
 
133
258
  if (__DEV__) {
134
259
  Menu.displayName = 'Menu';
135
260
  }
261
+ /**
262
+ * Mini 模式下渲染 item
263
+ */
264
+
265
+
266
+ var renderMenuItemMini = function renderMenuItemMini(menu) {
267
+ if (typeof menu.icon !== 'undefined') {
268
+ return menu.icon;
269
+ }
270
+
271
+ if (typeof menu.title === 'string') {
272
+ return menu.title.substring(0, 1);
273
+ }
274
+
275
+ return menu.title;
276
+ };
136
277
 
137
278
  export { Menu };
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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,10 +15,16 @@ import { RightOutlined, DownOutlined, UpOutlined } from '@hi-ui/icons';
15
15
  import MenuContext from './context.js';
16
16
  import Popper from '@hi-ui/popper';
17
17
  import { Expander } from './Expander.js';
18
- import { isArrayNonEmpty } from '@hi-ui/type-assertion';
18
+ import { isArrayNonEmpty, isFunction } from '@hi-ui/type-assertion';
19
19
  import { times } from '@hi-ui/array-utils';
20
20
  import { useMergeRefs } from '@hi-ui/use-merge-refs';
21
21
  var MENU_PREFIX = getPrefixCls('menu');
22
+ var hiddenStyle = {
23
+ position: 'absolute',
24
+ opacity: 0,
25
+ order: 9999,
26
+ visibility: 'hidden'
27
+ };
22
28
  var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
23
29
  var _cx, _cx2;
24
30
 
@@ -33,7 +39,11 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
33
39
  level = _a$level === void 0 ? 1 : _a$level,
34
40
  children = _a.children,
35
41
  parentIds = _a.parentIds,
36
- rest = __rest(_a, ["prefixCls", "className", "icon", "title", "disabled", "id", "level", "children", "parentIds"]);
42
+ _a$hidden = _a.hidden,
43
+ hidden = _a$hidden === void 0 ? false : _a$hidden,
44
+ render = _a.render,
45
+ raw = _a.raw,
46
+ rest = __rest(_a, ["prefixCls", "className", "icon", "title", "disabled", "id", "level", "children", "parentIds", "hidden", "render", "raw"]);
37
47
 
38
48
  var itemRef = useRef(null);
39
49
 
@@ -56,7 +66,8 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
56
66
  var mergedRef = useMergeRefs(itemRef, ref);
57
67
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("li", Object.assign({
58
68
  ref: mergedRef,
59
- className: cx(prefixCls + "-item", (_cx = {}, _cx[prefixCls + "-item__inner--mini"] = mini, _cx[prefixCls + "-item--disabled"] = disabled, _cx[prefixCls + "-item--active"] = placement === 'horizontal' && (activeId === id || (activeParents === null || activeParents === void 0 ? void 0 : activeParents.includes(id))) && level === 1, _cx), className)
69
+ className: cx(prefixCls + "-item", (_cx = {}, _cx[prefixCls + "-item__inner--mini"] = mini, _cx[prefixCls + "-item--disabled"] = disabled, _cx[prefixCls + "-item--active"] = placement === 'horizontal' && (activeId === id || (activeParents === null || activeParents === void 0 ? void 0 : activeParents.includes(id))) && level === 1, _cx), className),
70
+ style: hidden ? hiddenStyle : undefined
60
71
  }, rest), /*#__PURE__*/React.createElement("div", {
61
72
  className: cx(prefixCls + "-item__inner", (_cx2 = {}, _cx2[prefixCls + "-item__inner--active"] = activeId === id, _cx2[prefixCls + "-item__inner--active-p"] = activeParents === null || activeParents === void 0 ? void 0 : activeParents.includes(id), _cx2[prefixCls + "-item__inner--expanded"] = expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id), _cx2)),
62
73
  onClick: function onClick() {
@@ -66,7 +77,8 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
66
77
  }
67
78
  } else {
68
79
  if (clickMenu) {
69
- clickMenu(id);
80
+ // @ts-ignore
81
+ clickMenu(id, raw);
70
82
  }
71
83
 
72
84
  if (closeAllPopper && !(placement === 'vertical' && expandedType === 'collapse' && mini === false)) {
@@ -81,7 +93,11 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
81
93
  className: prefixCls + "-item__icon"
82
94
  }, icon) : null, /*#__PURE__*/React.createElement("span", {
83
95
  className: prefixCls + "-item__content"
84
- }, title), hasChildren && !mini && placement === 'vertical' && expandedType === 'collapse' && !showAllSubMenus && ((expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id)) ? /*#__PURE__*/React.createElement(Arrow, {
96
+ }, isFunction(render) ? render({
97
+ id: id,
98
+ icon: icon,
99
+ title: title
100
+ }) : title), hasChildren && !mini && placement === 'vertical' && expandedType === 'collapse' && !showAllSubMenus && ((expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id)) ? /*#__PURE__*/React.createElement(Arrow, {
85
101
  prefixCls: prefixCls + "-item",
86
102
  direction: "up"
87
103
  }) : /*#__PURE__*/React.createElement(Arrow, {
@@ -107,7 +123,8 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
107
123
  return /*#__PURE__*/React.createElement(MenuItem, Object.assign({}, child, {
108
124
  key: child.id,
109
125
  level: level + 1,
110
- parentIds: _parentIds
126
+ parentIds: _parentIds,
127
+ raw: child
111
128
  }));
112
129
  }))) : null), hasChildren && placement === 'vertical' && mini && !showAllSubMenus && expandedType === 'collapse' && (level === 1 ? /*#__PURE__*/React.createElement(Popper, {
113
130
  visible: !!(expandedIds === null || expandedIds === void 0 ? void 0 : expandedIds.includes(id)),
@@ -207,7 +224,7 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
207
224
  return /*#__PURE__*/React.createElement("div", {
208
225
  onClick: function onClick() {
209
226
  if (clickMenu) {
210
- clickMenu(item.id);
227
+ clickMenu(item.id, item);
211
228
  }
212
229
 
213
230
  if (closePopper) {
@@ -280,7 +297,7 @@ var MenuItem = /*#__PURE__*/forwardRef(function (_a, ref) {
280
297
  className: cx(prefixCls + "-item", (_cx4 = {}, _cx4[prefixCls + "-item--active"] = activeId === item.id, _cx4)),
281
298
  onClick: function onClick() {
282
299
  if (clickMenu) {
283
- clickMenu(item.id);
300
+ clickMenu(item.id, item);
284
301
  }
285
302
 
286
303
  if (closePopper) {
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
package/lib/esm/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
@@ -2,14 +2,13 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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
- var css_248z = "@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n@use 'sass:map';\n.hi-v4-menu-fat-menu {\n background-color: var(--hi-v4-color-static-white, #fff);\n margin: 0;\n font-size: var(--hi-v4-text-size-normal, 0.875rem);\n padding: var(--hi-v4-spacing-4, 8px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n color: var(--hi-v4-color-gray-700, #1f2733);\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n -ms-flex-wrap: wrap;\n flex-wrap: wrap; }\n.hi-v4-menu-fat-menu__group:not(:last-of-type) {\n margin-right: var(--hi-v4-spacing-18, 36px); }\n.hi-v4-menu-fat-menu .hi-v4-menu-group-item {\n height: 40px;\n margin: 0;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding: 0 var(--hi-v4-spacing-6, 12px);\n color: var(--hi-v4-color-gray-500, #929aa6); }\n.hi-v4-menu-fat-menu .hi-v4-menu-item {\n height: 40px;\n margin: 0;\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px); }\n.hi-v4-menu-fat-menu .hi-v4-menu-item--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));\n background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }\n.hi-v4-menu-fat-menu .hi-v4-menu-item:not(.hi-v4-menu-item--active):hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu-fat-menu ul {\n padding: 0;\n margin: 0; }\n.hi-v4-menu-fat-menu ul li {\n list-style-type: none; }\n.hi-v4-menu-popmenu {\n background-color: var(--hi-v4-color-static-white, #fff);\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n margin: 0;\n font-size: var(--hi-v4-text-size-normal, 0.875rem);\n padding: var(--hi-v4-spacing-4, 8px);\n color: var(--hi-v4-color-gray-700, #1f2733);\n width: 216px;\n -webkit-box-sizing: border-box;\n box-sizing: border-box; }\n.hi-v4-menu-popmenu .hi-v4-menu-item {\n height: 40px;\n margin: 0; }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n height: 40px;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n margin-bottom: var(--hi-v4-spacing-4, 8px);\n padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);\n border-radius: var(--hi-v4-border-radius-normal, 4px); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));\n background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active-p {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner--expanded {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu-popmenu .hi-v4-menu-item__content {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n max-width: 100%;\n padding-right: var(--hi-v4-spacing-4, 8px); }\n.hi-v4-menu {\n background-color: var(--hi-v4-color-static-white, #fff);\n color: var(--hi-v4-color-gray-700, #1f2733);\n font-size: var(--hi-v4-text-size-normal, 0.875rem);\n line-height: var(--hi-v4-text-lineheight-normal, 1.375rem);\n -webkit-box-sizing: border-box;\n box-sizing: border-box; }\n.hi-v4-menu ul {\n margin: 0;\n padding: 0; }\n.hi-v4-menu-item {\n list-style: none;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n cursor: pointer;\n -webkit-transition: all 0.3s;\n transition: all 0.3s; }\n.hi-v4-menu-item__icon {\n color: var(--hi-v4-color-gray-500, #929aa6);\n -webkit-margin-end: var(--hi-v4-spacing-4, 8px);\n margin-inline-end: var(--hi-v4-spacing-4, 8px); }\n.hi-v4-menu-item__icon svg[class^=hi-v4-icon] {\n font-size: var(--hi-v4-text-size-lg, 1rem); }\n.hi-v4-menu-item__arrow {\n color: var(--hi-v4-color-gray-500, #929aa6);\n font-size: var(--hi-v4-text-size-lg, 1rem); }\n.hi-v4-menu-item__indent {\n display: inline-block;\n width: 24px;\n height: 100%;\n -ms-flex-negative: 0;\n flex-shrink: 0; }\n.hi-v4-menu__wrapper {\n padding: 0;\n margin: 0; }\n.hi-v4-menu--horizontal {\n width: 100%;\n overflow-x: auto; }\n.hi-v4-menu--horizontal .hi-v4-menu__wrapper {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n overflow: visible;\n width: -webkit-max-content;\n width: -moz-max-content;\n width: max-content;\n -webkit-box-sizing: border-box;\n box-sizing: border-box; }\n.hi-v4-menu--horizontal .hi-v4-menu-item {\n margin: 0 var(--hi-v4-spacing-10, 20px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n height: 56px;\n border: none;\n font-size: var(--hi-v4-text-size-lg, 1rem); }\n.hi-v4-menu--horizontal .hi-v4-menu-item__arrow {\n -webkit-margin-start: var(--hi-v4-spacing-2, 4px);\n margin-inline-start: var(--hi-v4-spacing-2, 4px); }\n.hi-v4-menu--horizontal .hi-v4-menu-item:hover {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item:hover .hi-v4-menu-item__inner {\n border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__inner {\n border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active-p {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item--active-p .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item__inner {\n height: 100%;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n border-bottom: 2px solid transparent; }\n.hi-v4-menu--horizontal .hi-v4-menu-item__inner--expanded {\n border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--horizontal .hi-v4-menu-item__content {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n white-space: nowrap;\n max-width: none; }\n.hi-v4-menu--vertical {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-orient: vertical;\n -webkit-box-direction: normal;\n -ms-flex-direction: column;\n flex-direction: column;\n padding: var(--hi-v4-spacing-4, 8px);\n width: 216px;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n height: 100%;\n -webkit-transition: width 0.3s;\n transition: width 0.3s; }\n.hi-v4-menu--vertical .hi-v4-menu__wrapper {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n overflow: auto; }\n.hi-v4-menu--vertical.hi-v4-menu--mini {\n width: 56px;\n overflow-x: hidden; }\n.hi-v4-menu--vertical.hi-v4-menu--popup .hi-v4-menu-item__inner--expanded {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu--vertical .hi-v4-menu__toggle {\n width: 40px;\n cursor: pointer;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n color: var(--hi-v4-color-gray-500, #929aa6);\n height: 40px; }\n.hi-v4-menu--vertical .hi-v4-menu__toggle:hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n height: 40px;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n margin-bottom: var(--hi-v4-spacing-4, 8px);\n padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);\n border-radius: var(--hi-v4-border-radius-normal, 4px);\n -webkit-transition: all 0.3s;\n transition: all 0.3s; }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));\n background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p .hi-v4-menu-item__icon {\n color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }\n.hi-v4-menu--vertical .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {\n background-color: var(--hi-v4-color-gray-100, #f2f4f7); }\n.hi-v4-menu--vertical .hi-v4-menu-item__content {\n -webkit-box-flex: 1;\n -ms-flex: 1 1;\n flex: 1 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n text-indent: 0.5px; }\n";
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-menu-fat-menu {background-color: var(--hi-v4-color-static-white, #fff);margin: 0;font-size: var(--hi-v4-text-size-md, 0.875rem);padding: var(--hi-v4-spacing-4, 8px);display: -webkit-box;display: -ms-flexbox;display: flex;color: var(--hi-v4-color-gray-700, #1f2733);border-radius: var(--hi-v4-border-radius-md, 4px);-ms-flex-wrap: wrap;flex-wrap: wrap; }.hi-v4-menu-fat-menu__group:not(:last-of-type) {margin-right: var(--hi-v4-spacing-18, 36px); }.hi-v4-menu-fat-menu .hi-v4-menu-group-item {height: 40px;margin: 0;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;padding: 0 var(--hi-v4-spacing-6, 12px);color: var(--hi-v4-color-gray-500, #929aa6); }.hi-v4-menu-fat-menu .hi-v4-menu-item {height: 40px;margin: 0;border-radius: var(--hi-v4-border-radius-md, 4px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px); }.hi-v4-menu-fat-menu .hi-v4-menu-item--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-menu-fat-menu .hi-v4-menu-item:not(.hi-v4-menu-item--active):hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu-fat-menu ul {padding: 0;margin: 0; }.hi-v4-menu-fat-menu ul li {list-style-type: none; }.hi-v4-menu-popmenu {background-color: var(--hi-v4-color-static-white, #fff);border-radius: var(--hi-v4-border-radius-md, 4px);margin: 0;font-size: var(--hi-v4-text-size-md, 0.875rem);padding: var(--hi-v4-spacing-4, 8px);color: var(--hi-v4-color-gray-700, #1f2733);width: 216px;-webkit-box-sizing: border-box;box-sizing: border-box; }.hi-v4-menu-popmenu .hi-v4-menu-item {height: 40px;margin: 0; }.hi-v4-menu-popmenu .hi-v4-menu-item__inner {-webkit-box-sizing: border-box;box-sizing: border-box;height: 40px;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;margin-bottom: var(--hi-v4-spacing-4, 8px);padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);border-radius: var(--hi-v4-border-radius-md, 4px); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner--active-p {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner--expanded {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu-popmenu .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu-popmenu .hi-v4-menu-item__content {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width: 100%;padding-right: var(--hi-v4-spacing-4, 8px); }.hi-v4-menu {background-color: var(--hi-v4-color-static-white, #fff);color: var(--hi-v4-color-gray-700, #1f2733);font-size: var(--hi-v4-text-size-md, 0.875rem);line-height: var(--hi-v4-text-lineheight-md, 1.375rem);-webkit-box-sizing: border-box;box-sizing: border-box; }.hi-v4-menu ul {margin: 0;padding: 0; }.hi-v4-menu-item {list-style: none;-webkit-box-sizing: border-box;box-sizing: border-box;cursor: pointer;-webkit-transition: all 0.3s;transition: all 0.3s; }.hi-v4-menu-item__icon {color: var(--hi-v4-color-gray-500, #929aa6);-webkit-margin-end: var(--hi-v4-spacing-4, 8px);margin-inline-end: var(--hi-v4-spacing-4, 8px); }.hi-v4-menu-item__icon svg[class^=hi-v4-icon] {font-size: var(--hi-v4-text-size-lg, 1rem); }.hi-v4-menu-item__arrow {color: var(--hi-v4-color-gray-500, #929aa6);font-size: var(--hi-v4-text-size-lg, 1rem); }.hi-v4-menu-item__indent {display: inline-block;width: 24px;height: 100%;-ms-flex-negative: 0;flex-shrink: 0; }.hi-v4-menu__wrapper {padding: 0;margin: 0; }.hi-v4-menu--horizontal {width: 100%;overflow: hidden; }.hi-v4-menu--horizontal .hi-v4-menu__wrapper {display: -webkit-box;display: -ms-flexbox;display: flex;overflow: visible;width: -webkit-max-content;width: -moz-max-content;width: max-content;-webkit-box-sizing: border-box;box-sizing: border-box; }.hi-v4-menu--horizontal .hi-v4-menu-item {padding: 0 var(--hi-v4-spacing-10, 20px);display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;-webkit-box-align: center;-ms-flex-align: center;align-items: center;height: 56px;border: none;font-size: var(--hi-v4-text-size-lg, 1rem); }.hi-v4-menu--horizontal .hi-v4-menu-item__arrow {-webkit-margin-start: var(--hi-v4-spacing-2, 4px);margin-inline-start: var(--hi-v4-spacing-2, 4px); }.hi-v4-menu--horizontal .hi-v4-menu-item:hover {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item:hover .hi-v4-menu-item__inner {border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__inner {border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active-p {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item--active-p .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item__inner {height: 100%;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;border-bottom: 2px solid transparent; }.hi-v4-menu--horizontal .hi-v4-menu-item__inner--expanded {border-bottom: 2px solid var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--horizontal .hi-v4-menu-item__content {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;white-space: nowrap;max-width: none; }.hi-v4-menu--vertical {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;padding: var(--hi-v4-spacing-4, 8px);width: 216px;-webkit-box-sizing: border-box;box-sizing: border-box;height: 100%;-webkit-transition: width 0.3s;transition: width 0.3s; }.hi-v4-menu--vertical .hi-v4-menu__wrapper {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;overflow: auto; }.hi-v4-menu--vertical.hi-v4-menu--mini {width: 56px;overflow-x: hidden; }.hi-v4-menu--vertical.hi-v4-menu--popup .hi-v4-menu-item__inner--expanded {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu--vertical .hi-v4-menu__toggle {width: 40px;cursor: pointer;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;border-radius: var(--hi-v4-border-radius-md, 4px);color: var(--hi-v4-color-gray-500, #929aa6);height: 40px;-ms-flex-negative: 0;flex-shrink: 0;-webkit-transition-duration: var(--hi-v4-motion-duration-normal, 200ms);transition-duration: var(--hi-v4-motion-duration-normal, 200ms);-webkit-transition-timing-function: var(--hi-v4-motion-bezier-easing, cubic-bezier(0.37, 0.02, 0.34, 1));transition-timing-function: var(--hi-v4-motion-bezier-easing, cubic-bezier(0.37, 0.02, 0.34, 1));-webkit-transition-property: background-color;transition-property: background-color; }.hi-v4-menu--vertical .hi-v4-menu__toggle:hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu--vertical .hi-v4-menu-item__inner {-webkit-box-sizing: border-box;box-sizing: border-box;height: 40px;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;margin-bottom: var(--hi-v4-spacing-4, 8px);padding: 0 var(--hi-v4-spacing-4, 8px) 0 var(--hi-v4-spacing-6, 12px);border-radius: var(--hi-v4-border-radius-md, 4px);-webkit-transition: all 0.3s;transition: all 0.3s; }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner--active-p .hi-v4-menu-item__icon {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa)); }.hi-v4-menu--vertical .hi-v4-menu-item__inner:not(.hi-v4-menu-item__inner--active):hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7); }.hi-v4-menu--vertical .hi-v4-menu-item__content {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;text-indent: 0.5px; }";
13
12
 
14
13
  __styleInject__(css_248z);
15
14
 
package/lib/esm/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @hi-ui/menu
3
3
  * https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme
4
4
  *
5
- * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
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.
@@ -1,23 +1,85 @@
1
1
  import React from 'react';
2
2
  import { HiBaseHTMLProps } from '@hi-ui/core';
3
- import { MenuDataItem } from './types';
3
+ import { MenuDataItem, MenuFooterRenderProps } from './types';
4
4
  /**
5
5
  * TODO: What is Menu
6
6
  */
7
7
  export declare const Menu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<HTMLDivElement | null>>;
8
8
  export interface MenuProps extends Omit<HiBaseHTMLProps<'div'>, 'onClick'> {
9
+ /**
10
+ * 菜单项数据列表
11
+ */
9
12
  data: MenuDataItem[];
13
+ /**
14
+ * 默认激活的菜单项 id
15
+ */
16
+ defaultActiveId?: React.ReactText;
17
+ /**
18
+ * 激活的菜单项 id
19
+ */
10
20
  activeId?: React.ReactText;
21
+ /**
22
+ * 设置菜单水平或垂直展示
23
+ */
11
24
  placement?: 'horizontal' | 'vertical';
25
+ /**
26
+ * 是否收起子菜单,菜单垂直展示时有效
27
+ */
12
28
  collapsed?: boolean;
29
+ /**
30
+ * 默认是否收起子菜单,菜单垂直展示时有效
31
+ */
32
+ defaultCollapsed?: boolean;
33
+ /**
34
+ * 是否显示收缩开关,菜单垂直展示时有效
35
+ */
13
36
  showCollapse?: boolean;
37
+ /**
38
+ * 是否以胖菜单的形式展开所有子菜单(仅在水平菜单时有效)
39
+ */
14
40
  showAllSubMenus?: boolean;
41
+ /**
42
+ * 手风琴模式,菜单水平展示时有效
43
+ */
15
44
  accordion?: boolean;
16
- onClick?: (menuId: React.ReactText) => void;
17
- onClickSubMenu?: (subMenuId: React.ReactText, expandedIds: React.ReactText[]) => void;
18
- onCollapse?: (collapsed: boolean) => void;
45
+ /**
46
+ * 下拉框根类名
47
+ */
19
48
  overlayClassName?: string;
49
+ /**
50
+ * 弹出层展开方式
51
+ */
20
52
  expandedType?: 'collapse' | 'pop';
53
+ /**
54
+ * 首次渲染默认展开所有菜单项,为非受控模式
55
+ */
56
+ defaultExpandAll?: boolean;
57
+ /**
58
+ * 首次渲染默认展开菜单项 ids 列表,为非受控模式
59
+ */
21
60
  defaultExpandedIds?: React.ReactText[];
22
- defaultActiveId?: React.ReactText;
61
+ /**
62
+ * 展开菜单项 ids 列表,开启受控
63
+ */
64
+ expandedIds?: React.ReactText[];
65
+ /**
66
+ * 展开菜单时回调
67
+ */
68
+ onExpand?: (expandedIds: React.ReactText[]) => void;
69
+ /**
70
+ * 点击菜单选项时的回调
71
+ */
72
+ onClick?: (menuId: React.ReactText, menuItem: MenuDataItem) => void;
73
+ /**
74
+ * 点击父菜单项时的回调
75
+ */
76
+ onClickSubMenu?: (subMenuId: React.ReactText, expandedIds: React.ReactText[]) => void;
77
+ /**
78
+ * 点击收缩开关时的回调
79
+ */
80
+ onCollapse?: (collapsed: boolean) => void;
81
+ /**
82
+ * 底部渲染器
83
+ */
84
+ footerRender?: (props: MenuFooterRenderProps) => React.ReactNode;
23
85
  }
@@ -1,12 +1,15 @@
1
1
  import React from 'react';
2
2
  import { HiBaseHTMLProps } from '@hi-ui/core';
3
+ import { MenuDataItem } from './types';
3
4
  export declare const MenuItem: React.ForwardRefExoticComponent<MenuItemProps & React.RefAttributes<HTMLLIElement | null>>;
4
5
  export interface MenuItemProps extends Omit<HiBaseHTMLProps<'li'>, 'id'> {
5
6
  id: React.ReactText;
6
7
  title: React.ReactNode;
7
8
  icon?: React.ReactNode;
8
9
  disabled?: boolean;
9
- children?: MenuItemProps[];
10
+ children?: MenuDataItem[];
10
11
  level?: number;
11
12
  parentIds?: React.ReactText[];
13
+ render?: (node: MenuDataItem) => React.ReactNode;
14
+ raw?: MenuDataItem;
12
15
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { MenuDataItem } from './types';
2
3
  declare const MenuContext: React.Context<{
3
4
  placement?: "vertical" | "horizontal" | undefined;
4
5
  expandedType?: "collapse" | "pop" | undefined;
@@ -7,7 +8,7 @@ declare const MenuContext: React.Context<{
7
8
  expandedIds?: React.ReactText[] | undefined;
8
9
  activeId?: React.ReactText | undefined;
9
10
  activeParents?: React.ReactText[] | undefined;
10
- clickMenu?: ((id: React.ReactText) => void) | undefined;
11
+ clickMenu?: ((id: React.ReactText, raw: MenuDataItem) => void) | undefined;
11
12
  clickSubMenu?: ((id: React.ReactText) => void) | undefined;
12
13
  closePopper?: ((id: React.ReactText) => void) | undefined;
13
14
  closeAllPopper?: (() => void) | undefined;
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  export interface MenuDataItem {
3
3
  /**
4
- * 节点唯一 id
4
+ * 菜单项唯一标识
5
5
  */
6
6
  id: React.ReactText;
7
7
  /**
8
- * 节点标题
8
+ * 菜单项标题
9
9
  */
10
10
  title: React.ReactNode;
11
11
  /**
@@ -21,3 +21,13 @@ export interface MenuDataItem {
21
21
  */
22
22
  children?: MenuDataItem[];
23
23
  }
24
+ export interface MenuFooterRenderProps {
25
+ /**
26
+ * 当前菜单收起状态
27
+ */
28
+ collapsed?: boolean;
29
+ /**
30
+ * 当前菜单收缩控制器节点
31
+ */
32
+ collapseNode?: React.ReactNode;
33
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@hi-ui/menu",
3
- "version": "4.0.0-beta.9",
3
+ "version": "4.0.2",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
- "author": "HIUI <mi-hiui@xiaomi.com>",
6
+ "author": "HiUI <mi-hiui@xiaomi.com>",
7
7
  "homepage": "https://github.com/XiaoMi/hiui/tree/master/packages/ui/menu#readme",
8
8
  "license": "MIT",
9
9
  "directories": {
@@ -43,28 +43,33 @@
43
43
  "url": "https://github.com/XiaoMi/hiui/issues"
44
44
  },
45
45
  "dependencies": {
46
- "@hi-ui/array-utils": "^4.0.0-beta.5",
47
- "@hi-ui/classname": "^4.0.0-beta.0",
48
- "@hi-ui/core": "^4.0.0-beta.4",
49
- "@hi-ui/core-css": "^4.0.0-beta.3",
50
- "@hi-ui/env": "^4.0.0-beta.0",
51
- "@hi-ui/icons": "^4.0.0-beta.6",
52
- "@hi-ui/popper": "^4.0.0-beta.7",
53
- "@hi-ui/times": "^4.0.0-beta.3",
54
- "@hi-ui/tooltip": "^4.0.0-beta.10",
55
- "@hi-ui/type-assertion": "^4.0.0-beta.2",
56
- "@hi-ui/use-merge-refs": "^4.0.0-beta.2",
57
- "@hi-ui/use-uncontrolled-state": "^4.0.0-beta.2",
46
+ "@hi-ui/array-utils": "^4.0.1",
47
+ "@hi-ui/classname": "^4.0.1",
48
+ "@hi-ui/env": "^4.0.1",
49
+ "@hi-ui/icons": "^4.0.2",
50
+ "@hi-ui/popper": "^4.0.2",
51
+ "@hi-ui/times": "^4.0.1",
52
+ "@hi-ui/tooltip": "^4.0.2",
53
+ "@hi-ui/tree-utils": "^4.0.1",
54
+ "@hi-ui/type-assertion": "^4.0.1",
55
+ "@hi-ui/use-id": "^4.0.1",
56
+ "@hi-ui/use-merge-refs": "^4.0.1",
57
+ "@hi-ui/use-resize-observer": "^4.0.1",
58
+ "@hi-ui/use-toggle": "^4.0.1",
59
+ "@hi-ui/use-uncontrolled-state": "^4.0.1",
58
60
  "react-transition-group": "^4.4.2"
59
61
  },
60
62
  "peerDependencies": {
63
+ "@hi-ui/core": ">=4.0.0",
61
64
  "react": ">=16.8.6",
62
65
  "react-dom": ">=16.8.6"
63
66
  },
64
67
  "devDependencies": {
65
- "@hi-ui/hi-build": "^4.0.0-beta.2",
68
+ "@hi-ui/core": "^4.0.2",
69
+ "@hi-ui/core-css": "^4.0.1",
70
+ "@hi-ui/hi-build": "^4.0.1",
66
71
  "react": "^17.0.1",
67
72
  "react-dom": "^17.0.1"
68
73
  },
69
- "gitHead": "ee153a74347825eed55297d5b55459823f2b6f58"
74
+ "gitHead": "7d841458bef1853b31426203cb0a9dc2b9820908"
70
75
  }