@arcblock/ux 2.5.54 → 2.5.55
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/Address/did-address.js +17 -12
- package/lib/Address/index.js +13 -4
- package/lib/Avatar/index.js +34 -17
- package/lib/DID/index.js +117 -0
- package/package.json +6 -6
- package/src/Address/did-address.jsx +11 -10
- package/src/Address/index.jsx +4 -4
- package/src/Avatar/index.js +20 -13
- package/src/DID/index.jsx +85 -0
@@ -3,9 +3,9 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.formatAddress = exports.default = void 0;
|
6
|
+
exports.getFontSize = exports.formatAddress = exports.default = void 0;
|
7
7
|
|
8
|
-
var _react = require("react");
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
9
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
11
11
|
|
@@ -35,6 +35,10 @@ const _excluded = ["component", "size", "copyable", "content", "children", "prep
|
|
35
35
|
|
36
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37
37
|
|
38
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
39
|
+
|
40
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
41
|
+
|
38
42
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
39
43
|
|
40
44
|
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; }
|
@@ -50,6 +54,17 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
50
54
|
const formatAddress = str => str.split(':').pop();
|
51
55
|
|
52
56
|
exports.formatAddress = formatAddress;
|
57
|
+
|
58
|
+
const getFontSize = size => {
|
59
|
+
// 12px 及以上的 size 有效, 否则返回 inherit
|
60
|
+
if (size && Number(size) >= 12) {
|
61
|
+
return "".concat(Number(size), "px");
|
62
|
+
}
|
63
|
+
|
64
|
+
return 'inherit';
|
65
|
+
};
|
66
|
+
|
67
|
+
exports.getFontSize = getFontSize;
|
53
68
|
const translations = {
|
54
69
|
en: {
|
55
70
|
copy: 'Click To Copy',
|
@@ -198,16 +213,6 @@ DidAddress.defaultProps = {
|
|
198
213
|
endChars: 6,
|
199
214
|
locale: 'en'
|
200
215
|
};
|
201
|
-
|
202
|
-
const getFontSize = size => {
|
203
|
-
// 12px 及以上的 size 有效, 否则返回 inherit
|
204
|
-
if (size && Number(size) >= 12) {
|
205
|
-
return "".concat(Number(size), "px");
|
206
|
-
}
|
207
|
-
|
208
|
-
return 'inherit';
|
209
|
-
};
|
210
|
-
|
211
216
|
const Root = (0, _Theme.styled)('div', {
|
212
217
|
shouldForwardProp: prop => prop !== 'inline'
|
213
218
|
})(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-family: 'Ubuntu Mono', monospace;\n && {\n display: ", ";\n align-items: center;\n max-width: 100%;\n overflow: hidden;\n color: #ccc;\n font-size: ", ";\n font-weight: 400;\n\n svg {\n fill: currentColor;\n }\n }\n\n .did-address-text {\n color: #666;\n }\n /* truncate string with ellipsis */\n .did-address-truncate {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n .did-address-copy {\n flex: 0 0 auto;\n }\n .did-address-copy-wrapper {\n display: flex;\n justify-content: center;\n align-items: center;\n width: 1em;\n height: 1em;\n margin-left: 8px;\n }\n .did-address-copy {\n font-size: 1em;\n color: #999;\n cursor: pointer;\n }\n\n /* link */\n a {\n color: #666;\n }\n &:hover a {\n color: #222;\n text-decoration: underline;\n }\n"])), _ref2 => {
|
package/lib/Address/index.js
CHANGED
@@ -3,11 +3,18 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.default = DidAddressWrapper;
|
7
|
+
exports.formatAddress = void 0;
|
8
|
+
Object.defineProperty(exports, "getFontSize", {
|
9
|
+
enumerable: true,
|
10
|
+
get: function get() {
|
11
|
+
return _didAddress.getFontSize;
|
12
|
+
}
|
13
|
+
});
|
7
14
|
|
8
15
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
16
|
|
10
|
-
var _didAddress =
|
17
|
+
var _didAddress = _interopRequireWildcard(require("./did-address"));
|
11
18
|
|
12
19
|
var _responsiveDidAddress = _interopRequireDefault(require("./responsive-did-address"));
|
13
20
|
|
@@ -15,6 +22,10 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
15
22
|
|
16
23
|
const _excluded = ["responsive"];
|
17
24
|
|
25
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
26
|
+
|
27
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
28
|
+
|
18
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
30
|
|
20
31
|
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; }
|
@@ -44,8 +55,6 @@ function DidAddressWrapper(_ref) {
|
|
44
55
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_didAddress.default, _objectSpread({}, rest));
|
45
56
|
}
|
46
57
|
|
47
|
-
var _default = DidAddressWrapper;
|
48
|
-
exports.default = _default;
|
49
58
|
DidAddressWrapper.propTypes = {
|
50
59
|
responsive: _propTypes.default.bool
|
51
60
|
};
|
package/lib/Avatar/index.js
CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = AvatarWithErrorBoundary;
|
7
|
+
exports.isEthereumDid = void 0;
|
7
8
|
|
8
9
|
var _react = require("react");
|
9
10
|
|
@@ -29,7 +30,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
29
30
|
|
30
31
|
var _templateObject, _templateObject2;
|
31
32
|
|
32
|
-
const _excluded = ["did", "size", "src", "variant", "animation", "shape"];
|
33
|
+
const _excluded = ["did", "size", "src", "variant", "animation", "shape", "blockiesPadding"];
|
33
34
|
|
34
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35
36
|
|
@@ -76,6 +77,8 @@ const isEthereumDid = did => {
|
|
76
77
|
*/
|
77
78
|
|
78
79
|
|
80
|
+
exports.isEthereumDid = isEthereumDid;
|
81
|
+
|
79
82
|
function Avatar(props) {
|
80
83
|
const [imgError, setImgError] = (0, _react.useState)(false);
|
81
84
|
const newProps = (0, _Util.mergeProps)(props, Avatar, []);
|
@@ -86,7 +89,8 @@ function Avatar(props) {
|
|
86
89
|
src,
|
87
90
|
variant,
|
88
91
|
animation,
|
89
|
-
shape
|
92
|
+
shape,
|
93
|
+
blockiesPadding
|
90
94
|
} = newProps,
|
91
95
|
rest = _objectWithoutProperties(newProps, _excluded); // ethereum blockies
|
92
96
|
|
@@ -95,13 +99,13 @@ function Avatar(props) {
|
|
95
99
|
if (isEthereumDid(did)) {
|
96
100
|
return _etherscanBlockies.default.createIcon({
|
97
101
|
seed: did.replace('did:abt:', '').toLowerCase(),
|
98
|
-
size
|
102
|
+
size,
|
99
103
|
scale: 16
|
100
104
|
}).toDataURL();
|
101
105
|
}
|
102
106
|
|
103
107
|
return null;
|
104
|
-
}, [did]); // 如果显式传入 src 则直接使用 src
|
108
|
+
}, [did, size]); // 如果显式传入 src 则直接使用 src
|
105
109
|
|
106
110
|
if (src && !imgError) {
|
107
111
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledImg, _objectSpread(_objectSpread({
|
@@ -116,20 +120,31 @@ function Avatar(props) {
|
|
116
120
|
|
117
121
|
|
118
122
|
if (blockyIcon) {
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
123
|
+
if (blockiesPadding) {
|
124
|
+
// blocky icon 要与灰色卡片矩形留有空间
|
125
|
+
const padding = size > 24 ? 4 : 2;
|
126
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BlockyIconContainer, _objectSpread(_objectSpread({
|
127
|
+
$size: size
|
128
|
+
}, rest), {}, {
|
129
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
130
|
+
className: "blocky-icon-inner",
|
131
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Img.default, {
|
132
|
+
width: size * 0.7 - padding * 2,
|
133
|
+
src: blockyIcon,
|
134
|
+
alt: did
|
135
|
+
})
|
130
136
|
})
|
131
|
-
})
|
132
|
-
}
|
137
|
+
}));
|
138
|
+
}
|
139
|
+
|
140
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Img.default, {
|
141
|
+
width: size,
|
142
|
+
src: blockyIcon,
|
143
|
+
alt: did,
|
144
|
+
style: {
|
145
|
+
marginRight: 4
|
146
|
+
}
|
147
|
+
});
|
133
148
|
}
|
134
149
|
|
135
150
|
if (did) {
|
@@ -154,12 +169,14 @@ Avatar.propTypes = {
|
|
154
169
|
animation: _propTypes.default.bool,
|
155
170
|
// shape 仅对 did motif 有效, 明确指定 motif shape, 而非由 did role type 自动推断 shape
|
156
171
|
shape: _propTypes.default.oneOf(['', 'rectangle', 'square', 'hexagon', 'circle']),
|
172
|
+
blockiesPadding: _propTypes.default.bool,
|
157
173
|
responsive: _propTypes.default.bool
|
158
174
|
};
|
159
175
|
Avatar.defaultProps = {
|
160
176
|
size: 36,
|
161
177
|
variant: 'default',
|
162
178
|
animation: false,
|
179
|
+
blockiesPadding: true,
|
163
180
|
shape: '',
|
164
181
|
responsive: false
|
165
182
|
};
|
package/lib/DID/index.js
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
11
|
+
|
12
|
+
var _didMotif = require("@arcblock/did-motif");
|
13
|
+
|
14
|
+
var _Address = _interopRequireWildcard(require("../Address"));
|
15
|
+
|
16
|
+
var _Avatar = _interopRequireWildcard(require("../Avatar"));
|
17
|
+
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
19
|
+
|
20
|
+
const _excluded = ["did"];
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
|
+
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
27
|
+
|
28
|
+
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; }
|
29
|
+
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
31
|
+
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
33
|
+
|
34
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
35
|
+
|
36
|
+
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; }
|
37
|
+
|
38
|
+
const DIDPropTypes = {
|
39
|
+
did: _propTypes.default.string.isRequired,
|
40
|
+
size: _propTypes.default.number,
|
41
|
+
component: _propTypes.default.string,
|
42
|
+
copyable: _propTypes.default.bool,
|
43
|
+
responsive: _propTypes.default.bool,
|
44
|
+
showCopyButtonInTooltip: _propTypes.default.bool,
|
45
|
+
inline: _propTypes.default.bool,
|
46
|
+
append: _propTypes.default.any,
|
47
|
+
compact: _propTypes.default.bool,
|
48
|
+
startChars: _propTypes.default.number,
|
49
|
+
endChars: _propTypes.default.number,
|
50
|
+
locale: _propTypes.default.oneOf(['en', 'zh'])
|
51
|
+
};
|
52
|
+
|
53
|
+
const getFontColor = did => {
|
54
|
+
if ((0, _Avatar.isEthereumDid)(did)) {
|
55
|
+
const index = Uint8Array.from(did.slice(2).match(/.{1,2}/g).map(pair => parseInt(pair, 16))).slice(0, 8).reduce((acc, val) => acc + val, 0) % _didMotif.colors.length;
|
56
|
+
|
57
|
+
return _didMotif.colors[index];
|
58
|
+
}
|
59
|
+
|
60
|
+
return (0, _didMotif.getDIDMotifInfo)(did).color;
|
61
|
+
};
|
62
|
+
/**
|
63
|
+
* @type React.ForwardRefRenderFunction<HTMLElement, typeof DIDPropTypes>
|
64
|
+
*/
|
65
|
+
|
66
|
+
|
67
|
+
const DID = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
68
|
+
let {
|
69
|
+
did
|
70
|
+
} = _ref,
|
71
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
72
|
+
|
73
|
+
const fontSize = (0, _Address.getFontSize)(rest.size);
|
74
|
+
const prepend = [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
75
|
+
style: {
|
76
|
+
fontSize,
|
77
|
+
color: getFontColor(did)
|
78
|
+
},
|
79
|
+
children: "DID:"
|
80
|
+
}, "prefix-did"), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
81
|
+
className: "did-address-text",
|
82
|
+
style: {
|
83
|
+
fontSize
|
84
|
+
},
|
85
|
+
children: "ABT:"
|
86
|
+
}, "prefix-abt"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
87
|
+
did: did,
|
88
|
+
size: rest.size || 18,
|
89
|
+
style: {
|
90
|
+
marginLeft: 2,
|
91
|
+
marginRight: 2
|
92
|
+
},
|
93
|
+
blockiesPadding: false
|
94
|
+
}, "avatar")];
|
95
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, _objectSpread(_objectSpread({
|
96
|
+
ref: ref
|
97
|
+
}, rest), {}, {
|
98
|
+
prepend: prepend,
|
99
|
+
children: did
|
100
|
+
}));
|
101
|
+
});
|
102
|
+
var _default = DID;
|
103
|
+
exports.default = _default;
|
104
|
+
DID.propTypes = DIDPropTypes;
|
105
|
+
DID.defaultProps = {
|
106
|
+
size: 0,
|
107
|
+
component: 'span',
|
108
|
+
copyable: true,
|
109
|
+
responsive: true,
|
110
|
+
showCopyButtonInTooltip: false,
|
111
|
+
inline: false,
|
112
|
+
append: null,
|
113
|
+
compact: false,
|
114
|
+
startChars: 6,
|
115
|
+
endChars: 6,
|
116
|
+
locale: 'en'
|
117
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.5.
|
3
|
+
"version": "2.5.55",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"url": "git+https://github.com/ArcBlock/ux.git"
|
17
17
|
},
|
18
18
|
"scripts": {
|
19
|
-
"lint": "eslint src tests",
|
19
|
+
"lint": "eslint src tests --ext js --ext jsx",
|
20
20
|
"lint:fix": "npm run lint -- --fix",
|
21
21
|
"build": "babel src --out-dir lib --copy-files --no-copy-ignored",
|
22
22
|
"watch": "babel src --out-dir lib -w --copy-files --no-copy-ignored",
|
@@ -47,11 +47,11 @@
|
|
47
47
|
"peerDependencies": {
|
48
48
|
"react": ">=18.1.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "6ab89ceb6e7fb809ab7b45bf7c965ec5a276c033",
|
51
51
|
"dependencies": {
|
52
|
-
"@arcblock/did-motif": "^1.1.
|
53
|
-
"@arcblock/icons": "^2.5.
|
54
|
-
"@arcblock/react-hooks": "^2.5.
|
52
|
+
"@arcblock/did-motif": "^1.1.12",
|
53
|
+
"@arcblock/icons": "^2.5.55",
|
54
|
+
"@arcblock/react-hooks": "^2.5.55",
|
55
55
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
56
56
|
"@emotion/react": "^11.10.4",
|
57
57
|
"@emotion/styled": "^11.10.4",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useRef, useState, forwardRef } from 'react';
|
1
|
+
import React, { useRef, useState, forwardRef } from 'react';
|
2
2
|
import PropTypes from 'prop-types';
|
3
3
|
import '@fontsource/ubuntu-mono/400.css';
|
4
4
|
import useMountedState from 'react-use/lib/useMountedState';
|
@@ -7,12 +7,20 @@ import { green } from '@mui/material/colors';
|
|
7
7
|
import copy from 'copy-to-clipboard';
|
8
8
|
import CopyIcon from '@mui/icons-material/ContentCopy';
|
9
9
|
import CheckIcon from '@mui/icons-material/Check';
|
10
|
-
import { styled } from '../Theme';
|
11
10
|
|
11
|
+
import { styled } from '../Theme';
|
12
12
|
import CompactText from './compact-text';
|
13
13
|
|
14
14
|
export const formatAddress = (str) => str.split(':').pop();
|
15
15
|
|
16
|
+
export const getFontSize = (size) => {
|
17
|
+
// 12px 及以上的 size 有效, 否则返回 inherit
|
18
|
+
if (size && Number(size) >= 12) {
|
19
|
+
return `${Number(size)}px`;
|
20
|
+
}
|
21
|
+
return 'inherit';
|
22
|
+
};
|
23
|
+
|
16
24
|
const translations = {
|
17
25
|
en: {
|
18
26
|
copy: 'Click To Copy',
|
@@ -66,6 +74,7 @@ const DidAddress = forwardRef(
|
|
66
74
|
|
67
75
|
const [copied, setCopied] = useState(false);
|
68
76
|
const textRef = useRef();
|
77
|
+
|
69
78
|
const onCopy = (e) => {
|
70
79
|
e.stopPropagation();
|
71
80
|
copy(content || textRef.current.textContent);
|
@@ -154,14 +163,6 @@ DidAddress.defaultProps = {
|
|
154
163
|
locale: 'en',
|
155
164
|
};
|
156
165
|
|
157
|
-
const getFontSize = (size) => {
|
158
|
-
// 12px 及以上的 size 有效, 否则返回 inherit
|
159
|
-
if (size && Number(size) >= 12) {
|
160
|
-
return `${Number(size)}px`;
|
161
|
-
}
|
162
|
-
return 'inherit';
|
163
|
-
};
|
164
|
-
|
165
166
|
const Root = styled('div', { shouldForwardProp: (prop) => prop !== 'inline' })`
|
166
167
|
font-family: 'Ubuntu Mono', monospace;
|
167
168
|
&& {
|
package/src/Address/index.jsx
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
import PropTypes from 'prop-types';
|
2
|
-
import DidAddress from './did-address';
|
2
|
+
import DidAddress, { getFontSize } from './did-address';
|
3
3
|
import ResponsiveDidAddress from './responsive-did-address';
|
4
4
|
|
5
|
+
export { getFontSize };
|
6
|
+
|
5
7
|
export const formatAddress = (str) => str.split(':').pop();
|
6
8
|
|
7
|
-
function DidAddressWrapper({ responsive, ...rest }) {
|
9
|
+
export default function DidAddressWrapper({ responsive, ...rest }) {
|
8
10
|
if (responsive) {
|
9
11
|
return <ResponsiveDidAddress {...rest} />;
|
10
12
|
}
|
11
13
|
return <DidAddress {...rest} />;
|
12
14
|
}
|
13
15
|
|
14
|
-
export default DidAddressWrapper;
|
15
|
-
|
16
16
|
DidAddressWrapper.propTypes = {
|
17
17
|
responsive: PropTypes.bool,
|
18
18
|
};
|
package/src/Avatar/index.js
CHANGED
@@ -11,7 +11,7 @@ import DIDMotif from './did-motif';
|
|
11
11
|
import blockies from './etherscan-blockies';
|
12
12
|
|
13
13
|
// 参考: asset-chain @arcblock/did
|
14
|
-
const isEthereumDid = (did) => {
|
14
|
+
export const isEthereumDid = (did) => {
|
15
15
|
const address = did.replace('did:abt:', '');
|
16
16
|
// check if it has the basic requirements of an address
|
17
17
|
if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
|
@@ -42,7 +42,7 @@ const isEthereumDid = (did) => {
|
|
42
42
|
function Avatar(props) {
|
43
43
|
const [imgError, setImgError] = useState(false);
|
44
44
|
const newProps = mergeProps(props, Avatar, []);
|
45
|
-
const { did = '', size, src, variant, animation, shape, ...rest } = newProps;
|
45
|
+
const { did = '', size, src, variant, animation, shape, blockiesPadding, ...rest } = newProps;
|
46
46
|
|
47
47
|
// ethereum blockies
|
48
48
|
const blockyIcon = useMemo(() => {
|
@@ -50,13 +50,13 @@ function Avatar(props) {
|
|
50
50
|
return blockies
|
51
51
|
.createIcon({
|
52
52
|
seed: did.replace('did:abt:', '').toLowerCase(),
|
53
|
-
size
|
53
|
+
size,
|
54
54
|
scale: 16,
|
55
55
|
})
|
56
56
|
.toDataURL();
|
57
57
|
}
|
58
58
|
return null;
|
59
|
-
}, [did]);
|
59
|
+
}, [did, size]);
|
60
60
|
|
61
61
|
// 如果显式传入 src 则直接使用 src
|
62
62
|
if (src && !imgError) {
|
@@ -73,16 +73,21 @@ function Avatar(props) {
|
|
73
73
|
}
|
74
74
|
// 对于 eth address, 渲染成 blocky icon, 形状与 account role type 的 did motif 相似都为矩形, 高宽比为 0.7
|
75
75
|
if (blockyIcon) {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
<
|
81
|
-
<
|
82
|
-
|
83
|
-
|
84
|
-
|
76
|
+
if (blockiesPadding) {
|
77
|
+
// blocky icon 要与灰色卡片矩形留有空间
|
78
|
+
const padding = size > 24 ? 4 : 2;
|
79
|
+
return (
|
80
|
+
<BlockyIconContainer $size={size} {...rest}>
|
81
|
+
<div className="blocky-icon-inner">
|
82
|
+
<Img width={size * 0.7 - padding * 2} src={blockyIcon} alt={did} />
|
83
|
+
</div>
|
84
|
+
</BlockyIconContainer>
|
85
|
+
);
|
86
|
+
}
|
87
|
+
|
88
|
+
return <Img width={size} src={blockyIcon} alt={did} style={{ marginRight: 4 }} />;
|
85
89
|
}
|
90
|
+
|
86
91
|
if (did) {
|
87
92
|
// 渲染 did motif
|
88
93
|
return (
|
@@ -107,6 +112,7 @@ Avatar.propTypes = {
|
|
107
112
|
animation: PropTypes.bool,
|
108
113
|
// shape 仅对 did motif 有效, 明确指定 motif shape, 而非由 did role type 自动推断 shape
|
109
114
|
shape: PropTypes.oneOf(['', 'rectangle', 'square', 'hexagon', 'circle']),
|
115
|
+
blockiesPadding: PropTypes.bool,
|
110
116
|
responsive: PropTypes.bool,
|
111
117
|
};
|
112
118
|
|
@@ -114,6 +120,7 @@ Avatar.defaultProps = {
|
|
114
120
|
size: 36,
|
115
121
|
variant: 'default',
|
116
122
|
animation: false,
|
123
|
+
blockiesPadding: true,
|
117
124
|
shape: '',
|
118
125
|
responsive: false,
|
119
126
|
};
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import React, { forwardRef } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import { getDIDMotifInfo, colors } from '@arcblock/did-motif';
|
4
|
+
|
5
|
+
import Address, { getFontSize } from '../Address';
|
6
|
+
import Avatar, { isEthereumDid } from '../Avatar';
|
7
|
+
|
8
|
+
const DIDPropTypes = {
|
9
|
+
did: PropTypes.string.isRequired,
|
10
|
+
size: PropTypes.number,
|
11
|
+
component: PropTypes.string,
|
12
|
+
copyable: PropTypes.bool,
|
13
|
+
responsive: PropTypes.bool,
|
14
|
+
showCopyButtonInTooltip: PropTypes.bool,
|
15
|
+
inline: PropTypes.bool,
|
16
|
+
append: PropTypes.any,
|
17
|
+
compact: PropTypes.bool,
|
18
|
+
startChars: PropTypes.number,
|
19
|
+
endChars: PropTypes.number,
|
20
|
+
locale: PropTypes.oneOf(['en', 'zh']),
|
21
|
+
};
|
22
|
+
|
23
|
+
const getFontColor = (did) => {
|
24
|
+
if (isEthereumDid(did)) {
|
25
|
+
const index =
|
26
|
+
Uint8Array.from(
|
27
|
+
did
|
28
|
+
.slice(2)
|
29
|
+
.match(/.{1,2}/g)
|
30
|
+
.map((pair) => parseInt(pair, 16))
|
31
|
+
)
|
32
|
+
.slice(0, 8)
|
33
|
+
.reduce((acc, val) => acc + val, 0) % colors.length;
|
34
|
+
|
35
|
+
return colors[index];
|
36
|
+
}
|
37
|
+
|
38
|
+
return getDIDMotifInfo(did).color;
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @type React.ForwardRefRenderFunction<HTMLElement, typeof DIDPropTypes>
|
43
|
+
*/
|
44
|
+
const DID = forwardRef(({ did, ...rest }, ref) => {
|
45
|
+
const fontSize = getFontSize(rest.size);
|
46
|
+
const prepend = [
|
47
|
+
<span key="prefix-did" style={{ fontSize, color: getFontColor(did) }}>
|
48
|
+
DID:
|
49
|
+
</span>,
|
50
|
+
<span key="prefix-abt" className="did-address-text" style={{ fontSize }}>
|
51
|
+
ABT:
|
52
|
+
</span>,
|
53
|
+
<Avatar
|
54
|
+
key="avatar"
|
55
|
+
did={did}
|
56
|
+
size={rest.size || 18}
|
57
|
+
style={{ marginLeft: 2, marginRight: 2 }}
|
58
|
+
blockiesPadding={false}
|
59
|
+
/>,
|
60
|
+
];
|
61
|
+
|
62
|
+
return (
|
63
|
+
<Address ref={ref} {...rest} prepend={prepend}>
|
64
|
+
{did}
|
65
|
+
</Address>
|
66
|
+
);
|
67
|
+
});
|
68
|
+
|
69
|
+
export default DID;
|
70
|
+
|
71
|
+
DID.propTypes = DIDPropTypes;
|
72
|
+
|
73
|
+
DID.defaultProps = {
|
74
|
+
size: 0,
|
75
|
+
component: 'span',
|
76
|
+
copyable: true,
|
77
|
+
responsive: true,
|
78
|
+
showCopyButtonInTooltip: false,
|
79
|
+
inline: false,
|
80
|
+
append: null,
|
81
|
+
compact: false,
|
82
|
+
startChars: 6,
|
83
|
+
endChars: 6,
|
84
|
+
locale: 'en',
|
85
|
+
};
|