@arcblock/ux 3.4.15 → 3.5.1
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/package.json.js +1 -1
- package/package.json +10 -7
- package/src/ActionButton/ActionButton.stories.jsx +0 -61
- package/src/ActionButton/index.jsx +0 -106
- package/src/ActivityIndicator/ActivityIndicator.stories.jsx +0 -9
- package/src/ActivityIndicator/index.jsx +0 -140
- package/src/Address/Address.stories.jsx +0 -38
- package/src/Address/compact-text.jsx +0 -76
- package/src/Address/did-address.tsx +0 -223
- package/src/Address/index.tsx +0 -21
- package/src/Address/responsive-did-address.tsx +0 -154
- package/src/Alert/Alert.stories.jsx +0 -100
- package/src/Alert/index.jsx +0 -130
- package/src/AnimationWaiter/AnimationWaiter.stories.jsx +0 -35
- package/src/AnimationWaiter/dark-animation.json +0 -1
- package/src/AnimationWaiter/default-animation.json +0 -1
- package/src/AnimationWaiter/index.jsx +0 -296
- package/src/Async/index.tsx +0 -44
- package/src/Avatar/Avatar.stories.jsx +0 -11
- package/src/Avatar/did-motif.jsx +0 -38
- package/src/Avatar/etherscan-blockies.js +0 -81
- package/src/Avatar/index.jsx +0 -195
- package/src/Badge/Badge.stories.jsx +0 -41
- package/src/Badge/index.jsx +0 -101
- package/src/Blocklet/Blocklet.stories.jsx +0 -21
- package/src/Blocklet/blocklet.jsx +0 -276
- package/src/Blocklet/index.js +0 -5
- package/src/Blocklet/utils.jsx +0 -58
- package/src/BlockletContext/index.tsx +0 -72
- package/src/BlockletNFT/BlockletNFT.stories.jsx +0 -21
- package/src/BlockletNFT/index.jsx +0 -378
- package/src/BlockletV2/Blocklet.stories.jsx +0 -34
- package/src/BlockletV2/blocklet.tsx +0 -247
- package/src/BlockletV2/components/icon-text.tsx +0 -47
- package/src/BlockletV2/components/tooltip-icon.tsx +0 -52
- package/src/BlockletV2/index.ts +0 -6
- package/src/BlockletV2/utils.js +0 -75
- package/src/Button/Button.stories.jsx +0 -24
- package/src/Button/index.js +0 -9
- package/src/Button/wrap.jsx +0 -126
- package/src/ButtonGroup/index.js +0 -16
- package/src/CardSelector/index.tsx +0 -136
- package/src/Center/Center.stories.jsx +0 -20
- package/src/Center/index.tsx +0 -33
- package/src/ClickToCopy/ClickToCopy.stories.jsx +0 -24
- package/src/ClickToCopy/copy-button.tsx +0 -43
- package/src/ClickToCopy/hook.ts +0 -42
- package/src/ClickToCopy/index.tsx +0 -96
- package/src/CloseButton/index.tsx +0 -37
- package/src/CodeBlock/CodeBlock.stories.jsx +0 -22
- package/src/CodeBlock/LightBox.tsx +0 -87
- package/src/CodeBlock/index.tsx +0 -217
- package/src/Colors/Colors.stories.jsx +0 -211
- package/src/Colors/index.ts +0 -4
- package/src/Colors/themes/default.ts +0 -8
- package/src/Colors/themes/did-connect.ts +0 -64
- package/src/Colors/themes/temp.ts +0 -52
- package/src/Config/Config.stories.jsx +0 -16
- package/src/Config/config-provider.tsx +0 -62
- package/src/Config/index.ts +0 -2
- package/src/Config/theme-mode-toggle.tsx +0 -38
- package/src/ContactForm/ContactForm.stories.jsx +0 -32
- package/src/ContactForm/index.tsx +0 -264
- package/src/CookieConsent/CookieConsent.stories.jsx +0 -33
- package/src/CookieConsent/index.tsx +0 -104
- package/src/CountDown/CountDown.stories.jsx +0 -15
- package/src/CountDown/index.tsx +0 -170
- package/src/DID/DID.stories.jsx +0 -37
- package/src/DID/index.tsx +0 -393
- package/src/DIDConnect/app-icon.tsx +0 -37
- package/src/DIDConnect/app-info-item.tsx +0 -93
- package/src/DIDConnect/auth-apps/auth-apps-info.tsx +0 -77
- package/src/DIDConnect/auth-apps/index.tsx +0 -278
- package/src/DIDConnect/auth-apps/switch-role.tsx +0 -47
- package/src/DIDConnect/did-connect-container.tsx +0 -326
- package/src/DIDConnect/did-connect-footer.tsx +0 -76
- package/src/DIDConnect/did-connect-logo.tsx +0 -8
- package/src/DIDConnect/icons/did-wallet-logo.tsx +0 -18
- package/src/DIDConnect/icons/github-logo.tsx +0 -17
- package/src/DIDConnect/index.ts +0 -11
- package/src/DIDConnect/landing-page.tsx +0 -218
- package/src/DIDConnect/powered-by.tsx +0 -48
- package/src/DIDConnect/provider-icon.tsx +0 -62
- package/src/DIDConnect/request-storage-access-api-dialog.tsx +0 -304
- package/src/DIDConnect/with-container.tsx +0 -323
- package/src/DIDConnect/with-ux-theme.tsx +0 -22
- package/src/DIDLogo/Logo.stories.jsx +0 -11
- package/src/DIDLogo/index.tsx +0 -168
- package/src/Datatable/CustomToolbar.jsx +0 -415
- package/src/Datatable/Datatable.stories.jsx +0 -92
- package/src/Datatable/DatatableContext.jsx +0 -35
- package/src/Datatable/TableSearch.jsx +0 -166
- package/src/Datatable/index.jsx +0 -652
- package/src/Datatable/utils.js +0 -161
- package/src/Dialog/Dialog.stories.jsx +0 -21
- package/src/Dialog/confirm.jsx +0 -143
- package/src/Dialog/dialog.jsx +0 -199
- package/src/Dialog/index.js +0 -4
- package/src/Dialog/types.d.ts +0 -20
- package/src/Dialog/use-confirm.jsx +0 -188
- package/src/DriftBot/index.tsx +0 -81
- package/src/Earth/Earth.stories.jsx +0 -39
- package/src/Earth/countries.json +0 -8057
- package/src/Earth/index.tsx +0 -515
- package/src/Earth/util.ts +0 -72
- package/src/Empty/Empty.stories.jsx +0 -23
- package/src/Empty/index.jsx +0 -48
- package/src/ErrorBoundary/ErrorBoundary.stories.jsx +0 -13
- package/src/ErrorBoundary/fallback.tsx +0 -85
- package/src/ErrorBoundary/index.ts +0 -1
- package/src/Footer/Footer.stories.jsx +0 -13
- package/src/Footer/index.tsx +0 -130
- package/src/Header/Header.stories.jsx +0 -30
- package/src/Header/addon-button.tsx +0 -41
- package/src/Header/auto-hidden.tsx +0 -31
- package/src/Header/header-addons.tsx +0 -37
- package/src/Header/header.tsx +0 -214
- package/src/Header/index.ts +0 -3
- package/src/Header/responsive-header.tsx +0 -145
- package/src/Icon/Icon.stories.jsx +0 -45
- package/src/Icon/image.tsx +0 -53
- package/src/Icon/index.tsx +0 -63
- package/src/Img/Img.stories.jsx +0 -17
- package/src/Img/index.jsx +0 -258
- package/src/InfoRow/InfoRow.stories.jsx +0 -14
- package/src/InfoRow/index.tsx +0 -91
- package/src/Layout/Layout.stories.jsx +0 -24
- package/src/Layout/dashboard/external-link.tsx +0 -59
- package/src/Layout/dashboard/full-page.tsx +0 -58
- package/src/Layout/dashboard/index.tsx +0 -260
- package/src/Layout/dashboard/sidebar.tsx +0 -198
- package/src/Layout/dashboard-legacy/header.tsx +0 -156
- package/src/Layout/dashboard-legacy/index.tsx +0 -127
- package/src/Layout/dashboard-legacy/sidebar.tsx +0 -129
- package/src/Layout/index.tsx +0 -310
- package/src/LoadingMask/index.tsx +0 -108
- package/src/Locale/LocaleSelector.stories.jsx +0 -44
- package/src/Locale/browser-lang.ts +0 -65
- package/src/Locale/context.tsx +0 -162
- package/src/Locale/languages.ts +0 -58
- package/src/Locale/selector.tsx +0 -174
- package/src/Locale/util.ts +0 -38
- package/src/Logo/Logo.stories.jsx +0 -23
- package/src/Logo/images/logo-dark-text.svg +0 -3
- package/src/Logo/images/logo-dark-top.svg +0 -6
- package/src/Logo/images/logo-light-text.svg +0 -3
- package/src/Logo/images/logo-light-top.svg +0 -6
- package/src/Logo/index.tsx +0 -58
- package/src/Metric/Metric.stories.jsx +0 -29
- package/src/Metric/index.tsx +0 -130
- package/src/MuiWrap/index.tsx +0 -10
- package/src/NFTDisplay/NFTBroken.svg +0 -34
- package/src/NFTDisplay/NFTDisplay.stories.jsx +0 -30
- package/src/NFTDisplay/README.md +0 -59
- package/src/NFTDisplay/aspect-ratio-container.tsx +0 -36
- package/src/NFTDisplay/broken.tsx +0 -51
- package/src/NFTDisplay/displayApi.ts +0 -43
- package/src/NFTDisplay/index.tsx +0 -393
- package/src/NFTDisplay/loading.tsx +0 -16
- package/src/NFTDisplay/preview.tsx +0 -84
- package/src/NFTDisplay/render-svg.tsx +0 -21
- package/src/NFTDisplay/svg-embedder/img.tsx +0 -27
- package/src/NFTDisplay/svg-embedder/inline-svg.tsx +0 -36
- package/src/NavMenu/NavMenu.stories.jsx +0 -17
- package/src/NavMenu/images/OCAP.svg +0 -1
- package/src/NavMenu/images/abt-network.svg +0 -1
- package/src/NavMenu/images/ai-kit.svg +0 -1
- package/src/NavMenu/images/aigne-image-smith.svg +0 -1
- package/src/NavMenu/images/aigne.svg +0 -1
- package/src/NavMenu/images/aistro.png +0 -0
- package/src/NavMenu/images/arcsphere.svg +0 -1
- package/src/NavMenu/images/blocklet-framework.svg +0 -1
- package/src/NavMenu/images/blocklet-launcher.svg +0 -1
- package/src/NavMenu/images/blocklet-server.svg +0 -1
- package/src/NavMenu/images/blocklet-store.svg +0 -1
- package/src/NavMenu/images/creator-studio.svg +0 -1
- package/src/NavMenu/images/did-wallet.svg +0 -1
- package/src/NavMenu/images/did.svg +0 -1
- package/src/NavMenu/images/nft-studio.svg +0 -1
- package/src/NavMenu/images/payment-kit.png +0 -0
- package/src/NavMenu/images/vc.svg +0 -1
- package/src/NavMenu/images/web3-kit.svg +0 -1
- package/src/NavMenu/index.ts +0 -3
- package/src/NavMenu/nav-menu-context.tsx +0 -30
- package/src/NavMenu/nav-menu.tsx +0 -441
- package/src/NavMenu/products.tsx +0 -830
- package/src/NavMenu/style.ts +0 -258
- package/src/NavMenu/sub-container.tsx +0 -125
- package/src/NavMenu/sub-item-group.tsx +0 -42
- package/src/OrgTransfer/index.tsx +0 -53
- package/src/OrgTransfer/locales.ts +0 -25
- package/src/OrgTransfer/selector.tsx +0 -252
- package/src/OrgTransfer/type.ts +0 -31
- package/src/PageScroller/index.tsx +0 -316
- package/src/PageScroller/story/FifthComponent.jsx +0 -7
- package/src/PageScroller/story/FirstComponent.jsx +0 -7
- package/src/PageScroller/story/FourthComponent.jsx +0 -7
- package/src/PageScroller/story/FullPage.jsx +0 -55
- package/src/PageScroller/story/PageContain.jsx +0 -59
- package/src/PageScroller/story/PageScroller.stories.jsx +0 -18
- package/src/PageScroller/story/SecondComponent.jsx +0 -7
- package/src/PageScroller/story/ThirdComponent.jsx +0 -7
- package/src/PageScroller/story/index.css +0 -115
- package/src/PageScroller/usePrevValue.ts +0 -11
- package/src/Passport/index.ts +0 -3
- package/src/Passport/passport.tsx +0 -118
- package/src/PhoneInput/PhoneInput.stories.jsx +0 -12
- package/src/PhoneInput/country-select.tsx +0 -148
- package/src/PhoneInput/index.tsx +0 -269
- package/src/PoweredByArcBlock/index.tsx +0 -27
- package/src/PricingTable/PricingPlan.tsx +0 -120
- package/src/PricingTable/PricingTable.stories.jsx +0 -38
- package/src/PricingTable/index.tsx +0 -59
- package/src/QRCode/QRCode.stories.jsx +0 -13
- package/src/QRCode/index.tsx +0 -66
- package/src/RelativeTime/RelativeTime.stories.jsx +0 -20
- package/src/RelativeTime/index.tsx +0 -334
- package/src/Result/Result.stories.jsx +0 -61
- package/src/Result/common.tsx +0 -119
- package/src/Result/index.tsx +0 -30
- package/src/Result/result.tsx +0 -65
- package/src/Result/translations.ts +0 -57
- package/src/Screenshot/BaseScreenshot/index.tsx +0 -73
- package/src/Screenshot/BaseScreenshot/shells/Macbook.tsx +0 -38
- package/src/Screenshot/BaseScreenshot/shells/Phone.tsx +0 -35
- package/src/Screenshot/Screenshot.stories.jsx +0 -44
- package/src/Screenshot/devices.css +0 -1366
- package/src/Screenshot/index.tsx +0 -300
- package/src/SessionBlocklet/index.tsx +0 -178
- package/src/SessionManager/SessionManager.stories.jsx +0 -9
- package/src/SessionManager/index.tsx +0 -3
- package/src/SessionPermission/index.tsx +0 -26
- package/src/SessionUser/components/did-space.tsx +0 -68
- package/src/SessionUser/components/logged-in.tsx +0 -338
- package/src/SessionUser/components/quick-login-item.tsx +0 -132
- package/src/SessionUser/components/session-user-item.tsx +0 -93
- package/src/SessionUser/components/session-user-switch.tsx +0 -240
- package/src/SessionUser/components/un-login.tsx +0 -257
- package/src/SessionUser/components/user-info.tsx +0 -201
- package/src/SessionUser/index.tsx +0 -68
- package/src/SessionUser/libs/translation.ts +0 -30
- package/src/SessionUser/libs/utils.ts +0 -39
- package/src/SharedBridge/index.tsx +0 -126
- package/src/SocialShare/index.tsx +0 -194
- package/src/Sparkline/Sparkline.stories.jsx +0 -13
- package/src/Sparkline/index.tsx +0 -231
- package/src/Spinner/Spinner.stories.jsx +0 -98
- package/src/Spinner/index.tsx +0 -20
- package/src/SplitButton/SplitButton.stories.jsx +0 -32
- package/src/SplitButton/index.tsx +0 -116
- package/src/SplitButton/useClickAway.tsx +0 -24
- package/src/Success/index.tsx +0 -175
- package/src/Switch/Switch.stories.jsx +0 -16
- package/src/Switch/index.jsx +0 -79
- package/src/Tabs/Tabs.stories.jsx +0 -18
- package/src/Tabs/index.tsx +0 -255
- package/src/Tag/Tag.stories.jsx +0 -15
- package/src/Tag/index.jsx +0 -106
- package/src/TextCollapse/TextCollapse.stories.jsx +0 -73
- package/src/TextCollapse/index.tsx +0 -85
- package/src/Theme/Theme.stories.jsx +0 -11
- package/src/Theme/index.ts +0 -21
- package/src/Theme/theme-provider.tsx +0 -374
- package/src/Theme/theme.ts +0 -229
- package/src/Toast/Toast.stories.jsx +0 -28
- package/src/Toast/index.tsx +0 -80
- package/src/Typography/index.tsx +0 -124
- package/src/UserCard/Cards/avatar-only.tsx +0 -27
- package/src/UserCard/Cards/basic-info.tsx +0 -43
- package/src/UserCard/Cards/index.tsx +0 -16
- package/src/UserCard/Cards/social-actions.tsx +0 -196
- package/src/UserCard/Container/card.tsx +0 -63
- package/src/UserCard/Container/dialog.tsx +0 -37
- package/src/UserCard/Content/basic.tsx +0 -330
- package/src/UserCard/Content/clock.tsx +0 -82
- package/src/UserCard/Content/minimal.tsx +0 -113
- package/src/UserCard/Content/shorten-label.tsx +0 -32
- package/src/UserCard/Content/tooltip-avatar.tsx +0 -80
- package/src/UserCard/UserCard.stories.jsx +0 -19
- package/src/UserCard/components.tsx +0 -81
- package/src/UserCard/index.tsx +0 -132
- package/src/UserCard/types.ts +0 -165
- package/src/UserCard/use-follow.tsx +0 -111
- package/src/UserCard/utils.ts +0 -155
- package/src/Util/WebWalletOpener.stories.jsx +0 -5
- package/src/Util/client.ts +0 -4
- package/src/Util/constant.ts +0 -70
- package/src/Util/deprecate.tsx +0 -29
- package/src/Util/federated.ts +0 -125
- package/src/Util/iframe.ts +0 -19
- package/src/Util/index.ts +0 -760
- package/src/Util/logger.ts +0 -44
- package/src/Util/passport.ts +0 -127
- package/src/Util/security.ts +0 -72
- package/src/Util/style.ts +0 -17
- package/src/Util/wallet.ts +0 -35
- package/src/VerificationCode/index.tsx +0 -83
- package/src/Video/Video.stories.jsx +0 -6
- package/src/Video/index.tsx +0 -70
- package/src/Wallet/Action.stories.jsx +0 -8
- package/src/Wallet/Action.tsx +0 -118
- package/src/Wallet/Download.stories.jsx +0 -9
- package/src/Wallet/Download.tsx +0 -157
- package/src/Wallet/Open.tsx +0 -47
- package/src/Wallet/OpenInWallet.stories.jsx +0 -5
- package/src/Wallet/images/abtwallet.png +0 -0
- package/src/Wallet/images/android_download.svg +0 -22
- package/src/Wallet/images/app-store.svg +0 -30
- package/src/Wallet/images/google-play.svg +0 -69
- package/src/WalletOSIcon/index.tsx +0 -47
- package/src/WebWalletSWKeeper/index.tsx +0 -117
- package/src/WechatPrompt/images/android.png +0 -0
- package/src/WechatPrompt/images/ios.png +0 -0
- package/src/WechatPrompt/index.tsx +0 -75
- package/src/global.d.ts +0 -28
- package/src/hooks/use-blocklet-logo.tsx +0 -32
- package/src/hooks/use-clock.tsx +0 -62
- package/src/hooks/use-location-state.tsx +0 -117
- package/src/hooks/use-mobile.tsx +0 -6
- package/src/index.ts +0 -79
- package/src/type.d.ts +0 -44
- package/src/withTheme/index.tsx +0 -72
- package/src/withTracker/README.md +0 -37
- package/src/withTracker/action/bind-wallet.tsx +0 -17
- package/src/withTracker/action/login.tsx +0 -18
- package/src/withTracker/action/pay.tsx +0 -14
- package/src/withTracker/action/switch-passport.tsx +0 -20
- package/src/withTracker/constant/index.tsx +0 -3
- package/src/withTracker/env.tsx +0 -1
- package/src/withTracker/error_boundary.jsx +0 -34
- package/src/withTracker/index.tsx +0 -50
- package/src/withTracker/libs/utm.ts +0 -46
- package/vite.config.mjs +0 -37
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { lazy, Suspense, useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { Skeleton } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import noop from 'lodash/noop';
|
|
6
|
-
|
|
7
|
-
import { styled, useTheme } from '../Theme';
|
|
8
|
-
|
|
9
|
-
const Lottie = lazy(() => import('react-lottie-player'));
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 用于长时间等待的用的动画组件
|
|
13
|
-
* 动画会随着时间的变化而逐步加快播放速度,好适应用户的等待心理
|
|
14
|
-
* @param {object} props - 组件属性
|
|
15
|
-
* @param {object} [props.animationData] - lottie json 动画数据
|
|
16
|
-
* @param {number|string} [props.size] - 动画的尺寸,单位px
|
|
17
|
-
* @param {string|React.ReactNode[]} [props.message] - 动画下方的文字;数组情况下会在一定时间切换文案
|
|
18
|
-
* @param {number} [props.messageDuration=5000] - 动画下方的文字为数组时,每个文案的持续时间(毫秒)
|
|
19
|
-
* @param {boolean} [props.messageLoop=true] - 动画下方的文字为数组时,文案是否循环播放
|
|
20
|
-
* @param {React.ReactNode[]} [props.tips=[]] - 底部的提示元素
|
|
21
|
-
* @param {number} [props.tipsDuration=5000] - 底部提示的切换时间(毫秒)
|
|
22
|
-
* @param {number} [props.speed=1] - 动画默认的播放速度
|
|
23
|
-
* @param {number} [props.maybeDuration=120000] - 整个动画大概的持续时间(毫秒),用于计算增量下的动画速度
|
|
24
|
-
* @param {number} [props.increaseSpeed=0] - 在 maybeDuration 时间下增加的速度
|
|
25
|
-
* @returns {JSX.Element}
|
|
26
|
-
*/
|
|
27
|
-
export default function AnimationWaiter({
|
|
28
|
-
animationData = null,
|
|
29
|
-
size = 256,
|
|
30
|
-
message = '',
|
|
31
|
-
messageDuration = 5000,
|
|
32
|
-
messageLoop = true,
|
|
33
|
-
tips = [],
|
|
34
|
-
tipsDuration = 5000,
|
|
35
|
-
maybeDuration = 120000,
|
|
36
|
-
speed = 1,
|
|
37
|
-
increaseSpeed = 0,
|
|
38
|
-
...rest
|
|
39
|
-
}) {
|
|
40
|
-
const theme = useTheme();
|
|
41
|
-
const [tipsId, setTipsId] = useState(0);
|
|
42
|
-
const [currentSpeed, setCurrentSpeed] = useState(speed);
|
|
43
|
-
const [messageId, setMessageId] = useState(0);
|
|
44
|
-
const [defaultAnimation, setDefaultAnimation] = useState(null);
|
|
45
|
-
const [isLoading, setIsLoading] = useState(!animationData);
|
|
46
|
-
// 动画的开始时间
|
|
47
|
-
const startTime = useRef(new Date().getTime());
|
|
48
|
-
|
|
49
|
-
if (!Array.isArray(message)) {
|
|
50
|
-
// eslint-disable-next-line no-param-reassign
|
|
51
|
-
message = [message];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 懒加载默认动画
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (!animationData) {
|
|
57
|
-
setIsLoading(true);
|
|
58
|
-
const loadAnimation = async () => {
|
|
59
|
-
try {
|
|
60
|
-
const module = await (theme.palette.mode === 'dark'
|
|
61
|
-
? import('./dark-animation.json')
|
|
62
|
-
: import('./default-animation.json'));
|
|
63
|
-
|
|
64
|
-
setDefaultAnimation(module.default || module);
|
|
65
|
-
|
|
66
|
-
setIsLoading(false);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error('Failed to load animation:', error);
|
|
69
|
-
setIsLoading(false);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
loadAnimation();
|
|
74
|
-
}
|
|
75
|
-
}, [animationData, theme.palette.mode]);
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!message) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let msgIndex = 0;
|
|
83
|
-
|
|
84
|
-
const timer = setInterval(() => {
|
|
85
|
-
msgIndex++;
|
|
86
|
-
if (msgIndex >= message.length) {
|
|
87
|
-
if (messageLoop) {
|
|
88
|
-
msgIndex = 0;
|
|
89
|
-
} else {
|
|
90
|
-
msgIndex = message.length - 1;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
setMessageId(msgIndex);
|
|
94
|
-
}, messageDuration);
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line consistent-return
|
|
97
|
-
return () => {
|
|
98
|
-
clearInterval(timer);
|
|
99
|
-
};
|
|
100
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
|
-
}, [message, messageDuration]);
|
|
102
|
-
|
|
103
|
-
// tips
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
if (!tips.length) {
|
|
106
|
-
return noop;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const timer = setTimeout(() => {
|
|
110
|
-
let nextId = tipsId + 1;
|
|
111
|
-
|
|
112
|
-
if (nextId >= tips.length) {
|
|
113
|
-
nextId = 0;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
setTipsId(nextId);
|
|
117
|
-
}, tipsDuration);
|
|
118
|
-
|
|
119
|
-
return () => clearTimeout(timer);
|
|
120
|
-
}, [tips, tipsDuration, tipsId]);
|
|
121
|
-
|
|
122
|
-
// 动画speed
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
const timer = setTimeout(() => {
|
|
125
|
-
const diffTime = new Date().getTime() - startTime.current;
|
|
126
|
-
|
|
127
|
-
let percentage = diffTime / maybeDuration;
|
|
128
|
-
if (percentage > 1) {
|
|
129
|
-
percentage = 1;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const newSpeed = speed + increaseSpeed * percentage;
|
|
133
|
-
|
|
134
|
-
setCurrentSpeed(newSpeed);
|
|
135
|
-
}, 1000);
|
|
136
|
-
|
|
137
|
-
return () => clearTimeout(timer);
|
|
138
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
139
|
-
}, [currentSpeed]);
|
|
140
|
-
|
|
141
|
-
const getMsgClassName = (index) => {
|
|
142
|
-
let className = 'message-before';
|
|
143
|
-
if (messageId === index) {
|
|
144
|
-
className = 'show-message';
|
|
145
|
-
} else if (messageId < index) {
|
|
146
|
-
className = 'message-after';
|
|
147
|
-
}
|
|
148
|
-
return className;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const fallback = (
|
|
152
|
-
<div style={{ width: size, height: size, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
|
153
|
-
<Skeleton variant="rounded" width={size * 0.4} height={size * 0.4} />
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<Container {...rest}>
|
|
159
|
-
{isLoading ? (
|
|
160
|
-
// 当正在加载默认动画时直接展示 fallback
|
|
161
|
-
fallback
|
|
162
|
-
) : (
|
|
163
|
-
// 否则使用 Suspense 包裹懒加载的 Lottie,Suspense 会在 Lottie 本身未加载完成时展示 fallback
|
|
164
|
-
<Suspense fallback={fallback}>
|
|
165
|
-
<Lottie
|
|
166
|
-
loop
|
|
167
|
-
animationData={animationData || defaultAnimation}
|
|
168
|
-
play
|
|
169
|
-
speed={currentSpeed}
|
|
170
|
-
style={{
|
|
171
|
-
width: size,
|
|
172
|
-
height: size,
|
|
173
|
-
}}
|
|
174
|
-
/>
|
|
175
|
-
</Suspense>
|
|
176
|
-
)}
|
|
177
|
-
|
|
178
|
-
{message && (
|
|
179
|
-
<div className="waiter-message">
|
|
180
|
-
{message.map((text, index) => {
|
|
181
|
-
const className = getMsgClassName(index);
|
|
182
|
-
return (
|
|
183
|
-
<div
|
|
184
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
185
|
-
key={index}>
|
|
186
|
-
<span className={`message-block ${className}`}>{text}</span>
|
|
187
|
-
<span className={`placeholder-message ${className}`}>{text}</span>
|
|
188
|
-
</div>
|
|
189
|
-
);
|
|
190
|
-
})}
|
|
191
|
-
</div>
|
|
192
|
-
)}
|
|
193
|
-
|
|
194
|
-
{tips.length ? (
|
|
195
|
-
<div className="waiter-tips-container">
|
|
196
|
-
{tips.map((e, index) => {
|
|
197
|
-
return (
|
|
198
|
-
<div
|
|
199
|
-
className={`waiter-tips-block ${tipsId === index ? 'show-tips' : ''}`}
|
|
200
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
201
|
-
key={index}>
|
|
202
|
-
{e}
|
|
203
|
-
</div>
|
|
204
|
-
);
|
|
205
|
-
})}
|
|
206
|
-
</div>
|
|
207
|
-
) : (
|
|
208
|
-
''
|
|
209
|
-
)}
|
|
210
|
-
</Container>
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
AnimationWaiter.propTypes = {
|
|
215
|
-
animationData: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf([null])]),
|
|
216
|
-
size: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
217
|
-
message: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.node)]),
|
|
218
|
-
messageDuration: PropTypes.number,
|
|
219
|
-
messageLoop: PropTypes.bool,
|
|
220
|
-
tips: PropTypes.arrayOf(PropTypes.node),
|
|
221
|
-
tipsDuration: PropTypes.number,
|
|
222
|
-
speed: PropTypes.number,
|
|
223
|
-
maybeDuration: PropTypes.number,
|
|
224
|
-
increaseSpeed: PropTypes.number,
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const Container = styled('div')`
|
|
228
|
-
display: flex;
|
|
229
|
-
justify-content: center;
|
|
230
|
-
align-items: center;
|
|
231
|
-
flex-direction: column;
|
|
232
|
-
width: 100%;
|
|
233
|
-
height: 100%;
|
|
234
|
-
|
|
235
|
-
.waiter-message {
|
|
236
|
-
position: relative;
|
|
237
|
-
width: 100%;
|
|
238
|
-
font-weight: 700;
|
|
239
|
-
font-size: 18px;
|
|
240
|
-
line-height: 22px;
|
|
241
|
-
text-align: center;
|
|
242
|
-
overflow: hidden;
|
|
243
|
-
.message-block {
|
|
244
|
-
position: absolute;
|
|
245
|
-
left: 0;
|
|
246
|
-
width: 100%;
|
|
247
|
-
opacity: 0;
|
|
248
|
-
transition: all ease 0.3s;
|
|
249
|
-
user-select: none;
|
|
250
|
-
&.message-before {
|
|
251
|
-
transform: translate(-20px, 0);
|
|
252
|
-
}
|
|
253
|
-
&.message-after {
|
|
254
|
-
transform: translate(20px, 0);
|
|
255
|
-
}
|
|
256
|
-
&.show-message {
|
|
257
|
-
transform: translate(0, 0);
|
|
258
|
-
opacity: 1;
|
|
259
|
-
user-select: text;
|
|
260
|
-
z-index: 2;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
.placeholder-message {
|
|
265
|
-
user-select: none;
|
|
266
|
-
display: none;
|
|
267
|
-
opacity: 0;
|
|
268
|
-
&.show-message {
|
|
269
|
-
display: block;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
.waiter-tips-container {
|
|
275
|
-
position: relative;
|
|
276
|
-
margin-top: auto;
|
|
277
|
-
width: 100%;
|
|
278
|
-
.waiter-tips-block {
|
|
279
|
-
position: absolute;
|
|
280
|
-
bottom: 0;
|
|
281
|
-
left: 0;
|
|
282
|
-
width: 100%;
|
|
283
|
-
opacity: 0;
|
|
284
|
-
pointer-events: none;
|
|
285
|
-
z-index: 1;
|
|
286
|
-
transform: translate(-20px, 0);
|
|
287
|
-
transition: all ease 0.4s;
|
|
288
|
-
&.show-tips {
|
|
289
|
-
opacity: 1;
|
|
290
|
-
pointer-events: auto;
|
|
291
|
-
z-index: 2;
|
|
292
|
-
transform: translate(0, 0);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
`;
|
package/src/Async/index.tsx
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { CircularProgress } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
export default function LoadAsyncComponent<T extends React.ComponentType<any>>(
|
|
5
|
-
importComponent: () => Promise<Record<string, T>>,
|
|
6
|
-
key = 'default',
|
|
7
|
-
showProgress = true
|
|
8
|
-
) {
|
|
9
|
-
type Props = React.ComponentProps<T>;
|
|
10
|
-
type State = {
|
|
11
|
-
Component: React.ComponentType<any> | null;
|
|
12
|
-
error: string | null;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class AsyncComponent extends React.Component<Props, State> {
|
|
16
|
-
constructor(props: Props) {
|
|
17
|
-
super(props);
|
|
18
|
-
|
|
19
|
-
this.state = {
|
|
20
|
-
Component: null,
|
|
21
|
-
error: null,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
componentDidMount() {
|
|
26
|
-
importComponent()
|
|
27
|
-
.then((asyncModule) => this.setState({ Component: asyncModule[key] }))
|
|
28
|
-
.catch((err) => this.setState({ error: `Failed to load async component: ${err.message}` }));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
render() {
|
|
32
|
-
const { Component, error } = this.state;
|
|
33
|
-
|
|
34
|
-
if (error) {
|
|
35
|
-
return error;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line no-nested-ternary
|
|
39
|
-
return Component ? <Component {...this.props} /> : showProgress ? <CircularProgress color="primary" /> : null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return AsyncComponent;
|
|
44
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { default as WithDifferentSizes } from './demo/with-different-sizes';
|
|
2
|
-
export { default as WithDifferentDid } from './demo/with-different-did';
|
|
3
|
-
export { default as WithSpecifiedMotifShape } from './demo/with-specified-motif-shape';
|
|
4
|
-
export { default as ResponsiveDidMotif } from './demo/responsive-did-motif';
|
|
5
|
-
export { default as EthAddresses } from './demo/eth-addresses';
|
|
6
|
-
export { default as WithAnimation } from './demo/with-animation';
|
|
7
|
-
export { default as WithEmptyDidErrorFallback } from './demo/with-empty-did-error-fallback';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
title: 'DID/Avatar',
|
|
11
|
-
};
|
package/src/Avatar/did-motif.jsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useRef, useLayoutEffect } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { update } from '@arcblock/did-motif';
|
|
4
|
-
import { Box } from '@mui/material';
|
|
5
|
-
|
|
6
|
-
function DIDMotif({ did, size = 200, animation = false, shape = null, responsive = false, ...rest }) {
|
|
7
|
-
const svgRef = useRef(null);
|
|
8
|
-
|
|
9
|
-
useLayoutEffect(() => {
|
|
10
|
-
update(svgRef.current, did, { size, animation, shape });
|
|
11
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12
|
-
}, [did, size, shape]);
|
|
13
|
-
if (responsive) {
|
|
14
|
-
// fix avatar 显示问题 (safari 下父容器为 flex 时 inline svg 显示不出来, 需要明确指定 width)
|
|
15
|
-
const styles = { ...rest.style, width: '100%' };
|
|
16
|
-
return <Box component="svg" ref={svgRef} {...rest} style={styles} className="arc-avatar-did-motif" />;
|
|
17
|
-
}
|
|
18
|
-
return (
|
|
19
|
-
<Box
|
|
20
|
-
component="span"
|
|
21
|
-
{...rest}
|
|
22
|
-
style={{ display: 'inline-block', width: size, height: size, ...rest.style }}
|
|
23
|
-
className="arc-avatar-did-motif">
|
|
24
|
-
<Box component="svg" ref={svgRef} style={{ width: '100%' }} />
|
|
25
|
-
</Box>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
DIDMotif.propTypes = {
|
|
30
|
-
did: PropTypes.string.isRequired,
|
|
31
|
-
size: PropTypes.number,
|
|
32
|
-
animation: PropTypes.bool,
|
|
33
|
-
// 直接返回 svg 元素, svg 尺寸由父窗口决定 (撑满父窗口)
|
|
34
|
-
responsive: PropTypes.bool,
|
|
35
|
-
shape: PropTypes.number,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export default DIDMotif;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/* eslint-disable prefer-destructuring */
|
|
2
|
-
/* eslint-disable no-bitwise */
|
|
3
|
-
// copy from https://etherscan.io/jss/blockies.js
|
|
4
|
-
const randseed = new Array(4);
|
|
5
|
-
function seedrand(seed) {
|
|
6
|
-
for (let i = 0; i < randseed.length; i++) {
|
|
7
|
-
randseed[i] = 0;
|
|
8
|
-
}
|
|
9
|
-
for (let i = 0; i < seed.length; i++) {
|
|
10
|
-
randseed[i % 4] = (randseed[i % 4] << 5) - randseed[i % 4] + seed.charCodeAt(i);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function rand() {
|
|
14
|
-
const t = randseed[0] ^ (randseed[0] << 11);
|
|
15
|
-
randseed[0] = randseed[1];
|
|
16
|
-
randseed[1] = randseed[2];
|
|
17
|
-
randseed[2] = randseed[3];
|
|
18
|
-
randseed[3] = randseed[3] ^ (randseed[3] >> 19) ^ t ^ (t >> 8);
|
|
19
|
-
return (randseed[3] >>> 0) / ((1 << 31) >>> 0);
|
|
20
|
-
}
|
|
21
|
-
function createColor() {
|
|
22
|
-
const h = Math.floor(rand() * 360);
|
|
23
|
-
const s = `${rand() * 60 + 40}%`;
|
|
24
|
-
const l = `${(rand() + rand() + rand() + rand()) * 25}%`;
|
|
25
|
-
const color = `hsl(${h},${s},${l})`;
|
|
26
|
-
return color;
|
|
27
|
-
}
|
|
28
|
-
function createImageData(size) {
|
|
29
|
-
const width = size;
|
|
30
|
-
const height = size;
|
|
31
|
-
const dataWidth = Math.ceil(width / 2);
|
|
32
|
-
const mirrorWidth = width - dataWidth;
|
|
33
|
-
const data = [];
|
|
34
|
-
for (let y = 0; y < height; y++) {
|
|
35
|
-
let row = [];
|
|
36
|
-
for (let x = 0; x < dataWidth; x++) {
|
|
37
|
-
row[x] = Math.floor(rand() * 2.3);
|
|
38
|
-
}
|
|
39
|
-
const r = row.slice(0, mirrorWidth);
|
|
40
|
-
r.reverse();
|
|
41
|
-
row = row.concat(r);
|
|
42
|
-
for (let i = 0; i < row.length; i++) {
|
|
43
|
-
data.push(row[i]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return data;
|
|
47
|
-
}
|
|
48
|
-
function createCanvas(imageData, color, scale, bgcolor, spotcolor) {
|
|
49
|
-
const c = document.createElement('canvas');
|
|
50
|
-
const width = Math.sqrt(imageData.length);
|
|
51
|
-
// eslint-disable-next-line no-multi-assign
|
|
52
|
-
c.width = c.height = width * scale;
|
|
53
|
-
const cc = c.getContext('2d');
|
|
54
|
-
cc.fillStyle = bgcolor;
|
|
55
|
-
cc.fillRect(0, 0, c.width, c.height);
|
|
56
|
-
cc.fillStyle = color;
|
|
57
|
-
for (let i = 0; i < imageData.length; i++) {
|
|
58
|
-
const row = Math.floor(i / width);
|
|
59
|
-
const col = i % width;
|
|
60
|
-
cc.fillStyle = imageData[i] === 1 ? color : spotcolor;
|
|
61
|
-
if (imageData[i]) {
|
|
62
|
-
cc.fillRect(col * scale, row * scale, scale, scale);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return c;
|
|
66
|
-
}
|
|
67
|
-
function createIcon(opts) {
|
|
68
|
-
// eslint-disable-next-line no-param-reassign
|
|
69
|
-
opts = opts || {};
|
|
70
|
-
const size = opts.size || 8;
|
|
71
|
-
const scale = opts.scale || 4;
|
|
72
|
-
const seed = opts.seed || Math.floor(Math.random() * 10 ** 16).toString(16);
|
|
73
|
-
seedrand(seed);
|
|
74
|
-
const color = opts.color || createColor();
|
|
75
|
-
const bgcolor = opts.bgcolor || createColor();
|
|
76
|
-
const spotcolor = opts.spotcolor || createColor();
|
|
77
|
-
const imageData = createImageData(size);
|
|
78
|
-
const canvas = createCanvas(imageData, color, scale, bgcolor, spotcolor);
|
|
79
|
-
return canvas;
|
|
80
|
-
}
|
|
81
|
-
export default { createIcon };
|
package/src/Avatar/index.jsx
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/no-unused-prop-types */
|
|
2
|
-
import { useState, useMemo } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { ErrorBoundary } from 'react-error-boundary';
|
|
5
|
-
import { Shape } from '@arcblock/did-motif';
|
|
6
|
-
import { Box } from '@mui/material';
|
|
7
|
-
import isUndefined from 'lodash/isUndefined';
|
|
8
|
-
|
|
9
|
-
import Img from '../Img';
|
|
10
|
-
import { mergeProps, isEthereumDid } from '../Util';
|
|
11
|
-
import DIDMotif from './did-motif';
|
|
12
|
-
import blockies from './etherscan-blockies';
|
|
13
|
-
import { DID_PREFIX } from '../Util/constant';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Avatar component
|
|
17
|
-
* @typedef {{
|
|
18
|
-
* src?: string;
|
|
19
|
-
* did?: string;
|
|
20
|
-
* size?: number;
|
|
21
|
-
* variant?: 'circle' | 'rounded' | 'default';
|
|
22
|
-
* animation?: false | true;
|
|
23
|
-
* shape?: '' | 'rectangle' | 'square' | 'hexagon' | 'circle';
|
|
24
|
-
* blockiesPadding?: true | false;
|
|
25
|
-
* responsive?: false | true;
|
|
26
|
-
* useProxyFallback?: boolean;
|
|
27
|
-
* } & Omit<import('../Img').ImgProps, 'size' | 'src'>} AvatarProps
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @see 参考: https://github.com/blocklet/block-explorer/issues/478#issuecomment-1038954976
|
|
32
|
-
* @param {AvatarProps} props
|
|
33
|
-
* @returns {JSX.Element}
|
|
34
|
-
*/
|
|
35
|
-
function Avatar({ ...rawProps }) {
|
|
36
|
-
const props = Object.assign({}, rawProps);
|
|
37
|
-
if (isUndefined(props.did)) {
|
|
38
|
-
props.did = '';
|
|
39
|
-
}
|
|
40
|
-
if (isUndefined(props.size)) {
|
|
41
|
-
props.size = 36;
|
|
42
|
-
}
|
|
43
|
-
if (isUndefined(props.variant)) {
|
|
44
|
-
props.variant = 'default';
|
|
45
|
-
}
|
|
46
|
-
if (isUndefined(props.animation)) {
|
|
47
|
-
props.animation = false;
|
|
48
|
-
}
|
|
49
|
-
if (isUndefined(props.shape)) {
|
|
50
|
-
props.shape = '';
|
|
51
|
-
}
|
|
52
|
-
if (isUndefined(props.blockiesPadding)) {
|
|
53
|
-
props.blockiesPadding = true;
|
|
54
|
-
}
|
|
55
|
-
if (isUndefined(props.responsive)) {
|
|
56
|
-
props.responsive = false;
|
|
57
|
-
}
|
|
58
|
-
const [imgError, setImgError] = useState(false);
|
|
59
|
-
/** @type {AvatarProps} */
|
|
60
|
-
const newProps = mergeProps(props, Avatar, []);
|
|
61
|
-
const { did = '', size, src, variant, animation, shape, blockiesPadding, responsive, ...rest } = newProps;
|
|
62
|
-
|
|
63
|
-
// ethereum blockies
|
|
64
|
-
const blockyIcon = useMemo(() => {
|
|
65
|
-
if (isEthereumDid(did)) {
|
|
66
|
-
return blockies
|
|
67
|
-
.createIcon({
|
|
68
|
-
seed: did.replace(DID_PREFIX, '').toLowerCase(),
|
|
69
|
-
size: 8,
|
|
70
|
-
scale: 16,
|
|
71
|
-
})
|
|
72
|
-
.toDataURL();
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}, [did]);
|
|
76
|
-
|
|
77
|
-
// 如果显式传入 src 则直接使用 src
|
|
78
|
-
if (src && !imgError) {
|
|
79
|
-
return (
|
|
80
|
-
<Img
|
|
81
|
-
width={size}
|
|
82
|
-
src={src}
|
|
83
|
-
alt={did}
|
|
84
|
-
onError={() => setImgError(true)}
|
|
85
|
-
{...rest}
|
|
86
|
-
// HACK: 这个 className 是传递给子元素的,所以下面的 sx 需要通过子元素选择器来写样式
|
|
87
|
-
className={`avatar-img--${variant} ${rest?.className || ''}`}
|
|
88
|
-
useProxyFallback
|
|
89
|
-
sx={{
|
|
90
|
-
'& .avatar-img--rounded': {
|
|
91
|
-
borderRadius: '4px',
|
|
92
|
-
overflow: 'hidden',
|
|
93
|
-
},
|
|
94
|
-
'& .avatar-img--circle': {
|
|
95
|
-
borderRadius: '100%',
|
|
96
|
-
overflow: 'hidden',
|
|
97
|
-
},
|
|
98
|
-
...rest.sx,
|
|
99
|
-
}}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
// 对于 eth address, 渲染成 blocky icon, 形状与 account role type 的 did motif 相似都为矩形, 高宽比为 0.7
|
|
104
|
-
if (blockyIcon) {
|
|
105
|
-
if (blockiesPadding) {
|
|
106
|
-
// blocky icon 要与灰色卡片矩形留有空间
|
|
107
|
-
const padding = size > 24 ? 4 : 2;
|
|
108
|
-
return (
|
|
109
|
-
<Box
|
|
110
|
-
{...rest}
|
|
111
|
-
sx={{
|
|
112
|
-
display: 'flex',
|
|
113
|
-
alignItems: 'center',
|
|
114
|
-
width: size,
|
|
115
|
-
height: size,
|
|
116
|
-
'.blocky-icon-inner': {
|
|
117
|
-
boxSizing: 'border-box',
|
|
118
|
-
display: 'flex',
|
|
119
|
-
justifyContent: 'center',
|
|
120
|
-
alignItems: 'center',
|
|
121
|
-
width: size,
|
|
122
|
-
height: size * 0.7,
|
|
123
|
-
borderRadius: `${Math.min(10, Math.floor(0.1 * size + 2))}px`,
|
|
124
|
-
background: '#ddd',
|
|
125
|
-
},
|
|
126
|
-
...rest.sx,
|
|
127
|
-
}}>
|
|
128
|
-
<div className="blocky-icon-inner">
|
|
129
|
-
<Img width={size * 0.7 - padding * 2} src={blockyIcon} alt={did} />
|
|
130
|
-
</div>
|
|
131
|
-
</Box>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return <Img {...rest} width={size} src={blockyIcon} alt={did} style={{ marginRight: 4 }} />;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (did) {
|
|
139
|
-
// 渲染 did motif
|
|
140
|
-
return (
|
|
141
|
-
<DIDMotif
|
|
142
|
-
did={did.replace(DID_PREFIX, '')}
|
|
143
|
-
size={size}
|
|
144
|
-
animation={animation}
|
|
145
|
-
shape={Shape[(shape || '').toUpperCase()]}
|
|
146
|
-
responsive={responsive}
|
|
147
|
-
{...rest}
|
|
148
|
-
/>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
throw new Error(`Invalid DID: ${did}`);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
Avatar.propTypes = {
|
|
155
|
-
did: PropTypes.string,
|
|
156
|
-
size: PropTypes.number,
|
|
157
|
-
variant: PropTypes.oneOf(['circle', 'rounded', 'default']),
|
|
158
|
-
// animation 仅对 did motif 有效
|
|
159
|
-
animation: PropTypes.bool,
|
|
160
|
-
// shape 仅对 did motif 有效, 明确指定 motif shape, 而非由 did role type 自动推断 shape
|
|
161
|
-
shape: PropTypes.oneOf(['', 'rectangle', 'square', 'hexagon', 'circle']),
|
|
162
|
-
blockiesPadding: PropTypes.bool,
|
|
163
|
-
responsive: PropTypes.bool,
|
|
164
|
-
useProxyFallback: PropTypes.bool,
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @param {AvatarProps} props
|
|
169
|
-
* @returns {JSX.Element}
|
|
170
|
-
*/
|
|
171
|
-
export default function AvatarWithErrorBoundary(props) {
|
|
172
|
-
const size = props.size || 36;
|
|
173
|
-
const borderRadius = { rounded: '4px', circle: '100%' }[props.variant] || 0;
|
|
174
|
-
return (
|
|
175
|
-
<ErrorBoundary
|
|
176
|
-
// eslint-disable-next-line react/no-unstable-nested-components
|
|
177
|
-
fallbackRender={() => (
|
|
178
|
-
<Box
|
|
179
|
-
sx={{
|
|
180
|
-
width: size,
|
|
181
|
-
height: size,
|
|
182
|
-
bgcolor: 'grey.300',
|
|
183
|
-
borderRadius,
|
|
184
|
-
}}
|
|
185
|
-
/>
|
|
186
|
-
)}>
|
|
187
|
-
<Avatar {...props} />
|
|
188
|
-
</ErrorBoundary>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
AvatarWithErrorBoundary.propTypes = Avatar.propTypes;
|
|
193
|
-
|
|
194
|
-
// Export Avatar for access to its props
|
|
195
|
-
export { Avatar as AvatarProps };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import Badge from '.';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
title: 'Deprecated/Badge',
|
|
5
|
-
|
|
6
|
-
parameters: {
|
|
7
|
-
readme: {
|
|
8
|
-
sidebar: '<!-- PROPS -->',
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function WithDifferentType() {
|
|
14
|
-
return (
|
|
15
|
-
<div
|
|
16
|
-
style={{
|
|
17
|
-
display: 'flex',
|
|
18
|
-
flexDirection: 'column',
|
|
19
|
-
width: '300px',
|
|
20
|
-
justifyContent: 'space-between',
|
|
21
|
-
}}>
|
|
22
|
-
<Badge type="error" style={{ marginBottom: 16 }}>
|
|
23
|
-
Error message
|
|
24
|
-
</Badge>
|
|
25
|
-
<Badge type="warning" style={{ marginBottom: 16 }}>
|
|
26
|
-
Warning message
|
|
27
|
-
</Badge>
|
|
28
|
-
<Badge type="success" style={{ marginBottom: 16 }}>
|
|
29
|
-
Success message
|
|
30
|
-
</Badge>
|
|
31
|
-
<Badge type="primary" style={{ marginBottom: 16 }}>
|
|
32
|
-
Default tip
|
|
33
|
-
</Badge>
|
|
34
|
-
<Badge type="reverse" style={{ marginBottom: 16 }}>
|
|
35
|
-
Reverse styling
|
|
36
|
-
</Badge>
|
|
37
|
-
</div>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
WithDifferentType.storyName = 'with different type';
|