@blocklet/ui-react 1.17.16 → 1.17.19
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/Footer/index.js +13 -9
- package/lib/Header/index.js +12 -12
- package/lib/types.js +32 -0
- package/package.json +4 -4
- package/src/Footer/index.js +11 -7
- package/src/Header/index.js +13 -10
- package/src/types.js +25 -0
package/lib/Footer/index.js
CHANGED
|
@@ -7,8 +7,6 @@ exports.default = Footer;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
11
|
|
|
14
12
|
var _useTheme = _interopRequireDefault(require("@material-ui/core/styles/useTheme"));
|
|
@@ -17,7 +15,9 @@ var _Container = _interopRequireDefault(require("@material-ui/core/Container"));
|
|
|
17
15
|
|
|
18
16
|
var _NavMenu = _interopRequireDefault(require("@arcblock/ux/lib/NavMenu"));
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
var _types = require("../types");
|
|
19
|
+
|
|
20
|
+
const _excluded = ["meta"];
|
|
21
21
|
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
|
|
@@ -30,19 +30,23 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
30
30
|
*/
|
|
31
31
|
function Footer(_ref) {
|
|
32
32
|
let {
|
|
33
|
-
|
|
33
|
+
meta
|
|
34
34
|
} = _ref,
|
|
35
35
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
36
36
|
|
|
37
|
-
const theme = (0, _useTheme.default)();
|
|
37
|
+
const theme = (0, _useTheme.default)();
|
|
38
|
+
const blocklet = Object.assign({}, window.blocklet, meta);
|
|
39
|
+
|
|
40
|
+
if (!blocklet.appName) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
38
43
|
|
|
39
|
-
blockletMeta = blockletMeta || window.blocklet;
|
|
40
44
|
const {
|
|
41
45
|
appLogo,
|
|
42
46
|
appName,
|
|
43
47
|
theme: blockletTheme,
|
|
44
48
|
navigation
|
|
45
|
-
} =
|
|
49
|
+
} = blocklet;
|
|
46
50
|
return /*#__PURE__*/_react.default.createElement(Root, Object.assign({}, rest, {
|
|
47
51
|
$bgcolor: blockletTheme === null || blockletTheme === void 0 ? void 0 : blockletTheme.background,
|
|
48
52
|
$theme: theme
|
|
@@ -71,10 +75,10 @@ function Footer(_ref) {
|
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
Footer.propTypes = {
|
|
74
|
-
|
|
78
|
+
meta: _types.BlockletMeta
|
|
75
79
|
};
|
|
76
80
|
Footer.defaultProps = {
|
|
77
|
-
|
|
81
|
+
meta: {}
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
const Root = _styledComponents.default.div.withConfig({
|
package/lib/Header/index.js
CHANGED
|
@@ -25,7 +25,9 @@ var _context = require("@arcblock/ux/lib/Locale/context");
|
|
|
25
25
|
|
|
26
26
|
require("@iconify/iconify");
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
var _types = require("../types");
|
|
29
|
+
|
|
30
|
+
const _excluded = ["meta", "addons"];
|
|
29
31
|
|
|
30
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
33
|
|
|
@@ -87,7 +89,7 @@ const parseNavigation = navigation => {
|
|
|
87
89
|
|
|
88
90
|
function Header(_ref) {
|
|
89
91
|
let {
|
|
90
|
-
|
|
92
|
+
meta,
|
|
91
93
|
addons
|
|
92
94
|
} = _ref,
|
|
93
95
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -96,23 +98,21 @@ function Header(_ref) {
|
|
|
96
98
|
|
|
97
99
|
const {
|
|
98
100
|
locale
|
|
99
|
-
} = (0, _context.useLocaleContext)() || {};
|
|
100
|
-
|
|
101
|
-
blockletMeta = blockletMeta || window.blocklet;
|
|
101
|
+
} = (0, _context.useLocaleContext)() || {};
|
|
102
|
+
const blocklet = Object.assign({}, window.blocklet, meta);
|
|
102
103
|
|
|
103
|
-
if (!
|
|
104
|
-
console.warn('blocklet meta is not found.');
|
|
104
|
+
if (!blocklet.appName) {
|
|
105
105
|
return null;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
const {
|
|
109
109
|
appLogo,
|
|
110
110
|
appName,
|
|
111
|
-
theme
|
|
111
|
+
theme,
|
|
112
112
|
navigation = [],
|
|
113
113
|
enableConnect = true,
|
|
114
114
|
enableLocale = true
|
|
115
|
-
} =
|
|
115
|
+
} = blocklet;
|
|
116
116
|
const navItems = parseNavigation(navigation);
|
|
117
117
|
|
|
118
118
|
const renderAddons = () => {
|
|
@@ -157,7 +157,7 @@ function Header(_ref) {
|
|
|
157
157
|
brand: appName,
|
|
158
158
|
addons: renderAddons()
|
|
159
159
|
}, rest, {
|
|
160
|
-
$bgcolor:
|
|
160
|
+
$bgcolor: theme === null || theme === void 0 ? void 0 : theme.background
|
|
161
161
|
}), !(navItems !== null && navItems !== void 0 && navItems.length) ? null : _ref2 => {
|
|
162
162
|
let {
|
|
163
163
|
isMobile,
|
|
@@ -174,14 +174,14 @@ function Header(_ref) {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
Header.propTypes = {
|
|
177
|
-
|
|
177
|
+
meta: _types.BlockletMeta,
|
|
178
178
|
// 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
|
|
179
179
|
// - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
|
|
180
180
|
// - PropTypes.node: 将 addons 原样传给 UX Header 组件
|
|
181
181
|
addons: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node])
|
|
182
182
|
};
|
|
183
183
|
Header.defaultProps = {
|
|
184
|
-
|
|
184
|
+
meta: {},
|
|
185
185
|
addons: null
|
|
186
186
|
};
|
|
187
187
|
const StyledUxHeader = (0, _styledComponents.default)(_Header.ResponsiveHeader).withConfig({
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BlockletMeta = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/* eslint-disable import/prefer-default-export */
|
|
13
|
+
const BlockletMeta = _propTypes.default.shape({
|
|
14
|
+
appLogo: _propTypes.default.string,
|
|
15
|
+
appName: _propTypes.default.string,
|
|
16
|
+
theme: _propTypes.default.shape({
|
|
17
|
+
background: _propTypes.default.string
|
|
18
|
+
}),
|
|
19
|
+
enableConnect: _propTypes.default.bool,
|
|
20
|
+
enableLocale: _propTypes.default.bool,
|
|
21
|
+
navigation: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
22
|
+
title: _propTypes.default.string,
|
|
23
|
+
link: _propTypes.default.string,
|
|
24
|
+
icon: _propTypes.default.string,
|
|
25
|
+
items: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
26
|
+
title: _propTypes.default.string,
|
|
27
|
+
link: _propTypes.default.string
|
|
28
|
+
}))
|
|
29
|
+
}))
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
exports.BlockletMeta = BlockletMeta;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.19",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@arcblock/did-connect": "^1.17.
|
|
38
|
-
"@arcblock/ux": "^1.17.
|
|
37
|
+
"@arcblock/did-connect": "^1.17.19",
|
|
38
|
+
"@arcblock/ux": "^1.17.19",
|
|
39
39
|
"@iconify/iconify": "^2.2.1",
|
|
40
40
|
"@material-ui/core": "^4.12.3",
|
|
41
41
|
"core-js": "^3.6.4",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
57
57
|
"jest": "^24.1.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "fc295196e19ee7355a7dacab7f85fd9694cd2eb9"
|
|
60
60
|
}
|
package/src/Footer/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import styled from 'styled-components';
|
|
4
3
|
import useTheme from '@material-ui/core/styles/useTheme';
|
|
5
4
|
import Container from '@material-ui/core/Container';
|
|
6
5
|
import NavMenu from '@arcblock/ux/lib/NavMenu';
|
|
7
6
|
|
|
7
|
+
import { BlockletMeta } from '../types';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* 专门用于 (composable) blocklet 的 Footer 组件, 基于 blocklet meta 中的数据渲染
|
|
10
11
|
*/
|
|
11
|
-
export default function Footer({
|
|
12
|
+
export default function Footer({ meta, ...rest }) {
|
|
12
13
|
const theme = useTheme();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const blocklet = Object.assign({}, window.blocklet, meta);
|
|
15
|
+
if (!blocklet.appName) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { appLogo, appName, theme: blockletTheme, navigation } = blocklet;
|
|
16
20
|
return (
|
|
17
21
|
<Root {...rest} $bgcolor={blockletTheme?.background} $theme={theme}>
|
|
18
22
|
<Container>
|
|
@@ -45,11 +49,11 @@ export default function Footer({ blockletMeta, ...rest }) {
|
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
Footer.propTypes = {
|
|
48
|
-
|
|
52
|
+
meta: BlockletMeta,
|
|
49
53
|
};
|
|
50
54
|
|
|
51
55
|
Footer.defaultProps = {
|
|
52
|
-
|
|
56
|
+
meta: {},
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
const Root = styled.div`
|
package/src/Header/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import LocaleSelector from '@arcblock/ux/lib/Locale/selector';
|
|
|
9
9
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
10
10
|
import '@iconify/iconify';
|
|
11
11
|
|
|
12
|
+
import { BlockletMeta } from '../types';
|
|
13
|
+
|
|
12
14
|
const isLinkActive = link => {
|
|
13
15
|
if (window.location.pathname === '/') {
|
|
14
16
|
return link === '/';
|
|
@@ -53,23 +55,22 @@ const parseNavigation = navigation => {
|
|
|
53
55
|
/**
|
|
54
56
|
* 专门用于 (composable) blocklet 的 Header 组件, 解析 blocklet meta 中的数据, 通过组合 UX 中的 Header & NavMenu 组件来渲染
|
|
55
57
|
*/
|
|
56
|
-
export default function Header({
|
|
58
|
+
export default function Header({ meta, addons, ...rest }) {
|
|
57
59
|
const sessionInfo = React.useContext(SessionContext);
|
|
58
60
|
const { locale } = useLocaleContext() || {};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!blockletMeta) {
|
|
62
|
-
console.warn('blocklet meta is not found.');
|
|
61
|
+
const blocklet = Object.assign({}, window.blocklet, meta);
|
|
62
|
+
if (!blocklet.appName) {
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
|
+
|
|
65
66
|
const {
|
|
66
67
|
appLogo,
|
|
67
68
|
appName,
|
|
68
|
-
theme
|
|
69
|
+
theme,
|
|
69
70
|
navigation = [],
|
|
70
71
|
enableConnect = true,
|
|
71
72
|
enableLocale = true,
|
|
72
|
-
} =
|
|
73
|
+
} = blocklet;
|
|
73
74
|
const navItems = parseNavigation(navigation);
|
|
74
75
|
|
|
75
76
|
const renderAddons = () => {
|
|
@@ -93,6 +94,7 @@ export default function Header({ blockletMeta, addons, ...rest }) {
|
|
|
93
94
|
const addonsFragment = React.createElement(React.Fragment, null, ...addonsArray);
|
|
94
95
|
return addonsFragment;
|
|
95
96
|
};
|
|
97
|
+
|
|
96
98
|
return (
|
|
97
99
|
<StyledUxHeader
|
|
98
100
|
logo={
|
|
@@ -103,7 +105,7 @@ export default function Header({ blockletMeta, addons, ...rest }) {
|
|
|
103
105
|
brand={appName}
|
|
104
106
|
addons={renderAddons()}
|
|
105
107
|
{...rest}
|
|
106
|
-
$bgcolor={
|
|
108
|
+
$bgcolor={theme?.background}>
|
|
107
109
|
{/* blocklet.yml 没有配置 navigation 时, 则为 children 传入 null, 此时 ResponsiveHeader 会渲染普通的不带 menu 的 Header */}
|
|
108
110
|
{!navItems?.length
|
|
109
111
|
? null
|
|
@@ -121,7 +123,8 @@ export default function Header({ blockletMeta, addons, ...rest }) {
|
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
Header.propTypes = {
|
|
124
|
-
|
|
126
|
+
meta: BlockletMeta,
|
|
127
|
+
|
|
125
128
|
// 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
|
|
126
129
|
// - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
|
|
127
130
|
// - PropTypes.node: 将 addons 原样传给 UX Header 组件
|
|
@@ -129,7 +132,7 @@ Header.propTypes = {
|
|
|
129
132
|
};
|
|
130
133
|
|
|
131
134
|
Header.defaultProps = {
|
|
132
|
-
|
|
135
|
+
meta: {},
|
|
133
136
|
addons: null,
|
|
134
137
|
};
|
|
135
138
|
|
package/src/types.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
export const BlockletMeta = PropTypes.shape({
|
|
5
|
+
appLogo: PropTypes.string,
|
|
6
|
+
appName: PropTypes.string,
|
|
7
|
+
theme: PropTypes.shape({
|
|
8
|
+
background: PropTypes.string,
|
|
9
|
+
}),
|
|
10
|
+
enableConnect: PropTypes.bool,
|
|
11
|
+
enableLocale: PropTypes.bool,
|
|
12
|
+
navigation: PropTypes.arrayOf(
|
|
13
|
+
PropTypes.shape({
|
|
14
|
+
title: PropTypes.string,
|
|
15
|
+
link: PropTypes.string,
|
|
16
|
+
icon: PropTypes.string,
|
|
17
|
+
items: PropTypes.arrayOf(
|
|
18
|
+
PropTypes.shape({
|
|
19
|
+
title: PropTypes.string,
|
|
20
|
+
link: PropTypes.string,
|
|
21
|
+
})
|
|
22
|
+
),
|
|
23
|
+
})
|
|
24
|
+
),
|
|
25
|
+
});
|