@qsxy/element-plus-react 1.0.0-next.21 → 1.0.0-next.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Breadcrumb/Breadcrumb.js +9 -0
- package/dist/Breadcrumb/BreadcrumbItem.js +7 -4
- package/dist/Button/Button.js +3 -3
- package/dist/ColorPicker/ColorPicker.js +12 -2
- package/dist/ConfigProvider/ConfigProvider.d.ts +6 -22
- package/dist/ConfigProvider/ConfigProvider.js +22 -13
- package/dist/ConfigProvider/ConfigProviderContext.d.ts +5 -0
- package/dist/ConfigProvider/ConfigProviderContext.js +13 -0
- package/dist/ConfigProvider/index.d.ts +2 -2
- package/dist/ConfigProvider/index.js +1 -1
- package/dist/ConfigProvider/typings.d.ts +22 -0
- package/dist/ConfigProvider/typings.js +1 -0
- package/dist/Container/Aside.d.ts +5 -0
- package/dist/Container/Aside.js +26 -0
- package/dist/Container/Container.d.ts +5 -0
- package/dist/Container/Container.js +37 -0
- package/dist/Container/Footer.d.ts +5 -0
- package/dist/Container/Footer.js +26 -0
- package/dist/Container/Header.d.ts +5 -0
- package/dist/Container/Header.js +26 -0
- package/dist/Container/Main.d.ts +3 -0
- package/dist/Container/Main.js +14 -0
- package/dist/Container/index.d.ts +6 -0
- package/dist/Container/index.js +5 -0
- package/dist/Container/typings.d.ts +30 -0
- package/dist/Container/typings.js +1 -0
- package/dist/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/dist/InputNumber/InputNumber.js +4 -4
- package/dist/Menu/Menu.d.ts +4 -0
- package/dist/Menu/Menu.js +281 -0
- package/dist/Menu/MenuCollapseTransition.d.ts +6 -0
- package/dist/Menu/MenuCollapseTransition.js +40 -0
- package/dist/Menu/MenuContext.d.ts +18 -0
- package/dist/Menu/MenuContext.js +20 -0
- package/dist/Menu/MenuItem.d.ts +7 -0
- package/dist/Menu/MenuItem.js +77 -0
- package/dist/Menu/MenuItemGroup.d.ts +7 -0
- package/dist/Menu/MenuItemGroup.js +45 -0
- package/dist/Menu/SubMenu.d.ts +7 -0
- package/dist/Menu/SubMenu.js +287 -0
- package/dist/Menu/SubMenuCollapseTransition.d.ts +6 -0
- package/dist/Menu/SubMenuCollapseTransition.js +52 -0
- package/dist/Menu/index.d.ts +5 -0
- package/dist/Menu/index.js +4 -0
- package/dist/Menu/typings.d.ts +121 -0
- package/dist/Menu/typings.js +1 -0
- package/dist/Menu/useEllipsis.d.ts +6 -0
- package/dist/Menu/useEllipsis.js +82 -0
- package/dist/Message/Message.js +1 -1
- package/dist/Pagination/Options.js +1 -1
- package/dist/Pagination/Pagination.js +1 -1
- package/dist/Popper/Popper.js +10 -5
- package/dist/Popper/popperOptions.d.ts +7 -6
- package/dist/Popper/popperOptions.js +56 -8
- package/dist/Popper/typings.d.ts +1 -0
- package/dist/Radio/Radio.js +4 -3
- package/dist/Radio/RadioButton.d.ts +1 -1
- package/dist/Radio/RadioButton.js +3 -2
- package/dist/Radio/typings.d.ts +1 -1
- package/dist/Table/Table.js +9 -1
- package/dist/Tooltip/Tooltip.js +4 -3
- package/dist/Transition/CssTransiton.d.ts +15 -0
- package/dist/Transition/CssTransiton.js +29 -0
- package/dist/Transition/Transition.d.ts +2 -0
- package/dist/Transition/Transition.js +7 -2
- package/dist/hooks/popperPropsUtils.js +1 -1
- package/dist/hooks/useCssTransiton.d.ts +27 -0
- package/dist/hooks/useCssTransiton.js +87 -0
- package/dist/hooks/useResizeObserver.d.ts +42 -0
- package/dist/hooks/useResizeObserver.js +42 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/types/common.d.ts +2 -2
- package/package.json +4 -3
- package/theme-chalk/aside.scss +8 -0
- package/theme-chalk/common/transition.scss +142 -0
- package/theme-chalk/container.scss +14 -0
- package/theme-chalk/footer.scss +12 -0
- package/theme-chalk/header.scss +12 -0
- package/theme-chalk/index.scss +8 -0
- package/theme-chalk/main.scss +14 -0
- package/theme-chalk/menu-item-group.scss +0 -0
- package/theme-chalk/menu-item.scss +0 -0
- package/theme-chalk/menu.scss +353 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _templateObject, _templateObject2;
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
13
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
+
import classNames from 'classnames';
|
|
20
|
+
import { addClass, removeClass } from 'dom-lib';
|
|
21
|
+
import { pick } from 'lodash';
|
|
22
|
+
import React, { Children, forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';
|
|
23
|
+
import { More } from "../Icon/IconList/More";
|
|
24
|
+
import { mergeDefaultProps } from "../Util";
|
|
25
|
+
import { useClassNames, useControlled } from "../hooks";
|
|
26
|
+
import useCssTransiton from "../hooks/useCssTransiton";
|
|
27
|
+
import { afterEnter, afterLeave, beforeEnter, beforeLeave, onEnter, onLeave } from "./MenuCollapseTransition";
|
|
28
|
+
import { MenuContext } from "./MenuContext";
|
|
29
|
+
import SubMenu from "./SubMenu";
|
|
30
|
+
import useEllipsis from "./useEllipsis";
|
|
31
|
+
var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
32
|
+
var _props$style;
|
|
33
|
+
props = mergeDefaultProps({
|
|
34
|
+
mode: 'vertical',
|
|
35
|
+
showTimeout: 150,
|
|
36
|
+
hideTimeout: 300,
|
|
37
|
+
uniqueOpened: false,
|
|
38
|
+
collapseTransition: true,
|
|
39
|
+
defaultOpeneds: [],
|
|
40
|
+
ellipsis: false,
|
|
41
|
+
router: false
|
|
42
|
+
}, props);
|
|
43
|
+
var _props = props,
|
|
44
|
+
_props$classPrefix = _props.classPrefix,
|
|
45
|
+
classPrefix = _props$classPrefix === void 0 ? 'menu' : _props$classPrefix,
|
|
46
|
+
mode = _props.mode,
|
|
47
|
+
collapse = _props.collapse,
|
|
48
|
+
defaultActive = _props.defaultActive,
|
|
49
|
+
showTimeout = _props.showTimeout,
|
|
50
|
+
hideTimeout = _props.hideTimeout,
|
|
51
|
+
uniqueOpened = _props.uniqueOpened,
|
|
52
|
+
defaultOpeneds = _props.defaultOpeneds,
|
|
53
|
+
collapseTransition = _props.collapseTransition,
|
|
54
|
+
onSelect = _props.onSelect,
|
|
55
|
+
onOpen = _props.onOpen,
|
|
56
|
+
onClose = _props.onClose,
|
|
57
|
+
menuTrigger = _props.menuTrigger,
|
|
58
|
+
popperOffset = _props.popperOffset,
|
|
59
|
+
router = _props.router,
|
|
60
|
+
ellipsisIcon = _props.ellipsisIcon;
|
|
61
|
+
var _useClassNames = useClassNames(classPrefix),
|
|
62
|
+
b = _useClassNames.b,
|
|
63
|
+
m = _useClassNames.m;
|
|
64
|
+
var _useControlled = useControlled(undefined, [defaultActive]),
|
|
65
|
+
_useControlled2 = _slicedToArray(_useControlled, 2),
|
|
66
|
+
active = _useControlled2[0],
|
|
67
|
+
setActive = _useControlled2[1];
|
|
68
|
+
var _useState = useState(collapse),
|
|
69
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
70
|
+
_collapse = _useState2[0],
|
|
71
|
+
setCollapse = _useState2[1];
|
|
72
|
+
// const [, setItems] = useState<MenuItemRegistered[]>([]);
|
|
73
|
+
|
|
74
|
+
var menuRef = useRef(null);
|
|
75
|
+
var menuItemsRef = useRef([]);
|
|
76
|
+
var subMenuRef = useRef([]);
|
|
77
|
+
var openedMenus = useRef({});
|
|
78
|
+
useCssTransiton({
|
|
79
|
+
nodeRef: menuRef,
|
|
80
|
+
visible: collapse,
|
|
81
|
+
disabled: mode === 'horizontal' || !collapseTransition,
|
|
82
|
+
duration: 300,
|
|
83
|
+
beforeLeave: beforeLeave,
|
|
84
|
+
onLeave: onLeave,
|
|
85
|
+
afterLeave: afterLeave,
|
|
86
|
+
beforeEnter: beforeEnter,
|
|
87
|
+
onEnter: onEnter,
|
|
88
|
+
afterEnter: afterEnter,
|
|
89
|
+
done: function done() {
|
|
90
|
+
setCollapse(collapse);
|
|
91
|
+
if (collapse) {
|
|
92
|
+
addClass(menuRef.current, m(_templateObject || (_templateObject = _taggedTemplateLiteral(["collapse"]))));
|
|
93
|
+
} else {
|
|
94
|
+
removeClass(menuRef.current, m(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["collapse"]))));
|
|
95
|
+
subMenuRef.current.forEach(function (sub) {
|
|
96
|
+
sub.closeMenu(sub.index, sub.indexPath);
|
|
97
|
+
});
|
|
98
|
+
for (var key in openedMenus.current) {
|
|
99
|
+
if (Object.prototype.hasOwnProperty.call(openedMenus.current, key)) {
|
|
100
|
+
var item = openedMenus.current[key];
|
|
101
|
+
item.openMenu(item.index, item.indexPath);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
var _useEllipsis = useEllipsis(menuRef, props),
|
|
108
|
+
sliceIndex = _useEllipsis.sliceIndex;
|
|
109
|
+
var addItem = useCallback(function (menu) {
|
|
110
|
+
openedMenus.current = _objectSpread(_objectSpread({}, openedMenus.current), {}, _defineProperty({}, menu.index, menu));
|
|
111
|
+
}, []);
|
|
112
|
+
var removeItem = useCallback(function (menu) {
|
|
113
|
+
delete openedMenus.current[menu.index];
|
|
114
|
+
}, []);
|
|
115
|
+
var handleOpenMenu = useCallback(function (index, indexPath, item) {
|
|
116
|
+
if (mode === 'vertical') {
|
|
117
|
+
// 折叠模式下,index为子菜单,只能向上逐层打开父菜单
|
|
118
|
+
if (collapse) {
|
|
119
|
+
if (uniqueOpened) {
|
|
120
|
+
subMenuRef.current.forEach(function (sub) {
|
|
121
|
+
sub.closeMenu(index, indexPath);
|
|
122
|
+
removeItem(sub);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
indexPath.reduce(function (prev, e) {
|
|
126
|
+
subMenuRef.current.forEach(function (sub) {
|
|
127
|
+
if (sub.index === e) {
|
|
128
|
+
sub.openMenu(e, [].concat(_toConsumableArray(prev), [e]));
|
|
129
|
+
addItem(sub);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return [].concat(_toConsumableArray(prev), [e]);
|
|
133
|
+
}, []);
|
|
134
|
+
} else {
|
|
135
|
+
// 正常模式,index为父菜单的index
|
|
136
|
+
subMenuRef.current.forEach(function (sub) {
|
|
137
|
+
if (sub.index === index) {
|
|
138
|
+
sub.openMenu(index, indexPath);
|
|
139
|
+
addItem(sub);
|
|
140
|
+
}
|
|
141
|
+
if (uniqueOpened) {
|
|
142
|
+
if (sub.index !== index && !indexPath.includes(sub.index)) {
|
|
143
|
+
sub.closeMenu(index, indexPath);
|
|
144
|
+
removeItem(sub);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
onOpen === null || onOpen === void 0 || onOpen(index, indexPath, item);
|
|
151
|
+
}, [addItem, collapse, mode, onOpen, removeItem, uniqueOpened]);
|
|
152
|
+
|
|
153
|
+
/** 激活菜单项 */
|
|
154
|
+
var activeMenus = useCallback(function () {
|
|
155
|
+
if (defaultActive) {
|
|
156
|
+
var menu = menuItemsRef.current.find(function (item) {
|
|
157
|
+
return item.index === defaultActive;
|
|
158
|
+
});
|
|
159
|
+
if (menu && menu.indexPath.length > 1) {
|
|
160
|
+
setActive(menu.indexPath);
|
|
161
|
+
menu.indexPath.reduce(function (prev, item) {
|
|
162
|
+
handleOpenMenu(item, [].concat(_toConsumableArray(prev), [item]), {
|
|
163
|
+
index: item,
|
|
164
|
+
indexPath: [].concat(_toConsumableArray(prev), [item])
|
|
165
|
+
});
|
|
166
|
+
return [].concat(_toConsumableArray(prev), [item]);
|
|
167
|
+
}, []);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (defaultOpeneds.length > 0) {
|
|
171
|
+
defaultOpeneds.forEach(function (keys) {
|
|
172
|
+
var sub = subMenuRef.current.find(function (item) {
|
|
173
|
+
return item.index === keys;
|
|
174
|
+
});
|
|
175
|
+
if (sub) {
|
|
176
|
+
sub.openMenu(sub.index, sub.indexPath);
|
|
177
|
+
addItem(sub);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}, [addItem, defaultActive, defaultOpeneds, handleOpenMenu, setActive]);
|
|
182
|
+
|
|
183
|
+
/** 添加子菜单 */
|
|
184
|
+
var addMenuItem = useCallback(function (menu) {
|
|
185
|
+
var prev = menuItemsRef.current;
|
|
186
|
+
if (!prev.some(function (item) {
|
|
187
|
+
return item.index === menu.index;
|
|
188
|
+
})) {
|
|
189
|
+
menuItemsRef.current = [].concat(_toConsumableArray(prev), [menu]);
|
|
190
|
+
activeMenus();
|
|
191
|
+
} else {
|
|
192
|
+
var idx = prev.findIndex(function (item) {
|
|
193
|
+
return item.index === menu.index;
|
|
194
|
+
});
|
|
195
|
+
menuItemsRef.current = prev.splice(idx, 1, menu);
|
|
196
|
+
}
|
|
197
|
+
}, [activeMenus]);
|
|
198
|
+
|
|
199
|
+
/** 添加父菜单 */
|
|
200
|
+
var addSubMenu = useCallback(function (sub) {
|
|
201
|
+
var prev = subMenuRef.current;
|
|
202
|
+
if (!prev.some(function (item) {
|
|
203
|
+
return item.index === sub.index;
|
|
204
|
+
})) {
|
|
205
|
+
subMenuRef.current = [].concat(_toConsumableArray(prev), [sub]);
|
|
206
|
+
activeMenus();
|
|
207
|
+
}
|
|
208
|
+
}, [activeMenus]);
|
|
209
|
+
|
|
210
|
+
/** 展开菜单 */
|
|
211
|
+
var open = useCallback(function (index) {
|
|
212
|
+
var menu = subMenuRef.current.find(function (item) {
|
|
213
|
+
return item.index === index;
|
|
214
|
+
});
|
|
215
|
+
if (menu && menu.indexPath.length > 1) {
|
|
216
|
+
// setActive(menu.indexPath);
|
|
217
|
+
menu.indexPath.reduce(function (prev, item) {
|
|
218
|
+
handleOpenMenu(item, [].concat(_toConsumableArray(prev), [item]), {
|
|
219
|
+
index: item,
|
|
220
|
+
indexPath: [].concat(_toConsumableArray(prev), [item])
|
|
221
|
+
});
|
|
222
|
+
return [].concat(_toConsumableArray(prev), [item]);
|
|
223
|
+
}, []);
|
|
224
|
+
}
|
|
225
|
+
}, [handleOpenMenu]);
|
|
226
|
+
|
|
227
|
+
/** 折叠菜单 */
|
|
228
|
+
var close = useCallback(function (index) {
|
|
229
|
+
var sub = subMenuRef.current.find(function (item) {
|
|
230
|
+
return item.index === index;
|
|
231
|
+
});
|
|
232
|
+
if (sub) {
|
|
233
|
+
sub.closeMenu(sub.index, sub.indexPath);
|
|
234
|
+
removeItem(sub);
|
|
235
|
+
}
|
|
236
|
+
}, [removeItem]);
|
|
237
|
+
useImperativeHandle(ref, function () {
|
|
238
|
+
return {
|
|
239
|
+
open: open,
|
|
240
|
+
close: close
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
return (
|
|
244
|
+
/*#__PURE__*/
|
|
245
|
+
// @ts-ignore
|
|
246
|
+
React.createElement("ul", {
|
|
247
|
+
ref: menuRef,
|
|
248
|
+
className: classNames(b(), m(mode), /* { [m('collapse')]: mounted }, */props.className),
|
|
249
|
+
style: _objectSpread({
|
|
250
|
+
'--el-menu-level': 0
|
|
251
|
+
}, props.style)
|
|
252
|
+
}, /*#__PURE__*/React.createElement(MenuContext.Provider, {
|
|
253
|
+
value: {
|
|
254
|
+
activeIndex: active,
|
|
255
|
+
setActiveIndex: setActive,
|
|
256
|
+
parentIndex: [],
|
|
257
|
+
mode: mode,
|
|
258
|
+
showTimeout: showTimeout,
|
|
259
|
+
hideTimeout: hideTimeout,
|
|
260
|
+
onSelect: onSelect,
|
|
261
|
+
onOpen: handleOpenMenu,
|
|
262
|
+
onClose: onClose,
|
|
263
|
+
addMenuItem: addMenuItem,
|
|
264
|
+
addSubMenu: addSubMenu,
|
|
265
|
+
addItem: addItem,
|
|
266
|
+
removeItem: removeItem,
|
|
267
|
+
menuTrigger: menuTrigger,
|
|
268
|
+
popperOffset: popperOffset,
|
|
269
|
+
router: router,
|
|
270
|
+
collapse: _collapse,
|
|
271
|
+
themeStyle: pick((_props$style = props.style) !== null && _props$style !== void 0 ? _props$style : {}, ['--el-menu-active-color', '--el-menu-text-color', '--el-menu-hover-text-color', '--el-menu-bg-color', '--el-menu-hover-bg-color', '--el-menu-item-height', '--el-menu-sub-item-height', '--el-menu-horizontal-height', '--el-menu-horizontal-sub-item-height', '--el-menu-item-font-size', '--el-menu-item-hover-fill', '--el-menu-border-color', '--el-menu-base-level-padding', '--el-menu-level-padding', '--el-menu-icon-width'])
|
|
272
|
+
}
|
|
273
|
+
}, sliceIndex > 1 ? /*#__PURE__*/React.createElement(React.Fragment, null, Children.toArray(props.children).slice(0, sliceIndex), /*#__PURE__*/React.createElement(SubMenu, {
|
|
274
|
+
key: "__el__more",
|
|
275
|
+
index: "__el__more",
|
|
276
|
+
title: ellipsisIcon !== null && ellipsisIcon !== void 0 ? ellipsisIcon : /*#__PURE__*/React.createElement(More, null)
|
|
277
|
+
}, Children.toArray(props.children).slice(sliceIndex))) : props.children))
|
|
278
|
+
);
|
|
279
|
+
});
|
|
280
|
+
Menu.displayName = 'ElMenu';
|
|
281
|
+
export default Menu;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const beforeEnter: (el: any) => void;
|
|
2
|
+
export declare const onEnter: (el: HTMLElement, done: any) => void;
|
|
3
|
+
export declare const afterEnter: (el: HTMLElement) => void;
|
|
4
|
+
export declare const beforeLeave: (el: any) => void;
|
|
5
|
+
export declare const onLeave: (el: any) => void;
|
|
6
|
+
export declare const afterLeave: (el: any) => void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { addClass, hasClass, removeClass } from 'dom-lib';
|
|
2
|
+
import { namespace } from "../hooks/prefix";
|
|
3
|
+
export var beforeEnter = function beforeEnter(el) {
|
|
4
|
+
el.style.opacity = '0.2';
|
|
5
|
+
};
|
|
6
|
+
export var onEnter = function onEnter(el, done) {
|
|
7
|
+
addClass(el, "".concat(namespace, "-opacity-transition"));
|
|
8
|
+
el.style.opacity = '1';
|
|
9
|
+
done === null || done === void 0 || done();
|
|
10
|
+
};
|
|
11
|
+
export var afterEnter = function afterEnter(el) {
|
|
12
|
+
removeClass(el, "".concat(namespace, "-opacity-transition"));
|
|
13
|
+
el.style.opacity = '';
|
|
14
|
+
el.style.width = '';
|
|
15
|
+
};
|
|
16
|
+
export var beforeLeave = function beforeLeave(el) {
|
|
17
|
+
if (!el.dataset) {
|
|
18
|
+
el.dataset = {};
|
|
19
|
+
}
|
|
20
|
+
if (hasClass(el, "".concat(namespace, "-menu--collapse"))) {
|
|
21
|
+
removeClass(el, "".concat(namespace, "-menu--collapse"));
|
|
22
|
+
el.dataset.oldOverflow = el.style.overflow;
|
|
23
|
+
el.dataset.scrollWidth = el.clientWidth.toString();
|
|
24
|
+
addClass(el, "".concat(namespace, "-menu--collapse"));
|
|
25
|
+
} else {
|
|
26
|
+
addClass(el, "".concat(namespace, "-menu--collapse"));
|
|
27
|
+
el.dataset.oldOverflow = el.style.overflow;
|
|
28
|
+
el.dataset.scrollWidth = el.clientWidth.toString();
|
|
29
|
+
removeClass(el, "".concat(namespace, "-menu--collapse"));
|
|
30
|
+
}
|
|
31
|
+
el.style.width = "".concat(el.scrollWidth, "px");
|
|
32
|
+
el.style.overflow = 'hidden';
|
|
33
|
+
};
|
|
34
|
+
export var onLeave = function onLeave(el) {
|
|
35
|
+
addClass(el, 'horizontal-collapse-transition');
|
|
36
|
+
el.style.width = "".concat(el.dataset.scrollWidth, "px");
|
|
37
|
+
};
|
|
38
|
+
export var afterLeave = function afterLeave(el) {
|
|
39
|
+
removeClass(el, 'horizontal-collapse-transition');
|
|
40
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuItemRegistered, MenuProps, SubMenuProvider } from './typings';
|
|
3
|
+
interface MenuContextProps extends Pick<MenuProps, 'menuTrigger' | 'onSelect' | 'onOpen' | 'onClose' | 'showTimeout' | 'hideTimeout' | 'popperOffset' | 'router' | 'collapse'> {
|
|
4
|
+
activeIndex?: string[];
|
|
5
|
+
setActiveIndex?: (value: string[]) => void;
|
|
6
|
+
handleSubMenuClick?: () => void;
|
|
7
|
+
parentIndex?: string[];
|
|
8
|
+
addMenuItem?: (menu: MenuItemRegistered) => void;
|
|
9
|
+
addSubMenu?: (sub: SubMenuProvider) => void;
|
|
10
|
+
/** 菜单展示模式 */
|
|
11
|
+
mode?: 'horizontal' | 'vertical';
|
|
12
|
+
addItem?: (menu: SubMenuProvider) => void;
|
|
13
|
+
removeItem?: (menu: SubMenuProvider) => void;
|
|
14
|
+
themeStyle?: React.CSSProperties & Partial<Record<'--el-menu-active-color' | '--el-menu-text-color' | '--el-menu-hover-text-color' | '--el-menu-bg-color' | '--el-menu-hover-bg-color' | '--el-menu-item-height' | '--el-menu-sub-item-height' | '--el-menu-horizontal-height' | '--el-menu-horizontal-sub-item-height' | '--el-menu-item-font-size' | '--el-menu-item-hover-fill' | '--el-menu-border-color' | '--el-menu-base-level-padding' | '--el-menu-level-padding' | '--el-menu-icon-width', string>>;
|
|
15
|
+
}
|
|
16
|
+
export declare const MenuContext: React.Context<MenuContextProps>;
|
|
17
|
+
export declare const useMenuContext: () => MenuContextProps;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export var MenuContext = /*#__PURE__*/createContext({
|
|
3
|
+
activeIndex: [],
|
|
4
|
+
parentIndex: [],
|
|
5
|
+
mode: null,
|
|
6
|
+
handleSubMenuClick: null,
|
|
7
|
+
setActiveIndex: null,
|
|
8
|
+
onSelect: null,
|
|
9
|
+
onOpen: null,
|
|
10
|
+
onClose: null,
|
|
11
|
+
addSubMenu: null,
|
|
12
|
+
addItem: null,
|
|
13
|
+
removeItem: null,
|
|
14
|
+
showTimeout: 300,
|
|
15
|
+
hideTimeout: 300,
|
|
16
|
+
themeStyle: {}
|
|
17
|
+
});
|
|
18
|
+
export var useMenuContext = function useMenuContext() {
|
|
19
|
+
return useContext(MenuContext);
|
|
20
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
import { useMount } from 'ahooks';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import React, { useCallback, useMemo } from 'react';
|
|
10
|
+
import { useNavigate } from 'react-router-dom';
|
|
11
|
+
import { useClassNames } from "../hooks";
|
|
12
|
+
import { useMenuContext } from "./MenuContext";
|
|
13
|
+
var MenuItem = function MenuItem(props) {
|
|
14
|
+
var _props$classPrefix = props.classPrefix,
|
|
15
|
+
classPrefix = _props$classPrefix === void 0 ? 'menu-item' : _props$classPrefix,
|
|
16
|
+
index = props.index,
|
|
17
|
+
route = props.route,
|
|
18
|
+
disabled = props.disabled,
|
|
19
|
+
onClick = props.onClick;
|
|
20
|
+
var _useClassNames = useClassNames(classPrefix),
|
|
21
|
+
b = _useClassNames.b,
|
|
22
|
+
is = _useClassNames.is;
|
|
23
|
+
var _useMenuContext = useMenuContext(),
|
|
24
|
+
handleSubMenuClick = _useMenuContext.handleSubMenuClick,
|
|
25
|
+
activeIndex = _useMenuContext.activeIndex,
|
|
26
|
+
setActiveIndex = _useMenuContext.setActiveIndex,
|
|
27
|
+
parentIndex = _useMenuContext.parentIndex,
|
|
28
|
+
addMenuItem = _useMenuContext.addMenuItem,
|
|
29
|
+
onOpen = _useMenuContext.onOpen,
|
|
30
|
+
onSelect = _useMenuContext.onSelect,
|
|
31
|
+
router = _useMenuContext.router;
|
|
32
|
+
var navigate = useNavigate();
|
|
33
|
+
var indexPath = useMemo(function () {
|
|
34
|
+
return [].concat(_toConsumableArray(parentIndex), [index]);
|
|
35
|
+
}, [index, parentIndex]);
|
|
36
|
+
var handleMenuItemClick = useCallback(function (evt) {
|
|
37
|
+
evt.stopPropagation();
|
|
38
|
+
if (disabled) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setActiveIndex(indexPath);
|
|
42
|
+
handleSubMenuClick === null || handleSubMenuClick === void 0 || handleSubMenuClick();
|
|
43
|
+
onClick === null || onClick === void 0 || onClick({
|
|
44
|
+
index: index,
|
|
45
|
+
indexPath: indexPath,
|
|
46
|
+
active: activeIndex.includes(index)
|
|
47
|
+
});
|
|
48
|
+
onOpen === null || onOpen === void 0 || onOpen(index, indexPath, {
|
|
49
|
+
index: index,
|
|
50
|
+
indexPath: indexPath
|
|
51
|
+
});
|
|
52
|
+
onSelect === null || onSelect === void 0 || onSelect(index, indexPath, {
|
|
53
|
+
index: index,
|
|
54
|
+
indexPath: indexPath
|
|
55
|
+
});
|
|
56
|
+
if (router) {
|
|
57
|
+
navigate === null || navigate === void 0 || navigate(route !== null && route !== void 0 ? route : index);
|
|
58
|
+
}
|
|
59
|
+
}, [activeIndex, disabled, handleSubMenuClick, index, indexPath, navigate, onClick, onOpen, onSelect, route, router, setActiveIndex]);
|
|
60
|
+
useMount(function () {
|
|
61
|
+
addMenuItem({
|
|
62
|
+
index: index,
|
|
63
|
+
indexPath: indexPath
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
67
|
+
className: classNames(b(), is({
|
|
68
|
+
disabled: disabled,
|
|
69
|
+
active: activeIndex.includes(index)
|
|
70
|
+
}), props.className),
|
|
71
|
+
style: props.style,
|
|
72
|
+
role: "menuitem",
|
|
73
|
+
onClick: handleMenuItemClick
|
|
74
|
+
}, props.children);
|
|
75
|
+
};
|
|
76
|
+
MenuItem.displayName = 'ElMenuItem';
|
|
77
|
+
export default MenuItem;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useClassNames } from "../hooks";
|
|
6
|
+
var MenuItemGroup = function MenuItemGroup(props) {
|
|
7
|
+
var _props$classPrefix = props.classPrefix,
|
|
8
|
+
classPrefix = _props$classPrefix === void 0 ? 'menu-item-group' : _props$classPrefix,
|
|
9
|
+
title = props.title;
|
|
10
|
+
var _useClassNames = useClassNames(classPrefix),
|
|
11
|
+
b = _useClassNames.b,
|
|
12
|
+
e = _useClassNames.e;
|
|
13
|
+
|
|
14
|
+
// const { handleSubMenuClick, activeIndex, setActiveIndex, parentIndex, onSelect } = useMenuContext();
|
|
15
|
+
|
|
16
|
+
// const indexPath = useMemo(() => [...parentIndex, index], [index, parentIndex]);
|
|
17
|
+
|
|
18
|
+
// const handleMenuItemClick = useCallback(() => {
|
|
19
|
+
// if (disabled) {
|
|
20
|
+
// return;
|
|
21
|
+
// }
|
|
22
|
+
// setActiveIndex(indexPath);
|
|
23
|
+
// handleSubMenuClick?.();
|
|
24
|
+
// onClick?.({
|
|
25
|
+
// index,
|
|
26
|
+
// indexPath,
|
|
27
|
+
// active: activeIndex.includes(index),
|
|
28
|
+
// });
|
|
29
|
+
// onSelect?.(index, indexPath, { index, indexPath });
|
|
30
|
+
// }, [activeIndex, disabled, handleSubMenuClick, index, indexPath, onClick, onSelect, setActiveIndex]);
|
|
31
|
+
|
|
32
|
+
// useLayoutEffect(() => {
|
|
33
|
+
// // console.log(indexPath);
|
|
34
|
+
// }, []);
|
|
35
|
+
|
|
36
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
37
|
+
className: classNames(b(), props.className),
|
|
38
|
+
style: props.style,
|
|
39
|
+
role: "menuitem"
|
|
40
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
41
|
+
className: e(_templateObject || (_templateObject = _taggedTemplateLiteral(["title"])))
|
|
42
|
+
}, title), /*#__PURE__*/React.createElement("ul", null, props.children));
|
|
43
|
+
};
|
|
44
|
+
MenuItemGroup.displayName = 'ElMenuItemGroup';
|
|
45
|
+
export default MenuItemGroup;
|