@arcblock/ux 2.6.9 → 2.7.0
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/babel.config.es.js +12 -0
- package/es/ActionButton/index.js +99 -0
- package/es/ActivityIndicator/index.js +180 -0
- package/es/Address/compact-text.js +105 -0
- package/es/Address/did-address.js +211 -0
- package/es/Address/index.js +23 -0
- package/es/Address/responsive-did-address.js +88 -0
- package/es/Alert/index.js +134 -0
- package/es/AnimationWaiter/default-animation.json +1 -0
- package/es/AnimationWaiter/index.js +239 -0
- package/es/Async/index.js +38 -0
- package/es/Avatar/did-motif.js +64 -0
- package/es/Avatar/etherscan-blockies.js +83 -0
- package/es/Avatar/index.js +176 -0
- package/es/Badge/index.js +98 -0
- package/es/Blocklet/blocklet.js +298 -0
- package/es/Blocklet/index.js +4 -0
- package/es/Blocklet/utils.js +52 -0
- package/es/BlockletNFT/index.js +412 -0
- package/es/Button/index.js +8 -0
- package/es/Button/wrap.js +140 -0
- package/es/ButtonGroup/index.js +6 -0
- package/es/CardSelector/index.js +131 -0
- package/es/Center/index.js +41 -0
- package/es/ClickToCopy/copy-button.js +72 -0
- package/es/ClickToCopy/hook.js +39 -0
- package/es/ClickToCopy/index.js +93 -0
- package/es/CodeBlock/LightBox.js +85 -0
- package/es/CodeBlock/index.js +226 -0
- package/es/Colors/index.js +2 -0
- package/es/Colors/themes/default.js +78 -0
- package/es/ContactForm/index.js +230 -0
- package/es/CookieConsent/index.js +113 -0
- package/es/CountDown/index.js +178 -0
- package/es/DID/index.js +105 -0
- package/es/Datatable/CustomToolbar.js +396 -0
- package/es/Datatable/DatatableContext.js +34 -0
- package/es/Datatable/TableSearch.js +165 -0
- package/es/Datatable/index.js +627 -0
- package/es/Datatable/utils.js +132 -0
- package/es/Dialog/confirm.js +90 -0
- package/es/Dialog/dialog.js +192 -0
- package/es/Dialog/index.js +3 -0
- package/es/DidLogo/index.js +31 -0
- package/es/DriftBot/index.js +70 -0
- package/es/Earth/countries.json +8057 -0
- package/es/Earth/index.js +521 -0
- package/es/Earth/util.js +51 -0
- package/es/Empty/index.js +64 -0
- package/es/ErrorBoundary/fallback.js +73 -0
- package/es/ErrorBoundary/index.js +1 -0
- package/es/Footer/index.js +172 -0
- package/es/Header/auto-hidden.js +35 -0
- package/es/Header/header.js +211 -0
- package/es/Header/index.js +2 -0
- package/es/Header/responsive-header.js +111 -0
- package/es/Icon/image.js +65 -0
- package/es/Icon/index.js +84 -0
- package/es/Img/index.js +217 -0
- package/es/InfoRow/index.js +87 -0
- package/es/Layout/dashboard/external-link.js +58 -0
- package/es/Layout/dashboard/full-page.js +53 -0
- package/es/Layout/dashboard/index.js +275 -0
- package/es/Layout/dashboard/sidebar.js +209 -0
- package/es/Layout/dashboard-legacy/header.js +174 -0
- package/es/Layout/dashboard-legacy/index.js +149 -0
- package/es/Layout/dashboard-legacy/sidebar.js +129 -0
- package/es/Layout/index.js +335 -0
- package/es/Locale/browser-lang.js +52 -0
- package/es/Locale/context.js +114 -0
- package/es/Locale/languages.js +60 -0
- package/es/Locale/selector.js +180 -0
- package/es/Locale/util.js +13 -0
- package/es/Logo/images/logo-dark-text.svg +3 -0
- package/es/Logo/images/logo-dark-top.svg +6 -0
- package/es/Logo/images/logo-light-text.svg +3 -0
- package/es/Logo/images/logo-light-top.svg +6 -0
- package/es/Logo/index.js +136 -0
- package/es/Metric/index.js +132 -0
- package/es/NFTDisplay/README.md +59 -0
- package/es/NFTDisplay/aspect-ratio-container.js +39 -0
- package/es/NFTDisplay/broken.js +18 -0
- package/es/NFTDisplay/demo/data/asset-state-display-url.json +7 -0
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-1-1.json +10 -0
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-374-130.json +10 -0
- package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-with-foreign-object.json +20 -0
- package/es/NFTDisplay/demo/data/asset-state-svg.json +29 -0
- package/es/NFTDisplay/demo/data/asset-state-url.json +10 -0
- package/es/NFTDisplay/index.js +323 -0
- package/es/NFTDisplay/loading.js +18 -0
- package/es/NFTDisplay/svg-embedder/img.js +45 -0
- package/es/NFTDisplay/svg-embedder/inline-svg.js +39 -0
- package/es/NavMenu/index.js +2 -0
- package/es/NavMenu/nav-menu.js +286 -0
- package/es/NavMenu/style.js +176 -0
- package/es/PageScroller/index.js +286 -0
- package/es/PageScroller/story/FifthComponent.js +9 -0
- package/es/PageScroller/story/FirstComponent.js +9 -0
- package/es/PageScroller/story/FourthComponent.js +12 -0
- package/es/PageScroller/story/FullPage.js +47 -0
- package/es/PageScroller/story/PageContain.js +59 -0
- package/es/PageScroller/story/SecondComponent.js +9 -0
- package/es/PageScroller/story/ThirdComponent.js +9 -0
- package/es/PageScroller/story/index.css +115 -0
- package/es/PageScroller/usePrevValue.js +9 -0
- package/es/PricingTable/PricingPlan.js +124 -0
- package/es/PricingTable/index.js +53 -0
- package/es/QRCode/index.js +72 -0
- package/es/RelativeTime/index.js +98 -0
- package/es/Result/common.js +140 -0
- package/es/Result/demo/fixtures/result-image-404.svg +1 -0
- package/es/Result/index.js +33 -0
- package/es/Result/result.js +59 -0
- package/es/Result/translations.js +54 -0
- package/es/Screenshot/BaseScreenshot/index.js +91 -0
- package/es/Screenshot/BaseScreenshot/shells/Macbook.js +51 -0
- package/es/Screenshot/BaseScreenshot/shells/Phone.js +36 -0
- package/es/Screenshot/demo/images/bg-00.jpg +0 -0
- package/es/Screenshot/demo/images/bg-01.jpg +0 -0
- package/es/Screenshot/demo/images/bg-02.jpg +0 -0
- package/es/Screenshot/demo/images/bg-03.jpg +0 -0
- package/es/Screenshot/demo/images/bg-04.jpg +0 -0
- package/es/Screenshot/demo/images/bg-05.jpg +0 -0
- package/es/Screenshot/demo/images/bg-06.jpg +0 -0
- package/es/Screenshot/demo/images/bg-07.jpg +0 -0
- package/es/Screenshot/demo/images/bg-08.jpg +0 -0
- package/es/Screenshot/demo/images/bg-09.jpg +0 -0
- package/es/Screenshot/devices.css +1366 -0
- package/es/Screenshot/index.js +299 -0
- package/es/SessionManager/federated-login-detecter.js +166 -0
- package/es/SessionManager/index.js +468 -0
- package/es/SessionManager/user-popper.js +132 -0
- package/es/Sparkline/index.js +193 -0
- package/es/Spinner/index.js +28 -0
- package/es/SplitButton/index.js +144 -0
- package/es/Switch/index.js +96 -0
- package/es/Tabs/index.js +48 -0
- package/es/Tag/index.js +108 -0
- package/es/TextCollapse/index.js +92 -0
- package/es/Theme/index.js +16 -0
- package/es/Theme/theme-provider.js +39 -0
- package/es/Theme/theme.js +133 -0
- package/es/Toast/index.js +95 -0
- package/es/Util/deprecate.js +28 -0
- package/es/Util/index.js +298 -0
- package/es/Util/wallet.js +32 -0
- package/es/Video/index.js +89 -0
- package/es/Wallet/Action.js +119 -0
- package/es/Wallet/Download.js +331 -0
- package/es/Wallet/Open.js +45 -0
- package/es/Wallet/images/abtwallet.png +0 -0
- package/es/Wallet/images/android_download.svg +23 -0
- package/es/Wallet/images/app-store.svg +20 -0
- package/es/Wallet/images/google-play.svg +70 -0
- package/es/WebWalletSWKeeper/index.js +115 -0
- package/es/WechatPrompt/images/android.png +0 -0
- package/es/WechatPrompt/images/ios.png +0 -0
- package/es/WechatPrompt/index.js +88 -0
- package/es/index.js +38 -0
- package/es/withTheme/index.js +69 -0
- package/es/withTracker/README.md +34 -0
- package/es/withTracker/error_boundary.js +34 -0
- package/es/withTracker/index.js +56 -0
- package/package.json +272 -5
@@ -0,0 +1,12 @@
|
|
1
|
+
module.exports = {
|
2
|
+
presets: [
|
3
|
+
['@babel/preset-env', { modules: false, targets: 'chrome 114' }],
|
4
|
+
['@babel/preset-react', { useBuiltIns: true, runtime: 'automatic' }],
|
5
|
+
],
|
6
|
+
plugins: [
|
7
|
+
'babel-plugin-inline-react-svg',
|
8
|
+
'@babel/plugin-syntax-dynamic-import',
|
9
|
+
'@babel/plugin-proposal-class-properties',
|
10
|
+
],
|
11
|
+
ignore: ['src/**/*.stories.js', 'src/**/demo'],
|
12
|
+
};
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
import Button from '../Button';
|
3
|
+
import { mergeProps } from '../Util';
|
4
|
+
import { withDeprecated } from '../Util/deprecate';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Action button component
|
8
|
+
* @typedef {{
|
9
|
+
* href: string;
|
10
|
+
* children?: import('react').ReactNode;
|
11
|
+
* gradient?: string;
|
12
|
+
* color?: string;
|
13
|
+
* icon?: string;
|
14
|
+
* border?: string;
|
15
|
+
* text?: string;
|
16
|
+
* theme?: string;
|
17
|
+
* variant?: string;
|
18
|
+
* size?: string;
|
19
|
+
* width?: string;
|
20
|
+
* }} ActionButtonProps
|
21
|
+
*/
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Action button component
|
25
|
+
* @param {ActionButtonProps} props
|
26
|
+
* @returns {JSX.Element}
|
27
|
+
*/
|
28
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
29
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
30
|
+
function ActionButton(props) {
|
31
|
+
/** @type {ActionButtonProps & {}} */
|
32
|
+
const newProps = mergeProps(props, ActionButton);
|
33
|
+
const {
|
34
|
+
href,
|
35
|
+
icon,
|
36
|
+
size,
|
37
|
+
color,
|
38
|
+
theme,
|
39
|
+
variant,
|
40
|
+
gradient,
|
41
|
+
children,
|
42
|
+
text,
|
43
|
+
...rest
|
44
|
+
} = newProps;
|
45
|
+
|
46
|
+
/** @type {import('react').CSSProperties} */
|
47
|
+
const styles = {};
|
48
|
+
if (gradient) {
|
49
|
+
styles.backgroundImage = gradient;
|
50
|
+
styles.borderColor = 'transparent';
|
51
|
+
}
|
52
|
+
const attrs = ['color', 'border', 'width'];
|
53
|
+
attrs.forEach(x => {
|
54
|
+
if (newProps[x]) {
|
55
|
+
styles[x] = newProps[x];
|
56
|
+
}
|
57
|
+
});
|
58
|
+
return /*#__PURE__*/_jsxs(Button, {
|
59
|
+
color: theme,
|
60
|
+
href: href,
|
61
|
+
target: "_blank",
|
62
|
+
variant: variant,
|
63
|
+
style: styles,
|
64
|
+
size: size,
|
65
|
+
className: "action-button",
|
66
|
+
...rest,
|
67
|
+
children: [!!icon && /*#__PURE__*/_jsx("i", {
|
68
|
+
className: icon
|
69
|
+
}), text || children]
|
70
|
+
});
|
71
|
+
}
|
72
|
+
ActionButton.propTypes = {
|
73
|
+
href: PropTypes.string.isRequired,
|
74
|
+
children: PropTypes.any,
|
75
|
+
gradient: PropTypes.string,
|
76
|
+
color: PropTypes.string,
|
77
|
+
icon: PropTypes.string,
|
78
|
+
border: PropTypes.string,
|
79
|
+
text: PropTypes.string,
|
80
|
+
theme: PropTypes.string,
|
81
|
+
variant: PropTypes.string,
|
82
|
+
size: PropTypes.string,
|
83
|
+
width: PropTypes.string
|
84
|
+
};
|
85
|
+
ActionButton.defaultProps = {
|
86
|
+
gradient: '',
|
87
|
+
icon: '',
|
88
|
+
text: '',
|
89
|
+
color: '',
|
90
|
+
border: '',
|
91
|
+
width: '',
|
92
|
+
theme: 'inherit',
|
93
|
+
variant: 'outlined',
|
94
|
+
size: 'large',
|
95
|
+
children: null
|
96
|
+
};
|
97
|
+
export default withDeprecated(ActionButton, {
|
98
|
+
name: 'ActionButton'
|
99
|
+
});
|
@@ -0,0 +1,180 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import { green, blue } from '@mui/material/colors';
|
4
|
+
import Logo from '../Logo';
|
5
|
+
import colors from '../Colors';
|
6
|
+
import { styled } from '../Theme';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* ActivityIndicator is used when we want to tell the user the request they made on the UI will take time.
|
10
|
+
* @typedef {{
|
11
|
+
* interval?: number;
|
12
|
+
* messages: string[];
|
13
|
+
* } & import('react').ComponentPropsWithoutRef<"div"> } ActivityIndicatorProps
|
14
|
+
*/
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @description ActivityIndicator is used when we want to tell the user the request they made on the UI will take time.
|
18
|
+
* @param {ActivityIndicatorProps} props
|
19
|
+
* @returns {JSX.Element}
|
20
|
+
*/
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
22
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
23
|
+
export default function ActivityIndicator({
|
24
|
+
messages,
|
25
|
+
interval,
|
26
|
+
...rest
|
27
|
+
}) {
|
28
|
+
const [index, setIndex] = useState(0);
|
29
|
+
useEffect(() => {
|
30
|
+
const timer = setInterval(() => {
|
31
|
+
setIndex((index + 1) % messages.length);
|
32
|
+
}, interval);
|
33
|
+
return () => {
|
34
|
+
clearTimeout(timer);
|
35
|
+
};
|
36
|
+
});
|
37
|
+
return /*#__PURE__*/_jsx(Div, {
|
38
|
+
...rest,
|
39
|
+
children: /*#__PURE__*/_jsxs("div", {
|
40
|
+
className: "pm-loader-container",
|
41
|
+
children: [/*#__PURE__*/_jsx("div", {
|
42
|
+
className: "pm-loader-text",
|
43
|
+
children: /*#__PURE__*/_jsx("p", {
|
44
|
+
children: messages[index]
|
45
|
+
})
|
46
|
+
}), /*#__PURE__*/_jsxs("div", {
|
47
|
+
className: "pm-loader-atoms",
|
48
|
+
children: [/*#__PURE__*/_jsx(Logo, {
|
49
|
+
style: {
|
50
|
+
transform: 'scale(0.6)'
|
51
|
+
},
|
52
|
+
showText: false
|
53
|
+
}), /*#__PURE__*/_jsx(Orbit, {
|
54
|
+
size: 56,
|
55
|
+
orbitColor: green[500],
|
56
|
+
atomColor: green[500],
|
57
|
+
duration: 1
|
58
|
+
}), /*#__PURE__*/_jsx(Orbit, {
|
59
|
+
size: 80,
|
60
|
+
orbitColor: blue[800],
|
61
|
+
atomColor: blue[800],
|
62
|
+
duration: 1.5
|
63
|
+
}), /*#__PURE__*/_jsx(Orbit, {
|
64
|
+
size: 100,
|
65
|
+
orbitColor: colors.grey[900],
|
66
|
+
atomColor: colors.grey[900]
|
67
|
+
})]
|
68
|
+
})]
|
69
|
+
})
|
70
|
+
});
|
71
|
+
}
|
72
|
+
ActivityIndicator.propTypes = {
|
73
|
+
interval: PropTypes.number,
|
74
|
+
messages: PropTypes.arrayOf(PropTypes.string.isRequired)
|
75
|
+
};
|
76
|
+
ActivityIndicator.defaultProps = {
|
77
|
+
interval: 3000,
|
78
|
+
messages: ['Loading data...']
|
79
|
+
};
|
80
|
+
const Div = styled('div')`
|
81
|
+
&& {
|
82
|
+
box-sizing: border-box;
|
83
|
+
padding: 20px;
|
84
|
+
width: 100%;
|
85
|
+
height: 100%;
|
86
|
+
min-height: 360px;
|
87
|
+
z-index: 100;
|
88
|
+
transition: opacity 0.5s linear;
|
89
|
+
display: flex;
|
90
|
+
align-items: center;
|
91
|
+
flex-direction: column;
|
92
|
+
justify-content: center;
|
93
|
+
}
|
94
|
+
|
95
|
+
.pm-loader-text {
|
96
|
+
color: ${colors.grey[900]};
|
97
|
+
font-size: 14px;
|
98
|
+
text-align: center;
|
99
|
+
position: relative;
|
100
|
+
height: 70px;
|
101
|
+
-webkit-user-select: none;
|
102
|
+
}
|
103
|
+
|
104
|
+
.pm-loader-container {
|
105
|
+
width: 100%;
|
106
|
+
height: 100%;
|
107
|
+
display: flex;
|
108
|
+
align-items: center;
|
109
|
+
flex-direction: column;
|
110
|
+
justify-content: center;
|
111
|
+
flex: 1;
|
112
|
+
}
|
113
|
+
|
114
|
+
.pm-loader-atoms {
|
115
|
+
width: 100px;
|
116
|
+
height: 100px;
|
117
|
+
display: flex;
|
118
|
+
position: relative;
|
119
|
+
align-items: center;
|
120
|
+
justify-content: center;
|
121
|
+
}
|
122
|
+
`;
|
123
|
+
function Orbit({
|
124
|
+
size,
|
125
|
+
orbitColor,
|
126
|
+
atomColor,
|
127
|
+
duration,
|
128
|
+
...rest
|
129
|
+
}) {
|
130
|
+
return /*#__PURE__*/_jsx(OrbitRoot, {
|
131
|
+
$duration: duration,
|
132
|
+
style: {
|
133
|
+
width: size,
|
134
|
+
height: size,
|
135
|
+
border: `1px solid ${orbitColor}`
|
136
|
+
},
|
137
|
+
...rest,
|
138
|
+
children: /*#__PURE__*/_jsx("div", {
|
139
|
+
style: {
|
140
|
+
background: atomColor
|
141
|
+
}
|
142
|
+
})
|
143
|
+
});
|
144
|
+
}
|
145
|
+
Orbit.propTypes = {
|
146
|
+
size: PropTypes.number.isRequired,
|
147
|
+
orbitColor: PropTypes.string.isRequired,
|
148
|
+
atomColor: PropTypes.string.isRequired,
|
149
|
+
duration: PropTypes.number
|
150
|
+
};
|
151
|
+
Orbit.defaultProps = {
|
152
|
+
duration: 2
|
153
|
+
};
|
154
|
+
const OrbitRoot = styled('div')`
|
155
|
+
@keyframes orbit {
|
156
|
+
0% {
|
157
|
+
transform: rotate(0deg);
|
158
|
+
}
|
159
|
+
100% {
|
160
|
+
transform: rotate(360deg);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
position: absolute;
|
165
|
+
border-radius: 50%;
|
166
|
+
animation: orbit ${({
|
167
|
+
$duration
|
168
|
+
}) => $duration}s infinite;
|
169
|
+
animation-timing-function: linear;
|
170
|
+
transform-origin: center;
|
171
|
+
|
172
|
+
> div {
|
173
|
+
position: absolute;
|
174
|
+
top: 50%;
|
175
|
+
width: 6px;
|
176
|
+
height: 6px;
|
177
|
+
transform: translateX(-50%);
|
178
|
+
border-radius: 50%;
|
179
|
+
}
|
180
|
+
`;
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import { Children } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import Tooltip, { tooltipClasses } from '@mui/material/Tooltip';
|
4
|
+
import Box from '@mui/material/Box';
|
5
|
+
import { styled } from '../Theme';
|
6
|
+
import { CopyButton } from '../ClickToCopy';
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
9
|
+
const StyledTooltip = styled(({
|
10
|
+
className,
|
11
|
+
...props
|
12
|
+
}) => /*#__PURE__*/_jsx(Tooltip, {
|
13
|
+
...props,
|
14
|
+
classes: {
|
15
|
+
popper: className
|
16
|
+
}
|
17
|
+
}))({
|
18
|
+
[`& .${tooltipClasses.tooltip}`]: {
|
19
|
+
maxWidth: 360,
|
20
|
+
wordBreak: 'break-all'
|
21
|
+
}
|
22
|
+
});
|
23
|
+
|
24
|
+
// 递归, 将 text (string) 部分替换为 CompactText (保持元素结构)
|
25
|
+
// eslint-disable-next-line react/prop-types
|
26
|
+
function RecursiveWrapper({
|
27
|
+
children,
|
28
|
+
...rest
|
29
|
+
}) {
|
30
|
+
const wrappedChildren = Children.map(children, child => {
|
31
|
+
if (typeof child === 'string') {
|
32
|
+
return /*#__PURE__*/_jsx(CompactText, {
|
33
|
+
...rest,
|
34
|
+
children: child
|
35
|
+
});
|
36
|
+
}
|
37
|
+
if (child.props && child.props.children) {
|
38
|
+
return /*#__PURE__*/_jsx(child.type, {
|
39
|
+
...child.props,
|
40
|
+
children: /*#__PURE__*/_jsx(RecursiveWrapper, {
|
41
|
+
...rest,
|
42
|
+
children: child.props.children
|
43
|
+
})
|
44
|
+
});
|
45
|
+
}
|
46
|
+
return child;
|
47
|
+
});
|
48
|
+
return wrappedChildren;
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* 紧凑文本组件 (显示首尾, 中间截断显示省略号), 仅考虑等宽字体的情况
|
53
|
+
*/
|
54
|
+
export default function CompactText({
|
55
|
+
startChars,
|
56
|
+
endChars,
|
57
|
+
children,
|
58
|
+
showCopyButtonInTooltip
|
59
|
+
}) {
|
60
|
+
if (typeof children !== 'string') {
|
61
|
+
return /*#__PURE__*/_jsx(RecursiveWrapper, {
|
62
|
+
startChars: startChars,
|
63
|
+
endChars: endChars,
|
64
|
+
showCopyButtonInTooltip: showCopyButtonInTooltip,
|
65
|
+
children: children
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
// stopPropagation: 当 tooltip 处于 link 中时, 避免点击复制时触发链接跳转
|
70
|
+
const tooltipContent = /*#__PURE__*/_jsxs(Box, {
|
71
|
+
display: "flex",
|
72
|
+
alignItems: "center",
|
73
|
+
lineHeight: 1,
|
74
|
+
onClick: e => e.stopPropagation(),
|
75
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
76
|
+
children: children
|
77
|
+
}), showCopyButtonInTooltip && /*#__PURE__*/_jsx(CopyButton, {
|
78
|
+
content: children,
|
79
|
+
showTooltip: false,
|
80
|
+
style: {
|
81
|
+
fontSize: 16,
|
82
|
+
marginLeft: 4
|
83
|
+
}
|
84
|
+
})]
|
85
|
+
});
|
86
|
+
return /*#__PURE__*/_jsx(StyledTooltip, {
|
87
|
+
title: tooltipContent,
|
88
|
+
placement: "top",
|
89
|
+
children: /*#__PURE__*/_jsxs("span", {
|
90
|
+
children: [children.slice(0, startChars), "...", children.slice(children.length - endChars)]
|
91
|
+
})
|
92
|
+
});
|
93
|
+
}
|
94
|
+
CompactText.propTypes = {
|
95
|
+
startChars: PropTypes.number,
|
96
|
+
endChars: PropTypes.number,
|
97
|
+
children: PropTypes.node.isRequired,
|
98
|
+
// 在 tooltip 中完整地址后显示复制按钮
|
99
|
+
showCopyButtonInTooltip: PropTypes.bool
|
100
|
+
};
|
101
|
+
CompactText.defaultProps = {
|
102
|
+
startChars: 6,
|
103
|
+
endChars: 6,
|
104
|
+
showCopyButtonInTooltip: false
|
105
|
+
};
|
@@ -0,0 +1,211 @@
|
|
1
|
+
import React, { useRef, useState, forwardRef } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import '@fontsource/ubuntu-mono/400.css';
|
4
|
+
import useMountedState from 'react-use/lib/useMountedState';
|
5
|
+
import Tooltip from '@mui/material/Tooltip';
|
6
|
+
import { green } from '@mui/material/colors';
|
7
|
+
import copy from 'copy-to-clipboard';
|
8
|
+
import CopyIcon from '@mui/icons-material/ContentCopy';
|
9
|
+
import CheckIcon from '@mui/icons-material/Check';
|
10
|
+
import { styled } from '../Theme';
|
11
|
+
import { getFontSize } from '../Util';
|
12
|
+
import CompactText from './compact-text';
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
14
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
15
|
+
const translations = {
|
16
|
+
en: {
|
17
|
+
copy: 'Click To Copy',
|
18
|
+
copied: 'Copied!'
|
19
|
+
},
|
20
|
+
zh: {
|
21
|
+
copy: '点击复制',
|
22
|
+
copied: '已复制!'
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
/**
|
27
|
+
* DidAddress 组件 (新版设计)
|
28
|
+
*
|
29
|
+
* - 样式调整
|
30
|
+
* - click-to-copy 调整
|
31
|
+
* - 长文本截断处理 (Ellipsis)
|
32
|
+
* - 支持 inline 或 block 的显示方式
|
33
|
+
* - 支持紧凑模式, 该模式下:
|
34
|
+
* - 占用宽度较小, 因此不考虑水平空间不够用的情况, 且忽略末尾省略号
|
35
|
+
* - 对于多层元素结构的 children, 保持元素结构, 将最内层 text 替换为 CompactText 组件
|
36
|
+
* - 为保证 copy 功能正常工作, 原 children 始终渲染, 但在紧凑式下会隐藏
|
37
|
+
* - 可配合 useMediaQuery 使用
|
38
|
+
*/
|
39
|
+
const DidAddress = /*#__PURE__*/forwardRef(({
|
40
|
+
component,
|
41
|
+
size,
|
42
|
+
copyable,
|
43
|
+
content,
|
44
|
+
children,
|
45
|
+
prepend,
|
46
|
+
append,
|
47
|
+
compact,
|
48
|
+
startChars,
|
49
|
+
endChars,
|
50
|
+
locale,
|
51
|
+
showCopyButtonInTooltip,
|
52
|
+
...rest
|
53
|
+
}, ref) => {
|
54
|
+
if (!translations[locale]) {
|
55
|
+
// eslint-disable-next-line no-param-reassign
|
56
|
+
locale = 'en';
|
57
|
+
}
|
58
|
+
|
59
|
+
// 避免 unmounted 后 setTimeout handler 依然改变 state
|
60
|
+
const isMounted = useMountedState();
|
61
|
+
const [copied, setCopied] = useState(false);
|
62
|
+
const textRef = useRef();
|
63
|
+
const onCopy = e => {
|
64
|
+
e.stopPropagation();
|
65
|
+
e.preventDefault();
|
66
|
+
copy(content || textRef.current.textContent);
|
67
|
+
setCopied(true);
|
68
|
+
// 恢复 copied 状态
|
69
|
+
setTimeout(() => {
|
70
|
+
if (isMounted()) {
|
71
|
+
setCopied(false);
|
72
|
+
}
|
73
|
+
}, 1500);
|
74
|
+
};
|
75
|
+
let copyElement = null;
|
76
|
+
if (copyable) {
|
77
|
+
copyElement = /*#__PURE__*/_jsx("span", {
|
78
|
+
className: "did-address-copy-wrapper",
|
79
|
+
title: copied ? '' : translations[locale].copy,
|
80
|
+
children: copied ? /*#__PURE__*/_jsx(Tooltip, {
|
81
|
+
title: translations[locale].copied,
|
82
|
+
placement: "bottom",
|
83
|
+
arrow: true,
|
84
|
+
open: copied,
|
85
|
+
children: /*#__PURE__*/_jsx(CheckIcon, {
|
86
|
+
className: "did-address-copy",
|
87
|
+
style: {
|
88
|
+
color: green[500]
|
89
|
+
}
|
90
|
+
})
|
91
|
+
}) :
|
92
|
+
/*#__PURE__*/
|
93
|
+
/* title prop 直接加在 icon 上不生效 */
|
94
|
+
_jsx(CopyIcon, {
|
95
|
+
className: "did-address-copy",
|
96
|
+
onClick: onCopy
|
97
|
+
})
|
98
|
+
});
|
99
|
+
}
|
100
|
+
return /*#__PURE__*/_jsxs(Root, {
|
101
|
+
as: component,
|
102
|
+
size: size,
|
103
|
+
...rest,
|
104
|
+
ref: ref,
|
105
|
+
children: [prepend, /*#__PURE__*/_jsx("span", {
|
106
|
+
ref: textRef,
|
107
|
+
className: "did-address-text did-address-truncate",
|
108
|
+
style: {
|
109
|
+
display: compact ? 'none' : 'inline'
|
110
|
+
},
|
111
|
+
children: children
|
112
|
+
}), compact && /*#__PURE__*/_jsx("span", {
|
113
|
+
className: "did-address-text",
|
114
|
+
children: /*#__PURE__*/_jsx(CompactText, {
|
115
|
+
startChars: startChars,
|
116
|
+
endChars: endChars,
|
117
|
+
showCopyButtonInTooltip: showCopyButtonInTooltip,
|
118
|
+
children: children
|
119
|
+
})
|
120
|
+
}), copyElement, append]
|
121
|
+
});
|
122
|
+
});
|
123
|
+
export default DidAddress;
|
124
|
+
DidAddress.propTypes = {
|
125
|
+
component: PropTypes.string,
|
126
|
+
size: PropTypes.number,
|
127
|
+
copyable: PropTypes.bool,
|
128
|
+
// compact mode 下, hover 时会在 tooltip 中显示完整地址, showCopyButtonInTooltip = true 时会在完整地址后显示一个复制按钮
|
129
|
+
showCopyButtonInTooltip: PropTypes.bool,
|
130
|
+
children: PropTypes.any,
|
131
|
+
content: PropTypes.string,
|
132
|
+
inline: PropTypes.bool,
|
133
|
+
prepend: PropTypes.any,
|
134
|
+
append: PropTypes.any,
|
135
|
+
// 紧凑模式
|
136
|
+
compact: PropTypes.bool,
|
137
|
+
startChars: PropTypes.number,
|
138
|
+
endChars: PropTypes.number,
|
139
|
+
locale: PropTypes.oneOf(['en', 'zh'])
|
140
|
+
};
|
141
|
+
DidAddress.defaultProps = {
|
142
|
+
component: 'span',
|
143
|
+
size: 0,
|
144
|
+
copyable: true,
|
145
|
+
showCopyButtonInTooltip: false,
|
146
|
+
children: null,
|
147
|
+
content: '',
|
148
|
+
inline: false,
|
149
|
+
prepend: null,
|
150
|
+
append: null,
|
151
|
+
compact: false,
|
152
|
+
startChars: 6,
|
153
|
+
endChars: 6,
|
154
|
+
locale: 'en'
|
155
|
+
};
|
156
|
+
const Root = styled('div', {
|
157
|
+
shouldForwardProp: prop => prop !== 'inline'
|
158
|
+
})`
|
159
|
+
font-family: 'Ubuntu Mono', monospace;
|
160
|
+
&& {
|
161
|
+
display: ${({
|
162
|
+
inline
|
163
|
+
}) => inline ? 'inline-flex' : 'flex'};
|
164
|
+
align-items: center;
|
165
|
+
max-width: 100%;
|
166
|
+
overflow: hidden;
|
167
|
+
color: #ccc;
|
168
|
+
font-size: ${props => getFontSize(props.size)};
|
169
|
+
font-weight: 400;
|
170
|
+
|
171
|
+
svg {
|
172
|
+
fill: currentColor;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
.did-address-text {
|
177
|
+
color: #666;
|
178
|
+
}
|
179
|
+
/* truncate string with ellipsis */
|
180
|
+
.did-address-truncate {
|
181
|
+
white-space: nowrap;
|
182
|
+
overflow: hidden;
|
183
|
+
text-overflow: ellipsis;
|
184
|
+
}
|
185
|
+
|
186
|
+
.did-address-copy {
|
187
|
+
flex: 0 0 auto;
|
188
|
+
}
|
189
|
+
.did-address-copy-wrapper {
|
190
|
+
display: flex;
|
191
|
+
justify-content: center;
|
192
|
+
align-items: center;
|
193
|
+
width: 1em;
|
194
|
+
height: 1em;
|
195
|
+
margin-left: 8px;
|
196
|
+
}
|
197
|
+
.did-address-copy {
|
198
|
+
font-size: 1em;
|
199
|
+
color: #999;
|
200
|
+
cursor: pointer;
|
201
|
+
}
|
202
|
+
|
203
|
+
/* link */
|
204
|
+
a {
|
205
|
+
color: #666;
|
206
|
+
}
|
207
|
+
&:hover a {
|
208
|
+
color: #222;
|
209
|
+
text-decoration: underline;
|
210
|
+
}
|
211
|
+
`;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
import DidAddress from './did-address';
|
3
|
+
import ResponsiveDidAddress from './responsive-did-address';
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
5
|
+
export default function DidAddressWrapper({
|
6
|
+
responsive,
|
7
|
+
...rest
|
8
|
+
}) {
|
9
|
+
if (responsive) {
|
10
|
+
return /*#__PURE__*/_jsx(ResponsiveDidAddress, {
|
11
|
+
...rest
|
12
|
+
});
|
13
|
+
}
|
14
|
+
return /*#__PURE__*/_jsx(DidAddress, {
|
15
|
+
...rest
|
16
|
+
});
|
17
|
+
}
|
18
|
+
DidAddressWrapper.propTypes = {
|
19
|
+
responsive: PropTypes.bool
|
20
|
+
};
|
21
|
+
DidAddressWrapper.defaultProps = {
|
22
|
+
responsive: true
|
23
|
+
};
|