@qsxy/element-plus-react 1.0.0-next.21 → 1.0.0-next.22
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/BreadcrumbItem.js +7 -4
- package/dist/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/dist/Menu/Menu.d.ts +4 -0
- package/dist/Menu/Menu.js +231 -0
- package/dist/Menu/MenuCollapseTransition.d.ts +6 -0
- package/dist/Menu/MenuCollapseTransition.js +40 -0
- package/dist/Menu/MenuContext.d.ts +16 -0
- package/dist/Menu/MenuContext.js +18 -0
- package/dist/Menu/MenuItem.d.ts +4 -0
- package/dist/Menu/MenuItem.js +76 -0
- package/dist/Menu/MenuItemGroup.d.ts +4 -0
- package/dist/Menu/MenuItemGroup.js +44 -0
- package/dist/Menu/SubMenu.d.ts +4 -0
- package/dist/Menu/SubMenu.js +242 -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/Popper/Popper.js +9 -4
- package/dist/Popper/popperOptions.d.ts +2 -2
- package/dist/Popper/popperOptions.js +41 -2
- 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/Tooltip/Tooltip.js +3 -1
- 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/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 +2 -0
- package/dist/index.js +1 -0
- package/dist/types/common.d.ts +2 -2
- package/package.json +4 -3
- package/theme-chalk/common/transition.scss +142 -0
- package/theme-chalk/index.scss +3 -0
- package/theme-chalk/menu-item-group.scss +0 -0
- package/theme-chalk/menu-item.scss +0 -0
- package/theme-chalk/menu.scss +352 -0
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
9
9
|
import classNames from 'classnames';
|
|
10
10
|
import React, { cloneElement, memo, useCallback, useContext } from 'react';
|
|
11
|
+
import { useNavigate } from 'react-router-dom';
|
|
11
12
|
import { useClassNames } from "../hooks";
|
|
12
13
|
import { isNotEmpty } from "../Util";
|
|
13
14
|
import { BreadcrumbContext } from "./Breadcrumb";
|
|
@@ -22,14 +23,16 @@ var BreadcrumbItem = /*#__PURE__*/memo(function (props) {
|
|
|
22
23
|
is = _useClassNames.is;
|
|
23
24
|
var _useContext = useContext(BreadcrumbContext),
|
|
24
25
|
separator = _useContext.separator;
|
|
26
|
+
var navigate = useNavigate();
|
|
25
27
|
|
|
26
28
|
/** 点击链接跳转 */
|
|
27
29
|
var onClickLink = useCallback(function () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
if (isNotEmpty(to)) {
|
|
31
|
+
var _to$path;
|
|
32
|
+
navigate(typeof to === 'string' ? to : (_to$path = to === null || to === void 0 ? void 0 : to.path) !== null && _to$path !== void 0 ? _to$path : '*');
|
|
33
|
+
}
|
|
31
34
|
onClick === null || onClick === void 0 || onClick(to);
|
|
32
|
-
}, [onClick, to]);
|
|
35
|
+
}, [navigate, onClick, to]);
|
|
33
36
|
return /*#__PURE__*/React.createElement("div", {
|
|
34
37
|
className: classNames(e(_templateObject || (_templateObject = _taggedTemplateLiteral(["item"]))), props.className),
|
|
35
38
|
style: props.style,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DateTimePickerRef } from './typings';
|
|
3
|
-
declare const DateTimePicker: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<import("..").DatePickerProps, "
|
|
3
|
+
declare const DateTimePicker: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<import("..").DatePickerProps, "type" | "name"> & {
|
|
4
4
|
name?: string;
|
|
5
5
|
onClear?: (event?: any) => void;
|
|
6
6
|
defaultTime?: Date;
|
|
@@ -0,0 +1,231 @@
|
|
|
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 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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
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."); }
|
|
10
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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 } 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: 300,
|
|
36
|
+
hideTimeout: 300,
|
|
37
|
+
uniqueOpened: false,
|
|
38
|
+
collapseTransition: false,
|
|
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
|
+
onClose = _props.onClose,
|
|
56
|
+
menuTrigger = _props.menuTrigger,
|
|
57
|
+
popperOffset = _props.popperOffset,
|
|
58
|
+
router = _props.router,
|
|
59
|
+
ellipsisIcon = _props.ellipsisIcon;
|
|
60
|
+
var _useClassNames = useClassNames(classPrefix),
|
|
61
|
+
b = _useClassNames.b,
|
|
62
|
+
m = _useClassNames.m;
|
|
63
|
+
var _useControlled = useControlled(undefined, [defaultActive]),
|
|
64
|
+
_useControlled2 = _slicedToArray(_useControlled, 2),
|
|
65
|
+
active = _useControlled2[0],
|
|
66
|
+
setActive = _useControlled2[1];
|
|
67
|
+
// const [subMenu, setSubMenu] = useState<SubMenuProvider[]>([]);
|
|
68
|
+
// const [, setItems] = useState<MenuItemRegistered[]>([]);
|
|
69
|
+
|
|
70
|
+
var menuRef = useRef(null);
|
|
71
|
+
var menuItemsRef = useRef([]);
|
|
72
|
+
var subMenuRef = useRef([]);
|
|
73
|
+
useCssTransiton({
|
|
74
|
+
nodeRef: menuRef,
|
|
75
|
+
visible: collapse,
|
|
76
|
+
disabled: mode === 'horizontal' || !collapseTransition,
|
|
77
|
+
duration: 300,
|
|
78
|
+
beforeLeave: beforeLeave,
|
|
79
|
+
onLeave: onLeave,
|
|
80
|
+
afterLeave: afterLeave,
|
|
81
|
+
beforeEnter: beforeEnter,
|
|
82
|
+
onEnter: onEnter,
|
|
83
|
+
afterEnter: afterEnter,
|
|
84
|
+
done: function done() {
|
|
85
|
+
if (collapse) {
|
|
86
|
+
subMenuRef.current.forEach(function (sub) {
|
|
87
|
+
sub.closeMenu(sub.index, sub.indexPath);
|
|
88
|
+
});
|
|
89
|
+
addClass(menuRef.current, m(_templateObject || (_templateObject = _taggedTemplateLiteral(["collapse"]))));
|
|
90
|
+
} else {
|
|
91
|
+
removeClass(menuRef.current, m(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["collapse"]))));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
var _useEllipsis = useEllipsis(menuRef, props),
|
|
96
|
+
sliceIndex = _useEllipsis.sliceIndex;
|
|
97
|
+
var onOpen = useCallback(function (index, indexPath, item) {
|
|
98
|
+
var _props$onOpen, _props2;
|
|
99
|
+
if (mode === 'vertical') {
|
|
100
|
+
subMenuRef.current.forEach(function (sub) {
|
|
101
|
+
if (sub.index === index) {
|
|
102
|
+
sub.openMenu(index, indexPath);
|
|
103
|
+
}
|
|
104
|
+
if (uniqueOpened) {
|
|
105
|
+
if (sub.index !== index && !indexPath.includes(sub.index)) {
|
|
106
|
+
sub.closeMenu(index, indexPath);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
(_props$onOpen = (_props2 = props).onOpen) === null || _props$onOpen === void 0 || _props$onOpen.call(_props2, index, indexPath, item);
|
|
112
|
+
}, [mode, props, uniqueOpened]);
|
|
113
|
+
var activeMenus = useCallback(function () {
|
|
114
|
+
if (defaultActive) {
|
|
115
|
+
var menu = menuItemsRef.current.find(function (item) {
|
|
116
|
+
return item.index === defaultActive;
|
|
117
|
+
});
|
|
118
|
+
if (menu && menu.indexPath.length > 1) {
|
|
119
|
+
setActive(menu.indexPath);
|
|
120
|
+
menu.indexPath.reduce(function (prev, item) {
|
|
121
|
+
onOpen(item, [].concat(_toConsumableArray(prev), [item]), {
|
|
122
|
+
index: item,
|
|
123
|
+
indexPath: [].concat(_toConsumableArray(prev), [item])
|
|
124
|
+
});
|
|
125
|
+
return [].concat(_toConsumableArray(prev), [item]);
|
|
126
|
+
}, []);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (defaultOpeneds.length > 0) {
|
|
130
|
+
defaultOpeneds.forEach(function (keys) {
|
|
131
|
+
var sub = subMenuRef.current.find(function (item) {
|
|
132
|
+
return item.index === keys;
|
|
133
|
+
});
|
|
134
|
+
if (sub) {
|
|
135
|
+
sub.openMenu(sub.index, sub.indexPath);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}, [defaultActive, defaultOpeneds, onOpen, setActive]);
|
|
140
|
+
var addItems = useCallback(function (menu) {
|
|
141
|
+
var prev = menuItemsRef.current;
|
|
142
|
+
if (!prev.some(function (item) {
|
|
143
|
+
return item.index === menu.index;
|
|
144
|
+
})) {
|
|
145
|
+
menuItemsRef.current = [].concat(_toConsumableArray(prev), [menu]);
|
|
146
|
+
activeMenus();
|
|
147
|
+
} else {
|
|
148
|
+
var idx = prev.findIndex(function (item) {
|
|
149
|
+
return item.index === menu.index;
|
|
150
|
+
});
|
|
151
|
+
menuItemsRef.current = prev.splice(idx, 1, menu);
|
|
152
|
+
}
|
|
153
|
+
}, [activeMenus]);
|
|
154
|
+
var addSubMenu = useCallback(function (sub) {
|
|
155
|
+
var prev = subMenuRef.current;
|
|
156
|
+
if (!prev.some(function (item) {
|
|
157
|
+
return item.index === sub.index;
|
|
158
|
+
})) {
|
|
159
|
+
subMenuRef.current = [].concat(_toConsumableArray(prev), [sub]);
|
|
160
|
+
activeMenus();
|
|
161
|
+
}
|
|
162
|
+
}, [activeMenus]);
|
|
163
|
+
var open = useCallback(function (index) {
|
|
164
|
+
var menu = subMenuRef.current.find(function (item) {
|
|
165
|
+
return item.index === index;
|
|
166
|
+
});
|
|
167
|
+
if (menu && menu.indexPath.length > 1) {
|
|
168
|
+
// setActive(menu.indexPath);
|
|
169
|
+
menu.indexPath.reduce(function (prev, item) {
|
|
170
|
+
onOpen(item, [].concat(_toConsumableArray(prev), [item]), {
|
|
171
|
+
index: item,
|
|
172
|
+
indexPath: [].concat(_toConsumableArray(prev), [item])
|
|
173
|
+
});
|
|
174
|
+
return [].concat(_toConsumableArray(prev), [item]);
|
|
175
|
+
}, []);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// const sub = subMenuRef.current.find(item => item.index === index);
|
|
179
|
+
// if (sub) {
|
|
180
|
+
// sub.openMenu(sub.index, sub.indexPath);
|
|
181
|
+
// }
|
|
182
|
+
}, [onOpen]);
|
|
183
|
+
var close = useCallback(function (index) {
|
|
184
|
+
var sub = subMenuRef.current.find(function (item) {
|
|
185
|
+
return item.index === index;
|
|
186
|
+
});
|
|
187
|
+
if (sub) {
|
|
188
|
+
sub.closeMenu(sub.index, sub.indexPath);
|
|
189
|
+
}
|
|
190
|
+
}, []);
|
|
191
|
+
useImperativeHandle(ref, function () {
|
|
192
|
+
return {
|
|
193
|
+
open: open,
|
|
194
|
+
close: close
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
return (
|
|
198
|
+
/*#__PURE__*/
|
|
199
|
+
// @ts-ignore
|
|
200
|
+
React.createElement("ul", {
|
|
201
|
+
ref: menuRef,
|
|
202
|
+
className: classNames(b(), m(mode), /* { [m('collapse')]: mounted }, */props.className),
|
|
203
|
+
style: _objectSpread({
|
|
204
|
+
'--el-menu-level': 0
|
|
205
|
+
}, props.style)
|
|
206
|
+
}, /*#__PURE__*/React.createElement(MenuContext.Provider, {
|
|
207
|
+
value: {
|
|
208
|
+
activeIndex: active,
|
|
209
|
+
setActiveIndex: setActive,
|
|
210
|
+
parentIndex: [],
|
|
211
|
+
mode: mode,
|
|
212
|
+
showTimeout: showTimeout,
|
|
213
|
+
hideTimeout: hideTimeout,
|
|
214
|
+
onSelect: onSelect,
|
|
215
|
+
onOpen: onOpen,
|
|
216
|
+
onClose: onClose,
|
|
217
|
+
addItems: addItems,
|
|
218
|
+
addSubMenu: addSubMenu,
|
|
219
|
+
menuTrigger: menuTrigger,
|
|
220
|
+
popperOffset: popperOffset,
|
|
221
|
+
router: router,
|
|
222
|
+
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'])
|
|
223
|
+
}
|
|
224
|
+
}, sliceIndex > 1 ? /*#__PURE__*/React.createElement(React.Fragment, null, Children.toArray(props.children).slice(0, sliceIndex), /*#__PURE__*/React.createElement(SubMenu, {
|
|
225
|
+
key: "__el__more",
|
|
226
|
+
index: "__el__more",
|
|
227
|
+
title: ellipsisIcon !== null && ellipsisIcon !== void 0 ? ellipsisIcon : /*#__PURE__*/React.createElement(More, null)
|
|
228
|
+
}, Children.toArray(props.children).slice(sliceIndex))) : props.children))
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
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,16 @@
|
|
|
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'> {
|
|
4
|
+
activeIndex?: string[];
|
|
5
|
+
setActiveIndex?: (value: string[]) => void;
|
|
6
|
+
handleSubMenuClick?: () => void;
|
|
7
|
+
parentIndex?: string[];
|
|
8
|
+
addItems?: (menu: MenuItemRegistered) => void;
|
|
9
|
+
addSubMenu?: (sub: SubMenuProvider) => void;
|
|
10
|
+
/** 菜单展示模式 */
|
|
11
|
+
mode?: 'horizontal' | 'vertical';
|
|
12
|
+
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>>;
|
|
13
|
+
}
|
|
14
|
+
export declare const MenuContext: React.Context<MenuContextProps>;
|
|
15
|
+
export declare const useMenuContext: () => MenuContextProps;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
showTimeout: 300,
|
|
13
|
+
hideTimeout: 300,
|
|
14
|
+
themeStyle: {}
|
|
15
|
+
});
|
|
16
|
+
export var useMenuContext = function useMenuContext() {
|
|
17
|
+
return useContext(MenuContext);
|
|
18
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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 classNames from 'classnames';
|
|
8
|
+
import React, { useCallback, useLayoutEffect, useMemo } from 'react';
|
|
9
|
+
import { useNavigate } from 'react-router-dom';
|
|
10
|
+
import { useClassNames } from "../hooks";
|
|
11
|
+
import { useMenuContext } from "./MenuContext";
|
|
12
|
+
var MenuItem = function MenuItem(props) {
|
|
13
|
+
var _props$classPrefix = props.classPrefix,
|
|
14
|
+
classPrefix = _props$classPrefix === void 0 ? 'menu-item' : _props$classPrefix,
|
|
15
|
+
index = props.index,
|
|
16
|
+
route = props.route,
|
|
17
|
+
disabled = props.disabled,
|
|
18
|
+
onClick = props.onClick;
|
|
19
|
+
var _useClassNames = useClassNames(classPrefix),
|
|
20
|
+
b = _useClassNames.b,
|
|
21
|
+
is = _useClassNames.is;
|
|
22
|
+
var _useMenuContext = useMenuContext(),
|
|
23
|
+
handleSubMenuClick = _useMenuContext.handleSubMenuClick,
|
|
24
|
+
activeIndex = _useMenuContext.activeIndex,
|
|
25
|
+
setActiveIndex = _useMenuContext.setActiveIndex,
|
|
26
|
+
parentIndex = _useMenuContext.parentIndex,
|
|
27
|
+
addItems = _useMenuContext.addItems,
|
|
28
|
+
onOpen = _useMenuContext.onOpen,
|
|
29
|
+
onSelect = _useMenuContext.onSelect,
|
|
30
|
+
router = _useMenuContext.router;
|
|
31
|
+
var navigate = useNavigate();
|
|
32
|
+
var indexPath = useMemo(function () {
|
|
33
|
+
return [].concat(_toConsumableArray(parentIndex), [index]);
|
|
34
|
+
}, [index, parentIndex]);
|
|
35
|
+
var handleMenuItemClick = useCallback(function (evt) {
|
|
36
|
+
evt.stopPropagation();
|
|
37
|
+
if (disabled) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
setActiveIndex(indexPath);
|
|
41
|
+
handleSubMenuClick === null || handleSubMenuClick === void 0 || handleSubMenuClick();
|
|
42
|
+
onClick === null || onClick === void 0 || onClick({
|
|
43
|
+
index: index,
|
|
44
|
+
indexPath: indexPath,
|
|
45
|
+
active: activeIndex.includes(index)
|
|
46
|
+
});
|
|
47
|
+
onOpen === null || onOpen === void 0 || onOpen(index, indexPath, {
|
|
48
|
+
index: index,
|
|
49
|
+
indexPath: indexPath
|
|
50
|
+
});
|
|
51
|
+
onSelect === null || onSelect === void 0 || onSelect(index, indexPath, {
|
|
52
|
+
index: index,
|
|
53
|
+
indexPath: indexPath
|
|
54
|
+
});
|
|
55
|
+
if (router) {
|
|
56
|
+
navigate === null || navigate === void 0 || navigate(route !== null && route !== void 0 ? route : index);
|
|
57
|
+
}
|
|
58
|
+
}, [activeIndex, disabled, handleSubMenuClick, index, indexPath, navigate, onClick, onOpen, onSelect, route, router, setActiveIndex]);
|
|
59
|
+
useLayoutEffect(function () {
|
|
60
|
+
addItems({
|
|
61
|
+
index: index,
|
|
62
|
+
indexPath: indexPath
|
|
63
|
+
});
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
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
|
+
export default MenuItem;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
export default MenuItemGroup;
|