@arcblock/ux 2.1.26 → 2.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Header/header.js +1 -1
- package/lib/NavMenu/nav-menu.js +30 -22
- package/lib/SplitButton/index.js +1 -1
- package/package.json +4 -4
- package/src/Header/header.js +1 -4
- package/src/NavMenu/nav-menu.js +30 -16
- package/src/SplitButton/index.js +1 -1
package/lib/Header/header.js
CHANGED
|
@@ -107,7 +107,7 @@ Header.defaultProps = {
|
|
|
107
107
|
const Root = _styledComponents.default.div.withConfig({
|
|
108
108
|
displayName: "header__Root",
|
|
109
109
|
componentId: "sc-15qnwg1-0"
|
|
110
|
-
})(["position:relative;z-index:", ";font-size:14px;background:", ";.header-container{display:flex;align-items:center;height:64px;}.header-logo{display:inline-flex;position:relative;height:
|
|
110
|
+
})(["position:relative;z-index:", ";font-size:14px;background:", ";.header-container{display:flex;align-items:center;height:64px;}.header-logo{display:inline-flex;position:relative;height:44px;margin-right:16px;img,svg{width:auto;height:100%;}> a{height:100%;line-height:1;}> a::before{position:absolute;top:0;right:0;bottom:0;left:0;background-color:transparent;content:'';}}.header-brand{display:flex;flex-direction:column;flex-shrink:0;margin-right:16px;a{color:inherit;text-decoration:none;}.header-brand-title{display:flex;align-items:center;h2{margin:0;font-size:16px;}.header-brand-addon{margin-left:8px;}}.header-brand-desc{color:#9397a1;}}.header-addons{display:flex;align-items:center;}", "{.header-brand{margin-right:12px;.header-brand-title{h2{font-size:14px;}}}}", "{.header-container{height:56px;}.header-menu{display:inline-block;}.header-logo{height:32px;}.header-brand{display:none;}}"], props => props.$theme.zIndex.appBar, props => props.$theme.palette.common.white, props => props.$theme.breakpoints.down('lg'), props => props.$theme.breakpoints.down('md'));
|
|
111
111
|
|
|
112
112
|
var _default = Header;
|
|
113
113
|
exports.default = _default;
|
package/lib/NavMenu/nav-menu.js
CHANGED
|
@@ -17,7 +17,7 @@ var _style = require("./style");
|
|
|
17
17
|
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
19
|
|
|
20
|
-
const _excluded = ["items", "mode", "children", "
|
|
20
|
+
const _excluded = ["items", "mode", "children", "activeId", "textColor", "activeTextColor", "bgColor", "onSelected"],
|
|
21
21
|
_excluded2 = ["id", "icon", "label", "active", "onClick"],
|
|
22
22
|
_excluded3 = ["id", "icon", "label", "children", "expandIcon"];
|
|
23
23
|
|
|
@@ -60,7 +60,7 @@ function NavMenu(_ref) {
|
|
|
60
60
|
items,
|
|
61
61
|
mode,
|
|
62
62
|
children,
|
|
63
|
-
|
|
63
|
+
activeId,
|
|
64
64
|
textColor,
|
|
65
65
|
activeTextColor,
|
|
66
66
|
bgColor,
|
|
@@ -76,30 +76,38 @@ function NavMenu(_ref) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
const [state, setState] = (0, _react.useState)({
|
|
79
|
-
activeId
|
|
79
|
+
activeId,
|
|
80
80
|
openedIds: []
|
|
81
81
|
});
|
|
82
|
+
const activate = (0, _react.useCallback)(id => {
|
|
83
|
+
setState(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
84
|
+
activeId: id
|
|
85
|
+
}));
|
|
86
|
+
onSelected === null || onSelected === void 0 ? void 0 : onSelected(id);
|
|
87
|
+
}, [onSelected]);
|
|
88
|
+
const open = (0, _react.useCallback)(id => {
|
|
89
|
+
setState(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
90
|
+
openedIds: [...prev.openedIds, id]
|
|
91
|
+
}));
|
|
92
|
+
}, []);
|
|
93
|
+
const close = (0, _react.useCallback)(id => {
|
|
94
|
+
setState(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
95
|
+
openedIds: prev.openedIds.filter(item => item !== id)
|
|
96
|
+
}));
|
|
97
|
+
}, []);
|
|
82
98
|
const contextValue = (0, _react.useMemo)(() => {
|
|
83
99
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
84
100
|
mode,
|
|
85
|
-
activate
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}));
|
|
89
|
-
onSelected === null || onSelected === void 0 ? void 0 : onSelected(id);
|
|
90
|
-
},
|
|
91
|
-
open: id => {
|
|
92
|
-
setState(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
93
|
-
openedIds: [...prev.openedIds, id]
|
|
94
|
-
}));
|
|
95
|
-
},
|
|
96
|
-
close: id => {
|
|
97
|
-
setState(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
98
|
-
openedIds: prev.openedIds.filter(item => item !== id)
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
+
activate,
|
|
102
|
+
open,
|
|
103
|
+
close
|
|
101
104
|
});
|
|
102
|
-
}, [state, mode,
|
|
105
|
+
}, [state, mode, activate, open, close]);
|
|
106
|
+
(0, _react.useEffect)(() => {
|
|
107
|
+
if (activeId) {
|
|
108
|
+
activate(activeId);
|
|
109
|
+
}
|
|
110
|
+
}, [activate, activeId]);
|
|
103
111
|
const classes = (0, _clsx.default)('navmenu', "navmenu--".concat(mode), rest.className);
|
|
104
112
|
|
|
105
113
|
const renderItem = (item, index) => {
|
|
@@ -146,7 +154,7 @@ NavMenu.propTypes = {
|
|
|
146
154
|
// inline 模式: 垂直布局, 且通过 click 事件来收缩/伸展子菜单, 适用于移动端
|
|
147
155
|
mode: _propTypes.default.oneOf(['horizontal', 'vertical', 'inline']),
|
|
148
156
|
children: _propTypes.default.array,
|
|
149
|
-
|
|
157
|
+
activeId: _propTypes.default.string,
|
|
150
158
|
textColor: _propTypes.default.string,
|
|
151
159
|
activeTextColor: _propTypes.default.string,
|
|
152
160
|
bgColor: _propTypes.default.string,
|
|
@@ -156,7 +164,7 @@ NavMenu.defaultProps = {
|
|
|
156
164
|
items: null,
|
|
157
165
|
mode: 'horizontal',
|
|
158
166
|
children: null,
|
|
159
|
-
|
|
167
|
+
activeId: null,
|
|
160
168
|
textColor: '#9397a1',
|
|
161
169
|
activeTextColor: '#25292f',
|
|
162
170
|
bgColor: '#fff',
|
package/lib/SplitButton/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.29",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"react": ">=18.1.0",
|
|
53
53
|
"react-ga": "^2.7.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "710f8e28829c64030a36e3d9301358834b8937e4",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/icons": "^2.1.
|
|
58
|
-
"@arcblock/react-hooks": "^2.1.
|
|
57
|
+
"@arcblock/icons": "^2.1.29",
|
|
58
|
+
"@arcblock/react-hooks": "^2.1.29",
|
|
59
59
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
60
60
|
"@emotion/react": "^11.9.0",
|
|
61
61
|
"@emotion/styled": "^11.8.1",
|
package/src/Header/header.js
CHANGED
|
@@ -69,7 +69,7 @@ const Root = styled.div`
|
|
|
69
69
|
.header-logo {
|
|
70
70
|
display: inline-flex;
|
|
71
71
|
position: relative;
|
|
72
|
-
height:
|
|
72
|
+
height: 44px;
|
|
73
73
|
margin-right: 16px;
|
|
74
74
|
img,
|
|
75
75
|
svg {
|
|
@@ -117,9 +117,6 @@ const Root = styled.div`
|
|
|
117
117
|
.header-addons {
|
|
118
118
|
display: flex;
|
|
119
119
|
align-items: center;
|
|
120
|
-
> *:last-child {
|
|
121
|
-
padding-right: 0;
|
|
122
|
-
}
|
|
123
120
|
}
|
|
124
121
|
${(props) => props.$theme.breakpoints.down('lg')} {
|
|
125
122
|
.header-brand {
|
package/src/NavMenu/nav-menu.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children, useEffect, createContext, useContext, useMemo, useState, useRef } from 'react';
|
|
1
|
+
import { Children, useEffect, createContext, useContext, useMemo, useState, useRef, useCallback } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
@@ -22,29 +22,43 @@ function useUniqueId(id) {
|
|
|
22
22
|
/**
|
|
23
23
|
* NavMenu, 导航组件, 可用于 header/footer/sidebar
|
|
24
24
|
*/
|
|
25
|
-
function NavMenu({ items, mode, children,
|
|
25
|
+
function NavMenu({ items, mode, children, activeId, textColor, activeTextColor, bgColor, onSelected, ...rest }) {
|
|
26
26
|
// eslint-disable-next-line no-param-reassign
|
|
27
27
|
children = filterItems(children);
|
|
28
28
|
if (!items?.length && !children?.length) {
|
|
29
29
|
throw new Error("One of 'items' or 'children' is required by NavMenu component.");
|
|
30
30
|
}
|
|
31
|
-
const [state, setState] = useState({ activeId
|
|
31
|
+
const [state, setState] = useState({ activeId, openedIds: [] });
|
|
32
|
+
|
|
33
|
+
const activate = useCallback(
|
|
34
|
+
(id) => {
|
|
35
|
+
setState((prev) => ({ ...prev, activeId: id }));
|
|
36
|
+
onSelected?.(id);
|
|
37
|
+
},
|
|
38
|
+
[onSelected]
|
|
39
|
+
);
|
|
40
|
+
const open = useCallback((id) => {
|
|
41
|
+
setState((prev) => ({ ...prev, openedIds: [...prev.openedIds, id] }));
|
|
42
|
+
}, []);
|
|
43
|
+
const close = useCallback((id) => {
|
|
44
|
+
setState((prev) => ({ ...prev, openedIds: prev.openedIds.filter((item) => item !== id) }));
|
|
45
|
+
}, []);
|
|
32
46
|
const contextValue = useMemo(() => {
|
|
33
47
|
return {
|
|
34
48
|
...state,
|
|
35
49
|
mode,
|
|
36
|
-
activate
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
open: (id) => {
|
|
41
|
-
setState((prev) => ({ ...prev, openedIds: [...prev.openedIds, id] }));
|
|
42
|
-
},
|
|
43
|
-
close: (id) => {
|
|
44
|
-
setState((prev) => ({ ...prev, openedIds: prev.openedIds.filter((item) => item !== id) }));
|
|
45
|
-
},
|
|
50
|
+
activate,
|
|
51
|
+
open,
|
|
52
|
+
close,
|
|
46
53
|
};
|
|
47
|
-
}, [state, mode,
|
|
54
|
+
}, [state, mode, activate, open, close]);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (activeId) {
|
|
58
|
+
activate(activeId);
|
|
59
|
+
}
|
|
60
|
+
}, [activate, activeId]);
|
|
61
|
+
|
|
48
62
|
const classes = clsx('navmenu', `navmenu--${mode}`, rest.className);
|
|
49
63
|
const renderItem = (item, index) => {
|
|
50
64
|
if (item.children) {
|
|
@@ -80,7 +94,7 @@ NavMenu.propTypes = {
|
|
|
80
94
|
// inline 模式: 垂直布局, 且通过 click 事件来收缩/伸展子菜单, 适用于移动端
|
|
81
95
|
mode: PropTypes.oneOf(['horizontal', 'vertical', 'inline']),
|
|
82
96
|
children: PropTypes.array,
|
|
83
|
-
|
|
97
|
+
activeId: PropTypes.string,
|
|
84
98
|
textColor: PropTypes.string,
|
|
85
99
|
activeTextColor: PropTypes.string,
|
|
86
100
|
bgColor: PropTypes.string,
|
|
@@ -90,7 +104,7 @@ NavMenu.defaultProps = {
|
|
|
90
104
|
items: null,
|
|
91
105
|
mode: 'horizontal',
|
|
92
106
|
children: null,
|
|
93
|
-
|
|
107
|
+
activeId: null,
|
|
94
108
|
textColor: '#9397a1',
|
|
95
109
|
activeTextColor: '#25292f',
|
|
96
110
|
bgColor: '#fff',
|
package/src/SplitButton/index.js
CHANGED
|
@@ -27,7 +27,7 @@ export default function SplitButton({ size, color, menu, children, variant, onCl
|
|
|
27
27
|
|
|
28
28
|
// 点击 item 后收起下拉菜单, 如果想要点击 action 后不收起下拉菜单, 可以在 item#onClick 时调用 e.stopPropagation()
|
|
29
29
|
const handleItemClick = (e) => {
|
|
30
|
-
if (e.target.classList.contains('
|
|
30
|
+
if (e.target.classList.contains('MuiMenuItem-root')) {
|
|
31
31
|
setOpen(false);
|
|
32
32
|
}
|
|
33
33
|
};
|