@arcblock/ux 2.4.9 → 2.4.12
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/Layout/dashboard/{with-external-link.js → external-link.js} +67 -33
- package/lib/Layout/dashboard/index.js +6 -5
- package/lib/Layout/dashboard/sidebar.js +11 -7
- package/package.json +4 -4
- package/src/Layout/dashboard/external-link.js +47 -0
- package/src/Layout/dashboard/index.js +4 -3
- package/src/Layout/dashboard/sidebar.js +5 -5
- package/src/Layout/dashboard/with-external-link.js +0 -20
@@ -3,14 +3,19 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
7
|
-
exports.
|
6
|
+
exports.Link = Link;
|
7
|
+
exports.NavLink = NavLink;
|
8
|
+
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
8
10
|
|
9
11
|
var _reactRouterDom = require("react-router-dom");
|
10
12
|
|
11
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
12
14
|
|
13
|
-
const _excluded = ["to", "external"]
|
15
|
+
const _excluded = ["children", "routerLinkComponent", "to", "external"],
|
16
|
+
_excluded2 = ["className"];
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
19
|
|
15
20
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
16
21
|
|
@@ -22,35 +27,64 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
22
27
|
|
23
28
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
24
29
|
|
25
|
-
// 包裹 router Link/NavLink 组件, 支持 external link (external 为 true
|
26
|
-
function
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
to: to
|
49
|
-
}, rest));
|
50
|
-
};
|
30
|
+
// 包裹 router Link/NavLink 组件, 支持 external link (external 为 true 时渲染为 a 标签)
|
31
|
+
function ExternalLink(_ref) {
|
32
|
+
let {
|
33
|
+
children,
|
34
|
+
routerLinkComponent: RouterLinkComponent,
|
35
|
+
to,
|
36
|
+
external
|
37
|
+
} = _ref,
|
38
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
39
|
+
|
40
|
+
if (external) {
|
41
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("a", _objectSpread(_objectSpread({
|
42
|
+
href: to
|
43
|
+
}, rest), {}, {
|
44
|
+
children: children
|
45
|
+
}));
|
46
|
+
}
|
47
|
+
|
48
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(RouterLinkComponent, _objectSpread(_objectSpread({
|
49
|
+
to: to
|
50
|
+
}, rest), {}, {
|
51
|
+
children: children
|
52
|
+
}));
|
51
53
|
}
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
ExternalLink.propTypes = {
|
56
|
+
children: _propTypes.default.any.isRequired,
|
57
|
+
routerLinkComponent: _propTypes.default.elementType.isRequired,
|
58
|
+
external: _propTypes.default.bool,
|
59
|
+
to: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]).isRequired
|
60
|
+
};
|
61
|
+
ExternalLink.defaultProps = {
|
62
|
+
external: false
|
63
|
+
};
|
64
|
+
|
65
|
+
function Link(props) {
|
66
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ExternalLink, _objectSpread({
|
67
|
+
routerLinkComponent: _reactRouterDom.Link
|
68
|
+
}, props));
|
69
|
+
}
|
70
|
+
|
71
|
+
function NavLink(_ref2) {
|
72
|
+
let {
|
73
|
+
className
|
74
|
+
} = _ref2,
|
75
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
76
|
+
|
77
|
+
// NavLink#className 支持 function
|
78
|
+
const classes = rest.external && typeof className === 'function' ? className({}) : className;
|
79
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ExternalLink, _objectSpread({
|
80
|
+
routerLinkComponent: _reactRouterDom.NavLink,
|
81
|
+
className: classes
|
82
|
+
}, rest));
|
83
|
+
}
|
84
|
+
|
85
|
+
NavLink.propTypes = {
|
86
|
+
className: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func])
|
87
|
+
};
|
88
|
+
NavLink.defaultProps = {
|
89
|
+
className: ''
|
90
|
+
};
|
@@ -31,10 +31,10 @@ var _Footer = _interopRequireDefault(require("../../Footer"));
|
|
31
31
|
|
32
32
|
var _sidebar = _interopRequireDefault(require("./sidebar"));
|
33
33
|
|
34
|
-
var _withExternalLink = require("./with-external-link");
|
35
|
-
|
36
34
|
var _Theme = require("../../Theme");
|
37
35
|
|
36
|
+
var _externalLink = require("./external-link");
|
37
|
+
|
38
38
|
var _jsxRuntime = require("react/jsx-runtime");
|
39
39
|
|
40
40
|
var _templateObject, _templateObject2;
|
@@ -80,12 +80,13 @@ function formatLinks(links, location) {
|
|
80
80
|
}
|
81
81
|
|
82
82
|
return _objectSpread(_objectSpread({}, link), {}, {
|
83
|
-
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
84
|
-
external: link.external,
|
83
|
+
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_externalLink.Link, {
|
85
84
|
to: link.url,
|
85
|
+
external: link.external,
|
86
86
|
children: link.title
|
87
87
|
}),
|
88
|
-
active
|
88
|
+
// external = true 时 active 状态由传入 links 的调用方决定 (适用于 blocklet ui dashboard 的情况)
|
89
|
+
active: link.external ? link.active : !!(0, _reactRouterDom.matchPath)({
|
89
90
|
path: link.url,
|
90
91
|
end: false
|
91
92
|
}, location.pathname)
|
@@ -13,10 +13,10 @@ var _colors = require("@mui/material/colors");
|
|
13
13
|
|
14
14
|
var _clsx = _interopRequireDefault(require("clsx"));
|
15
15
|
|
16
|
-
var _withExternalLink = require("./with-external-link");
|
17
|
-
|
18
16
|
var _Theme = require("../../Theme");
|
19
17
|
|
18
|
+
var _externalLink = require("./external-link");
|
19
|
+
|
20
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
21
21
|
|
22
22
|
var _templateObject;
|
@@ -64,17 +64,21 @@ function renderLinksItem(item) {
|
|
64
64
|
icon,
|
65
65
|
title,
|
66
66
|
showBadge,
|
67
|
-
external
|
68
|
-
|
67
|
+
external,
|
68
|
+
active
|
69
|
+
} = item; // external = true 时 link active 状态由传入 links 的调用方决定 (适用于 blocklet ui dashboard 的情况)
|
70
|
+
|
69
71
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
70
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
71
|
-
to: url,
|
72
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_externalLink.NavLink, {
|
72
73
|
external: external,
|
74
|
+
to: url,
|
73
75
|
className: _ref => {
|
74
76
|
let {
|
75
77
|
isActive
|
76
78
|
} = _ref;
|
77
|
-
return
|
79
|
+
return (0, _clsx.default)('layout-sidebar-link', {
|
80
|
+
'layout-sidebar-link--active': external ? active : isActive
|
81
|
+
});
|
78
82
|
},
|
79
83
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
80
84
|
className: "layout-sidebar-icon ".concat(showBadge ? 'layout-sidebar-badge' : ''),
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.4.
|
3
|
+
"version": "2.4.12",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -47,10 +47,10 @@
|
|
47
47
|
"react": ">=18.1.0",
|
48
48
|
"react-ga": "^2.7.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "67b9da0555a2ee6ddd151b2e0dd1e7bdae6108ef",
|
51
51
|
"dependencies": {
|
52
|
-
"@arcblock/icons": "^2.4.
|
53
|
-
"@arcblock/react-hooks": "^2.4.
|
52
|
+
"@arcblock/icons": "^2.4.12",
|
53
|
+
"@arcblock/react-hooks": "^2.4.12",
|
54
54
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
55
55
|
"@emotion/react": "^11.10.0",
|
56
56
|
"@emotion/styled": "^11.10.0",
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
import { Link as RouterLink, NavLink as RouterNavLink } from 'react-router-dom';
|
3
|
+
|
4
|
+
// 包裹 router Link/NavLink 组件, 支持 external link (external 为 true 时渲染为 a 标签)
|
5
|
+
function ExternalLink({ children, routerLinkComponent: RouterLinkComponent, to, external, ...rest }) {
|
6
|
+
if (external) {
|
7
|
+
return (
|
8
|
+
<a href={to} {...rest}>
|
9
|
+
{children}
|
10
|
+
</a>
|
11
|
+
);
|
12
|
+
}
|
13
|
+
return (
|
14
|
+
<RouterLinkComponent to={to} {...rest}>
|
15
|
+
{children}
|
16
|
+
</RouterLinkComponent>
|
17
|
+
);
|
18
|
+
}
|
19
|
+
|
20
|
+
ExternalLink.propTypes = {
|
21
|
+
children: PropTypes.any.isRequired,
|
22
|
+
routerLinkComponent: PropTypes.elementType.isRequired,
|
23
|
+
external: PropTypes.bool,
|
24
|
+
to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
|
25
|
+
};
|
26
|
+
|
27
|
+
ExternalLink.defaultProps = {
|
28
|
+
external: false,
|
29
|
+
};
|
30
|
+
|
31
|
+
export function Link(props) {
|
32
|
+
return <ExternalLink routerLinkComponent={RouterLink} {...props} />;
|
33
|
+
}
|
34
|
+
|
35
|
+
export function NavLink({ className, ...rest }) {
|
36
|
+
// NavLink#className 支持 function
|
37
|
+
const classes = rest.external && typeof className === 'function' ? className({}) : className;
|
38
|
+
return <ExternalLink routerLinkComponent={RouterNavLink} className={classes} {...rest} />;
|
39
|
+
}
|
40
|
+
|
41
|
+
NavLink.propTypes = {
|
42
|
+
className: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
43
|
+
};
|
44
|
+
|
45
|
+
NavLink.defaultProps = {
|
46
|
+
className: '',
|
47
|
+
};
|
@@ -11,8 +11,8 @@ import { ResponsiveHeader } from '../../Header';
|
|
11
11
|
import NavMenu from '../../NavMenu';
|
12
12
|
import Footer from '../../Footer';
|
13
13
|
import Sidebar from './sidebar';
|
14
|
-
import { Link } from './with-external-link';
|
15
14
|
import { styled, useTheme } from '../../Theme';
|
15
|
+
import { Link } from './external-link';
|
16
16
|
|
17
17
|
// 监听 location 变化并关闭 header 中的 menu (确保 drawer - disablePortal:false, keepMounted:true)
|
18
18
|
// 直接监听 menu 中 link 点击来触发 closeMenu 会有问题 (Suspense & lazy)
|
@@ -34,11 +34,12 @@ function formatLinks(links, location) {
|
|
34
34
|
return {
|
35
35
|
...link,
|
36
36
|
label: (
|
37
|
-
<Link
|
37
|
+
<Link to={link.url} external={link.external}>
|
38
38
|
{link.title}
|
39
39
|
</Link>
|
40
40
|
),
|
41
|
-
active
|
41
|
+
// external = true 时 active 状态由传入 links 的调用方决定 (适用于 blocklet ui dashboard 的情况)
|
42
|
+
active: link.external ? link.active : !!matchPath({ path: link.url, end: false }, location.pathname),
|
42
43
|
};
|
43
44
|
});
|
44
45
|
}
|
@@ -3,9 +3,8 @@ import PropTypes from 'prop-types';
|
|
3
3
|
import Typography from '@mui/material/Typography';
|
4
4
|
import { teal } from '@mui/material/colors';
|
5
5
|
import clsx from 'clsx';
|
6
|
-
|
7
|
-
import { NavLink } from './with-external-link';
|
8
6
|
import { styled } from '../../Theme';
|
7
|
+
import { NavLink } from './external-link';
|
9
8
|
|
10
9
|
// 渲染 links, 为 group links 添加分隔线, 返回展平后的、包含分隔线元素的 links 数组
|
11
10
|
function renderLinks(links) {
|
@@ -25,14 +24,15 @@ function renderLinksItem(item) {
|
|
25
24
|
if (Array.isArray(item)) {
|
26
25
|
return item.map(renderLinksItem);
|
27
26
|
}
|
28
|
-
const { url, icon, title, showBadge, external } = item;
|
27
|
+
const { url, icon, title, showBadge, external, active } = item;
|
28
|
+
// external = true 时 link active 状态由传入 links 的调用方决定 (适用于 blocklet ui dashboard 的情况)
|
29
29
|
return (
|
30
30
|
<li key={url}>
|
31
31
|
<NavLink
|
32
|
-
to={url}
|
33
32
|
external={external}
|
33
|
+
to={url}
|
34
34
|
className={({ isActive }) =>
|
35
|
-
|
35
|
+
clsx('layout-sidebar-link', { 'layout-sidebar-link--active': external ? active : isActive })
|
36
36
|
}>
|
37
37
|
<span className={`layout-sidebar-icon ${showBadge ? 'layout-sidebar-badge' : ''}`}>{icon}</span>
|
38
38
|
<Typography component="span" className="layout-sidebar-link-text">
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { Link as RouterLink, NavLink as RouterNavLink } from 'react-router-dom';
|
2
|
-
|
3
|
-
// 包裹 router Link/NavLink 组件, 支持 external link (external 为 true 时通过 click 事件跳转)
|
4
|
-
export function withExternalLink(RouterLinkComponent) {
|
5
|
-
// eslint-disable-next-line react/prop-types
|
6
|
-
return function WithExternalLink({ to, external, ...rest }) {
|
7
|
-
const handleClick = (e) => {
|
8
|
-
e.preventDefault();
|
9
|
-
window.location.href = to;
|
10
|
-
};
|
11
|
-
if (external) {
|
12
|
-
return <RouterLinkComponent onClick={handleClick} to={to} {...rest} />;
|
13
|
-
}
|
14
|
-
return <RouterLinkComponent to={to} {...rest} />;
|
15
|
-
};
|
16
|
-
}
|
17
|
-
|
18
|
-
export const Link = withExternalLink(RouterLink);
|
19
|
-
|
20
|
-
export const NavLink = withExternalLink(RouterNavLink);
|