@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.
Files changed (333) hide show
  1. package/lib/package.json.js +1 -1
  2. package/package.json +10 -7
  3. package/src/ActionButton/ActionButton.stories.jsx +0 -61
  4. package/src/ActionButton/index.jsx +0 -106
  5. package/src/ActivityIndicator/ActivityIndicator.stories.jsx +0 -9
  6. package/src/ActivityIndicator/index.jsx +0 -140
  7. package/src/Address/Address.stories.jsx +0 -38
  8. package/src/Address/compact-text.jsx +0 -76
  9. package/src/Address/did-address.tsx +0 -223
  10. package/src/Address/index.tsx +0 -21
  11. package/src/Address/responsive-did-address.tsx +0 -154
  12. package/src/Alert/Alert.stories.jsx +0 -100
  13. package/src/Alert/index.jsx +0 -130
  14. package/src/AnimationWaiter/AnimationWaiter.stories.jsx +0 -35
  15. package/src/AnimationWaiter/dark-animation.json +0 -1
  16. package/src/AnimationWaiter/default-animation.json +0 -1
  17. package/src/AnimationWaiter/index.jsx +0 -296
  18. package/src/Async/index.tsx +0 -44
  19. package/src/Avatar/Avatar.stories.jsx +0 -11
  20. package/src/Avatar/did-motif.jsx +0 -38
  21. package/src/Avatar/etherscan-blockies.js +0 -81
  22. package/src/Avatar/index.jsx +0 -195
  23. package/src/Badge/Badge.stories.jsx +0 -41
  24. package/src/Badge/index.jsx +0 -101
  25. package/src/Blocklet/Blocklet.stories.jsx +0 -21
  26. package/src/Blocklet/blocklet.jsx +0 -276
  27. package/src/Blocklet/index.js +0 -5
  28. package/src/Blocklet/utils.jsx +0 -58
  29. package/src/BlockletContext/index.tsx +0 -72
  30. package/src/BlockletNFT/BlockletNFT.stories.jsx +0 -21
  31. package/src/BlockletNFT/index.jsx +0 -378
  32. package/src/BlockletV2/Blocklet.stories.jsx +0 -34
  33. package/src/BlockletV2/blocklet.tsx +0 -247
  34. package/src/BlockletV2/components/icon-text.tsx +0 -47
  35. package/src/BlockletV2/components/tooltip-icon.tsx +0 -52
  36. package/src/BlockletV2/index.ts +0 -6
  37. package/src/BlockletV2/utils.js +0 -75
  38. package/src/Button/Button.stories.jsx +0 -24
  39. package/src/Button/index.js +0 -9
  40. package/src/Button/wrap.jsx +0 -126
  41. package/src/ButtonGroup/index.js +0 -16
  42. package/src/CardSelector/index.tsx +0 -136
  43. package/src/Center/Center.stories.jsx +0 -20
  44. package/src/Center/index.tsx +0 -33
  45. package/src/ClickToCopy/ClickToCopy.stories.jsx +0 -24
  46. package/src/ClickToCopy/copy-button.tsx +0 -43
  47. package/src/ClickToCopy/hook.ts +0 -42
  48. package/src/ClickToCopy/index.tsx +0 -96
  49. package/src/CloseButton/index.tsx +0 -37
  50. package/src/CodeBlock/CodeBlock.stories.jsx +0 -22
  51. package/src/CodeBlock/LightBox.tsx +0 -87
  52. package/src/CodeBlock/index.tsx +0 -217
  53. package/src/Colors/Colors.stories.jsx +0 -211
  54. package/src/Colors/index.ts +0 -4
  55. package/src/Colors/themes/default.ts +0 -8
  56. package/src/Colors/themes/did-connect.ts +0 -64
  57. package/src/Colors/themes/temp.ts +0 -52
  58. package/src/Config/Config.stories.jsx +0 -16
  59. package/src/Config/config-provider.tsx +0 -62
  60. package/src/Config/index.ts +0 -2
  61. package/src/Config/theme-mode-toggle.tsx +0 -38
  62. package/src/ContactForm/ContactForm.stories.jsx +0 -32
  63. package/src/ContactForm/index.tsx +0 -264
  64. package/src/CookieConsent/CookieConsent.stories.jsx +0 -33
  65. package/src/CookieConsent/index.tsx +0 -104
  66. package/src/CountDown/CountDown.stories.jsx +0 -15
  67. package/src/CountDown/index.tsx +0 -170
  68. package/src/DID/DID.stories.jsx +0 -37
  69. package/src/DID/index.tsx +0 -393
  70. package/src/DIDConnect/app-icon.tsx +0 -37
  71. package/src/DIDConnect/app-info-item.tsx +0 -93
  72. package/src/DIDConnect/auth-apps/auth-apps-info.tsx +0 -77
  73. package/src/DIDConnect/auth-apps/index.tsx +0 -278
  74. package/src/DIDConnect/auth-apps/switch-role.tsx +0 -47
  75. package/src/DIDConnect/did-connect-container.tsx +0 -326
  76. package/src/DIDConnect/did-connect-footer.tsx +0 -76
  77. package/src/DIDConnect/did-connect-logo.tsx +0 -8
  78. package/src/DIDConnect/icons/did-wallet-logo.tsx +0 -18
  79. package/src/DIDConnect/icons/github-logo.tsx +0 -17
  80. package/src/DIDConnect/index.ts +0 -11
  81. package/src/DIDConnect/landing-page.tsx +0 -218
  82. package/src/DIDConnect/powered-by.tsx +0 -48
  83. package/src/DIDConnect/provider-icon.tsx +0 -62
  84. package/src/DIDConnect/request-storage-access-api-dialog.tsx +0 -304
  85. package/src/DIDConnect/with-container.tsx +0 -323
  86. package/src/DIDConnect/with-ux-theme.tsx +0 -22
  87. package/src/DIDLogo/Logo.stories.jsx +0 -11
  88. package/src/DIDLogo/index.tsx +0 -168
  89. package/src/Datatable/CustomToolbar.jsx +0 -415
  90. package/src/Datatable/Datatable.stories.jsx +0 -92
  91. package/src/Datatable/DatatableContext.jsx +0 -35
  92. package/src/Datatable/TableSearch.jsx +0 -166
  93. package/src/Datatable/index.jsx +0 -652
  94. package/src/Datatable/utils.js +0 -161
  95. package/src/Dialog/Dialog.stories.jsx +0 -21
  96. package/src/Dialog/confirm.jsx +0 -143
  97. package/src/Dialog/dialog.jsx +0 -199
  98. package/src/Dialog/index.js +0 -4
  99. package/src/Dialog/types.d.ts +0 -20
  100. package/src/Dialog/use-confirm.jsx +0 -188
  101. package/src/DriftBot/index.tsx +0 -81
  102. package/src/Earth/Earth.stories.jsx +0 -39
  103. package/src/Earth/countries.json +0 -8057
  104. package/src/Earth/index.tsx +0 -515
  105. package/src/Earth/util.ts +0 -72
  106. package/src/Empty/Empty.stories.jsx +0 -23
  107. package/src/Empty/index.jsx +0 -48
  108. package/src/ErrorBoundary/ErrorBoundary.stories.jsx +0 -13
  109. package/src/ErrorBoundary/fallback.tsx +0 -85
  110. package/src/ErrorBoundary/index.ts +0 -1
  111. package/src/Footer/Footer.stories.jsx +0 -13
  112. package/src/Footer/index.tsx +0 -130
  113. package/src/Header/Header.stories.jsx +0 -30
  114. package/src/Header/addon-button.tsx +0 -41
  115. package/src/Header/auto-hidden.tsx +0 -31
  116. package/src/Header/header-addons.tsx +0 -37
  117. package/src/Header/header.tsx +0 -214
  118. package/src/Header/index.ts +0 -3
  119. package/src/Header/responsive-header.tsx +0 -145
  120. package/src/Icon/Icon.stories.jsx +0 -45
  121. package/src/Icon/image.tsx +0 -53
  122. package/src/Icon/index.tsx +0 -63
  123. package/src/Img/Img.stories.jsx +0 -17
  124. package/src/Img/index.jsx +0 -258
  125. package/src/InfoRow/InfoRow.stories.jsx +0 -14
  126. package/src/InfoRow/index.tsx +0 -91
  127. package/src/Layout/Layout.stories.jsx +0 -24
  128. package/src/Layout/dashboard/external-link.tsx +0 -59
  129. package/src/Layout/dashboard/full-page.tsx +0 -58
  130. package/src/Layout/dashboard/index.tsx +0 -260
  131. package/src/Layout/dashboard/sidebar.tsx +0 -198
  132. package/src/Layout/dashboard-legacy/header.tsx +0 -156
  133. package/src/Layout/dashboard-legacy/index.tsx +0 -127
  134. package/src/Layout/dashboard-legacy/sidebar.tsx +0 -129
  135. package/src/Layout/index.tsx +0 -310
  136. package/src/LoadingMask/index.tsx +0 -108
  137. package/src/Locale/LocaleSelector.stories.jsx +0 -44
  138. package/src/Locale/browser-lang.ts +0 -65
  139. package/src/Locale/context.tsx +0 -162
  140. package/src/Locale/languages.ts +0 -58
  141. package/src/Locale/selector.tsx +0 -174
  142. package/src/Locale/util.ts +0 -38
  143. package/src/Logo/Logo.stories.jsx +0 -23
  144. package/src/Logo/images/logo-dark-text.svg +0 -3
  145. package/src/Logo/images/logo-dark-top.svg +0 -6
  146. package/src/Logo/images/logo-light-text.svg +0 -3
  147. package/src/Logo/images/logo-light-top.svg +0 -6
  148. package/src/Logo/index.tsx +0 -58
  149. package/src/Metric/Metric.stories.jsx +0 -29
  150. package/src/Metric/index.tsx +0 -130
  151. package/src/MuiWrap/index.tsx +0 -10
  152. package/src/NFTDisplay/NFTBroken.svg +0 -34
  153. package/src/NFTDisplay/NFTDisplay.stories.jsx +0 -30
  154. package/src/NFTDisplay/README.md +0 -59
  155. package/src/NFTDisplay/aspect-ratio-container.tsx +0 -36
  156. package/src/NFTDisplay/broken.tsx +0 -51
  157. package/src/NFTDisplay/displayApi.ts +0 -43
  158. package/src/NFTDisplay/index.tsx +0 -393
  159. package/src/NFTDisplay/loading.tsx +0 -16
  160. package/src/NFTDisplay/preview.tsx +0 -84
  161. package/src/NFTDisplay/render-svg.tsx +0 -21
  162. package/src/NFTDisplay/svg-embedder/img.tsx +0 -27
  163. package/src/NFTDisplay/svg-embedder/inline-svg.tsx +0 -36
  164. package/src/NavMenu/NavMenu.stories.jsx +0 -17
  165. package/src/NavMenu/images/OCAP.svg +0 -1
  166. package/src/NavMenu/images/abt-network.svg +0 -1
  167. package/src/NavMenu/images/ai-kit.svg +0 -1
  168. package/src/NavMenu/images/aigne-image-smith.svg +0 -1
  169. package/src/NavMenu/images/aigne.svg +0 -1
  170. package/src/NavMenu/images/aistro.png +0 -0
  171. package/src/NavMenu/images/arcsphere.svg +0 -1
  172. package/src/NavMenu/images/blocklet-framework.svg +0 -1
  173. package/src/NavMenu/images/blocklet-launcher.svg +0 -1
  174. package/src/NavMenu/images/blocklet-server.svg +0 -1
  175. package/src/NavMenu/images/blocklet-store.svg +0 -1
  176. package/src/NavMenu/images/creator-studio.svg +0 -1
  177. package/src/NavMenu/images/did-wallet.svg +0 -1
  178. package/src/NavMenu/images/did.svg +0 -1
  179. package/src/NavMenu/images/nft-studio.svg +0 -1
  180. package/src/NavMenu/images/payment-kit.png +0 -0
  181. package/src/NavMenu/images/vc.svg +0 -1
  182. package/src/NavMenu/images/web3-kit.svg +0 -1
  183. package/src/NavMenu/index.ts +0 -3
  184. package/src/NavMenu/nav-menu-context.tsx +0 -30
  185. package/src/NavMenu/nav-menu.tsx +0 -441
  186. package/src/NavMenu/products.tsx +0 -830
  187. package/src/NavMenu/style.ts +0 -258
  188. package/src/NavMenu/sub-container.tsx +0 -125
  189. package/src/NavMenu/sub-item-group.tsx +0 -42
  190. package/src/OrgTransfer/index.tsx +0 -53
  191. package/src/OrgTransfer/locales.ts +0 -25
  192. package/src/OrgTransfer/selector.tsx +0 -252
  193. package/src/OrgTransfer/type.ts +0 -31
  194. package/src/PageScroller/index.tsx +0 -316
  195. package/src/PageScroller/story/FifthComponent.jsx +0 -7
  196. package/src/PageScroller/story/FirstComponent.jsx +0 -7
  197. package/src/PageScroller/story/FourthComponent.jsx +0 -7
  198. package/src/PageScroller/story/FullPage.jsx +0 -55
  199. package/src/PageScroller/story/PageContain.jsx +0 -59
  200. package/src/PageScroller/story/PageScroller.stories.jsx +0 -18
  201. package/src/PageScroller/story/SecondComponent.jsx +0 -7
  202. package/src/PageScroller/story/ThirdComponent.jsx +0 -7
  203. package/src/PageScroller/story/index.css +0 -115
  204. package/src/PageScroller/usePrevValue.ts +0 -11
  205. package/src/Passport/index.ts +0 -3
  206. package/src/Passport/passport.tsx +0 -118
  207. package/src/PhoneInput/PhoneInput.stories.jsx +0 -12
  208. package/src/PhoneInput/country-select.tsx +0 -148
  209. package/src/PhoneInput/index.tsx +0 -269
  210. package/src/PoweredByArcBlock/index.tsx +0 -27
  211. package/src/PricingTable/PricingPlan.tsx +0 -120
  212. package/src/PricingTable/PricingTable.stories.jsx +0 -38
  213. package/src/PricingTable/index.tsx +0 -59
  214. package/src/QRCode/QRCode.stories.jsx +0 -13
  215. package/src/QRCode/index.tsx +0 -66
  216. package/src/RelativeTime/RelativeTime.stories.jsx +0 -20
  217. package/src/RelativeTime/index.tsx +0 -334
  218. package/src/Result/Result.stories.jsx +0 -61
  219. package/src/Result/common.tsx +0 -119
  220. package/src/Result/index.tsx +0 -30
  221. package/src/Result/result.tsx +0 -65
  222. package/src/Result/translations.ts +0 -57
  223. package/src/Screenshot/BaseScreenshot/index.tsx +0 -73
  224. package/src/Screenshot/BaseScreenshot/shells/Macbook.tsx +0 -38
  225. package/src/Screenshot/BaseScreenshot/shells/Phone.tsx +0 -35
  226. package/src/Screenshot/Screenshot.stories.jsx +0 -44
  227. package/src/Screenshot/devices.css +0 -1366
  228. package/src/Screenshot/index.tsx +0 -300
  229. package/src/SessionBlocklet/index.tsx +0 -178
  230. package/src/SessionManager/SessionManager.stories.jsx +0 -9
  231. package/src/SessionManager/index.tsx +0 -3
  232. package/src/SessionPermission/index.tsx +0 -26
  233. package/src/SessionUser/components/did-space.tsx +0 -68
  234. package/src/SessionUser/components/logged-in.tsx +0 -338
  235. package/src/SessionUser/components/quick-login-item.tsx +0 -132
  236. package/src/SessionUser/components/session-user-item.tsx +0 -93
  237. package/src/SessionUser/components/session-user-switch.tsx +0 -240
  238. package/src/SessionUser/components/un-login.tsx +0 -257
  239. package/src/SessionUser/components/user-info.tsx +0 -201
  240. package/src/SessionUser/index.tsx +0 -68
  241. package/src/SessionUser/libs/translation.ts +0 -30
  242. package/src/SessionUser/libs/utils.ts +0 -39
  243. package/src/SharedBridge/index.tsx +0 -126
  244. package/src/SocialShare/index.tsx +0 -194
  245. package/src/Sparkline/Sparkline.stories.jsx +0 -13
  246. package/src/Sparkline/index.tsx +0 -231
  247. package/src/Spinner/Spinner.stories.jsx +0 -98
  248. package/src/Spinner/index.tsx +0 -20
  249. package/src/SplitButton/SplitButton.stories.jsx +0 -32
  250. package/src/SplitButton/index.tsx +0 -116
  251. package/src/SplitButton/useClickAway.tsx +0 -24
  252. package/src/Success/index.tsx +0 -175
  253. package/src/Switch/Switch.stories.jsx +0 -16
  254. package/src/Switch/index.jsx +0 -79
  255. package/src/Tabs/Tabs.stories.jsx +0 -18
  256. package/src/Tabs/index.tsx +0 -255
  257. package/src/Tag/Tag.stories.jsx +0 -15
  258. package/src/Tag/index.jsx +0 -106
  259. package/src/TextCollapse/TextCollapse.stories.jsx +0 -73
  260. package/src/TextCollapse/index.tsx +0 -85
  261. package/src/Theme/Theme.stories.jsx +0 -11
  262. package/src/Theme/index.ts +0 -21
  263. package/src/Theme/theme-provider.tsx +0 -374
  264. package/src/Theme/theme.ts +0 -229
  265. package/src/Toast/Toast.stories.jsx +0 -28
  266. package/src/Toast/index.tsx +0 -80
  267. package/src/Typography/index.tsx +0 -124
  268. package/src/UserCard/Cards/avatar-only.tsx +0 -27
  269. package/src/UserCard/Cards/basic-info.tsx +0 -43
  270. package/src/UserCard/Cards/index.tsx +0 -16
  271. package/src/UserCard/Cards/social-actions.tsx +0 -196
  272. package/src/UserCard/Container/card.tsx +0 -63
  273. package/src/UserCard/Container/dialog.tsx +0 -37
  274. package/src/UserCard/Content/basic.tsx +0 -330
  275. package/src/UserCard/Content/clock.tsx +0 -82
  276. package/src/UserCard/Content/minimal.tsx +0 -113
  277. package/src/UserCard/Content/shorten-label.tsx +0 -32
  278. package/src/UserCard/Content/tooltip-avatar.tsx +0 -80
  279. package/src/UserCard/UserCard.stories.jsx +0 -19
  280. package/src/UserCard/components.tsx +0 -81
  281. package/src/UserCard/index.tsx +0 -132
  282. package/src/UserCard/types.ts +0 -165
  283. package/src/UserCard/use-follow.tsx +0 -111
  284. package/src/UserCard/utils.ts +0 -155
  285. package/src/Util/WebWalletOpener.stories.jsx +0 -5
  286. package/src/Util/client.ts +0 -4
  287. package/src/Util/constant.ts +0 -70
  288. package/src/Util/deprecate.tsx +0 -29
  289. package/src/Util/federated.ts +0 -125
  290. package/src/Util/iframe.ts +0 -19
  291. package/src/Util/index.ts +0 -760
  292. package/src/Util/logger.ts +0 -44
  293. package/src/Util/passport.ts +0 -127
  294. package/src/Util/security.ts +0 -72
  295. package/src/Util/style.ts +0 -17
  296. package/src/Util/wallet.ts +0 -35
  297. package/src/VerificationCode/index.tsx +0 -83
  298. package/src/Video/Video.stories.jsx +0 -6
  299. package/src/Video/index.tsx +0 -70
  300. package/src/Wallet/Action.stories.jsx +0 -8
  301. package/src/Wallet/Action.tsx +0 -118
  302. package/src/Wallet/Download.stories.jsx +0 -9
  303. package/src/Wallet/Download.tsx +0 -157
  304. package/src/Wallet/Open.tsx +0 -47
  305. package/src/Wallet/OpenInWallet.stories.jsx +0 -5
  306. package/src/Wallet/images/abtwallet.png +0 -0
  307. package/src/Wallet/images/android_download.svg +0 -22
  308. package/src/Wallet/images/app-store.svg +0 -30
  309. package/src/Wallet/images/google-play.svg +0 -69
  310. package/src/WalletOSIcon/index.tsx +0 -47
  311. package/src/WebWalletSWKeeper/index.tsx +0 -117
  312. package/src/WechatPrompt/images/android.png +0 -0
  313. package/src/WechatPrompt/images/ios.png +0 -0
  314. package/src/WechatPrompt/index.tsx +0 -75
  315. package/src/global.d.ts +0 -28
  316. package/src/hooks/use-blocklet-logo.tsx +0 -32
  317. package/src/hooks/use-clock.tsx +0 -62
  318. package/src/hooks/use-location-state.tsx +0 -117
  319. package/src/hooks/use-mobile.tsx +0 -6
  320. package/src/index.ts +0 -79
  321. package/src/type.d.ts +0 -44
  322. package/src/withTheme/index.tsx +0 -72
  323. package/src/withTracker/README.md +0 -37
  324. package/src/withTracker/action/bind-wallet.tsx +0 -17
  325. package/src/withTracker/action/login.tsx +0 -18
  326. package/src/withTracker/action/pay.tsx +0 -14
  327. package/src/withTracker/action/switch-passport.tsx +0 -20
  328. package/src/withTracker/constant/index.tsx +0 -3
  329. package/src/withTracker/env.tsx +0 -1
  330. package/src/withTracker/error_boundary.jsx +0 -34
  331. package/src/withTracker/index.tsx +0 -50
  332. package/src/withTracker/libs/utm.ts +0 -46
  333. package/vite.config.mjs +0 -37
@@ -1,334 +0,0 @@
1
- import { Box, SxProps, Tooltip, TooltipProps } from '@mui/material';
2
- import { useEffect, useMemo } from 'react';
3
- import dayjs from 'dayjs';
4
- import 'dayjs/locale/zh-cn';
5
- import utc from 'dayjs/plugin/utc';
6
- import timezone from 'dayjs/plugin/timezone';
7
- import relativeTime from 'dayjs/plugin/relativeTime';
8
- import updateLocale from 'dayjs/plugin/updateLocale';
9
- import localizedFormat from 'dayjs/plugin/localizedFormat';
10
- import { create } from 'zustand';
11
- import { formatToDatetime, setDateTool } from '../Util';
12
- import type { Locale } from '../type';
13
-
14
- dayjs.extend(localizedFormat);
15
- dayjs.extend(utc);
16
- dayjs.extend(timezone);
17
- dayjs.extend(updateLocale);
18
- dayjs.extend(relativeTime);
19
- dayjs.updateLocale('zh-cn', {
20
- // copy with https://github.com/iamkun/dayjs/blob/dev/src/locale/zh-cn.js
21
- relativeTime: {
22
- future: '%s后',
23
- past: '%s前',
24
- s: '几秒',
25
- m: '1 分钟',
26
- mm: '%d 分钟',
27
- h: '1 小时',
28
- hh: '%d 小时',
29
- d: '1 天',
30
- dd: '%d 天',
31
- M: '1 个月',
32
- MM: '%d 个月',
33
- y: '1 年',
34
- yy: '%d 年',
35
- },
36
- });
37
- // FIXME: @zhanghan 此处不能真正的将 relativeTime 设置为支持中文
38
- setDateTool(dayjs);
39
-
40
- const translations: Record<Locale, { utc: string; local: string; shortUTC: string; shortLocal: string }> = {
41
- en: {
42
- utc: 'UTC Timezone',
43
- local: 'Local Timezone',
44
- shortUTC: 'UTC',
45
- shortLocal: 'Local',
46
- },
47
- zh: {
48
- utc: 'UTC 时区',
49
- local: '当前时区',
50
- shortUTC: 'UTC',
51
- shortLocal: '当前时区',
52
- },
53
- };
54
-
55
- type UtcState = { isUtc: boolean; setIsUtc: (isUtc: boolean) => void };
56
- const useUtcStore = create<UtcState>((set) => ({
57
- isUtc: false,
58
- setIsUtc: (isUtc: boolean) => set({ isUtc }),
59
- }));
60
-
61
- export interface RelativeTimeProps {
62
- value: string | number;
63
- locale?: Locale;
64
- withoutSuffix?: false | true;
65
- from?: string | number;
66
- to?: string | number;
67
- type?: 'relative' | 'absolute' | 'utc' | 'all';
68
- tz?: string;
69
- relativeRange?: number;
70
- enableTooltip?: boolean;
71
- useShortTimezone?: boolean;
72
- disableTimezone?: boolean;
73
- placement?: TooltipProps['placement'];
74
- sx?: SxProps;
75
- format?: string;
76
- mode?: 'all' | 'daysLeft'; // all: 显示所有内容,daysLeft: 只显示剩余天数
77
- }
78
-
79
- function normalizeTimestamp(value: string | number) {
80
- let normalizedValue = value;
81
- if (typeof normalizedValue === 'string' && /^\d+$/.test(normalizedValue)) {
82
- normalizedValue = Number(normalizedValue);
83
- }
84
-
85
- if (typeof normalizedValue === 'number') {
86
- // 10 位左右:很可能是秒(例如 1699411200)
87
- // 13 位左右:很可能是毫秒(例如 1699411200000)
88
- const abs = Math.abs(Math.trunc(normalizedValue));
89
- // < 100,000,000,000 -> treat as seconds (safe threshold for seconds)
90
- if (abs < 1e11) {
91
- return new Date(normalizedValue * 1000).getTime();
92
- }
93
-
94
- return new Date(normalizedValue).getTime();
95
- }
96
-
97
- return new Date(normalizedValue).getTime();
98
- }
99
-
100
- function useRelativeTime({
101
- value,
102
- locale = 'en',
103
- withoutSuffix = false,
104
- from = '',
105
- to = '',
106
- type = 'relative',
107
- tz,
108
- relativeRange,
109
- format,
110
- }: {
111
- value: string | number;
112
- locale?: Locale;
113
- withoutSuffix?: boolean;
114
- from?: string | number;
115
- to?: string | number;
116
- type?: 'relative' | 'absolute' | 'utc';
117
- tz?: string;
118
- relativeRange?: number;
119
- format?: string;
120
- }) {
121
- const date = new Date();
122
- const timeZoneOffset = date.getTimezoneOffset();
123
- const sign = timeZoneOffset > 0 ? '-' : '+';
124
- const hoursOffset = Math.abs(timeZoneOffset) / 60;
125
- const isLocalUtc = timeZoneOffset === 0;
126
-
127
- const isUtc = useUtcStore((state) => state.isUtc);
128
- const setIsUtc = useUtcStore((state) => state.setIsUtc);
129
-
130
- useEffect(() => {
131
- setIsUtc(isLocalUtc);
132
- // eslint-disable-next-line react-hooks/exhaustive-deps
133
- }, [isLocalUtc]);
134
-
135
- if (!value) {
136
- return { innerContent: '-', popContent: '-', isUtc, setIsUtc, sign, hoursOffset };
137
- }
138
-
139
- const normalizedValue = normalizeTimestamp(value);
140
- const localeOption = locale === 'zh' ? 'zh-cn' : 'en';
141
- let datetime = dayjs(normalizedValue);
142
-
143
- if (type === 'utc') {
144
- datetime = datetime.utc();
145
- }
146
-
147
- if (tz) {
148
- datetime = datetime.tz(tz);
149
- }
150
-
151
- datetime = datetime.locale(localeOption);
152
-
153
- const absoluteString = formatToDatetime(normalizedValue, { locale: localeOption, tz, format });
154
-
155
- let relativeString;
156
-
157
- if (from) {
158
- relativeString = datetime.from(from, withoutSuffix);
159
- } else if (to) {
160
- relativeString = datetime.to(to, withoutSuffix);
161
- } else if (relativeRange) {
162
- const diffTime = datetime.diff(dayjs());
163
- if (Math.abs(diffTime) > relativeRange) {
164
- relativeString = absoluteString;
165
- }
166
- }
167
-
168
- if (!relativeString) {
169
- relativeString = datetime.fromNow(withoutSuffix);
170
- }
171
-
172
- let innerContent = relativeString;
173
- let popContent = absoluteString;
174
-
175
- if (type === 'absolute') {
176
- innerContent = absoluteString;
177
- popContent = relativeString;
178
- }
179
-
180
- if (type === 'utc') {
181
- if (isUtc) {
182
- innerContent = formatToDatetime(normalizedValue, { locale: localeOption, tz, isUtc: true, format });
183
- popContent = formatToDatetime(normalizedValue, { locale: localeOption, tz, isUtc: true, format });
184
- } else {
185
- innerContent = absoluteString;
186
- popContent = relativeString;
187
- }
188
- }
189
-
190
- return { innerContent, popContent, isUtc, setIsUtc, sign, hoursOffset, relativeString, absoluteString };
191
- }
192
-
193
- function UTCChip({
194
- locale,
195
- isUtc = false,
196
- setIsUtc,
197
- useShortTimezone = true,
198
- }: {
199
- locale: Locale;
200
- isUtc?: boolean;
201
- setIsUtc: (data: boolean) => void;
202
- useShortTimezone?: boolean;
203
- }) {
204
- const text = useMemo(() => {
205
- const UTC = useShortTimezone ? 'shortUTC' : 'utc';
206
- const LOCAL = useShortTimezone ? 'shortLocal' : 'local';
207
- // fallback to en
208
- const config = translations[locale] || translations.en;
209
-
210
- if (isUtc) {
211
- return `${config[UTC]}`;
212
- }
213
-
214
- return `${config[LOCAL]}`;
215
- }, [locale, useShortTimezone, isUtc]);
216
-
217
- return (
218
- <Box
219
- component="span"
220
- sx={{
221
- color: 'inherit',
222
- cursor: 'pointer',
223
- border: '1px solid',
224
- borderColor: 'divider',
225
- borderRadius: '20px',
226
- padding: '4px 8px',
227
- lineHeight: 1,
228
- }}
229
- onClick={() => setIsUtc(!isUtc)}>
230
- {text}
231
- </Box>
232
- );
233
- }
234
-
235
- export default function RelativeTime({
236
- value,
237
- locale = 'en',
238
- withoutSuffix = false,
239
- from = '',
240
- to = '',
241
- type = 'relative',
242
- tz = undefined,
243
- relativeRange = undefined,
244
- enableTooltip = true,
245
- useShortTimezone = false,
246
- disableTimezone = false,
247
- placement = 'top-end',
248
- format = 'lll',
249
- mode = 'all',
250
- ...rest
251
- }: RelativeTimeProps) {
252
- const { innerContent, popContent, isUtc, setIsUtc, relativeString } = useRelativeTime({
253
- value,
254
- locale,
255
- withoutSuffix,
256
- from,
257
- to,
258
- type: type === 'all' ? 'utc' : type,
259
- tz,
260
- relativeRange,
261
- format,
262
- });
263
-
264
- const allContent = (
265
- <Box
266
- {...rest}
267
- sx={[
268
- {
269
- display: 'inline-flex',
270
- alignItems: 'center',
271
- gap: 0.5,
272
- },
273
- ...(Array.isArray(rest.sx) ? rest.sx : [rest.sx]),
274
- ]}>
275
- <Box component="span" {...rest} sx={{}}>
276
- {innerContent}
277
- </Box>
278
-
279
- <Box component="span" sx={{ color: 'inherit' }}>
280
- ·
281
- </Box>
282
-
283
- <Box component="span" sx={{ color: 'inherit' }}>
284
- {relativeString}
285
- </Box>
286
-
287
- {!disableTimezone && (
288
- <>
289
- <Box component="span" sx={{ color: 'inherit' }}>
290
- ·
291
- </Box>
292
-
293
- <UTCChip locale={locale} isUtc={isUtc} setIsUtc={setIsUtc} useShortTimezone={useShortTimezone} />
294
- </>
295
- )}
296
- </Box>
297
- );
298
-
299
- // 优先通过 mode 来决定显示什么内容
300
- if (mode === 'daysLeft') {
301
- return (
302
- <Tooltip title={allContent} placement={placement} enterTouchDelay={0}>
303
- <Box component="span">{relativeString}</Box>
304
- </Tooltip>
305
- );
306
- }
307
-
308
- if (type === 'all' && mode === 'all') {
309
- return (
310
- <Tooltip title={undefined} placement={placement} enterTouchDelay={0}>
311
- {allContent}
312
- </Tooltip>
313
- );
314
- }
315
-
316
- return (
317
- <Tooltip title={enableTooltip ? popContent : undefined} placement={placement} enterTouchDelay={0}>
318
- <Box
319
- sx={{
320
- display: 'inline-flex',
321
- alignItems: 'center',
322
- gap: 1,
323
- }}>
324
- <Box component="span" {...rest}>
325
- {innerContent}
326
- </Box>
327
-
328
- {type === 'utc' && !disableTimezone && (
329
- <UTCChip locale={locale} isUtc={isUtc} setIsUtc={setIsUtc} useShortTimezone={useShortTimezone} />
330
- )}
331
- </Box>
332
- </Tooltip>
333
- );
334
- }
@@ -1,61 +0,0 @@
1
- import { Box } from '@mui/material';
2
- import { LocaleProvider } from '../Locale/context';
3
- import LocaleSelector from '../Locale/selector';
4
-
5
- export { default as Common404 } from './demo/common404';
6
- export { default as Common403 } from './demo/common403';
7
- export { default as Common500 } from './demo/common500';
8
- export { default as CommonError } from './demo/common-error';
9
- export { default as CommonMaintenance } from './demo/common-maintenance';
10
- export { default as CommonComingSoon } from './demo/common-coming-soon';
11
- export { default as Custom404Page } from './demo/custom404-page';
12
- export { default as InfoPage } from './demo/info-page';
13
-
14
- export default {
15
- title: 'Feedback/Result',
16
-
17
- parameters: {
18
- layout: 'fullscreen',
19
-
20
- docs: {
21
- description: {
22
- component: 'Used to provide feedback on the outcomes of a series of operational tasks.',
23
- },
24
- },
25
- },
26
- decorators: [
27
- (StoryFn) => (
28
- <TestContainer>
29
- <StoryFn />
30
- </TestContainer>
31
- ),
32
- ],
33
- };
34
-
35
- // eslint-disable-next-line react/prop-types
36
- function TestContainer({ children, ...rest }) {
37
- return (
38
- <LocaleProvider locale="en" translations={{}}>
39
- <Box
40
- {...rest}
41
- sx={[
42
- {
43
- position: 'relative',
44
- height: 760,
45
- overflow: 'hidden',
46
- },
47
- ...(Array.isArray(rest.sx) ? rest.sx : [rest.sx]),
48
- ]}>
49
- <Box
50
- sx={{
51
- position: 'absolute',
52
- top: 16,
53
- right: 16,
54
- }}>
55
- <LocaleSelector />
56
- </Box>
57
- {children}
58
- </Box>
59
- </LocaleProvider>
60
- );
61
- }
@@ -1,119 +0,0 @@
1
- /* eslint-disable react/prop-types */
2
- /* eslint-disable no-param-reassign */
3
- import { Info as InfoIcon, CancelRounded as CancelRoundedIcon } from '@mui/icons-material';
4
- import { type SvgIconProps } from '@mui/material';
5
- import Result, { type ResultProps } from './result';
6
- import translations from './translations';
7
- import { useLocaleContext } from '../Locale/context';
8
- import { useTheme } from '../Theme';
9
- import type { Locale } from '../type';
10
-
11
- // 优先使用显式指定的 locale, 再尝试使用 context 中的 locale, 最后使用默认 'en'
12
- const useLocale = (locale: Locale) => {
13
- locale = ['zh', 'en'].includes(locale) ? locale : '';
14
- const { locale: localeFromContext } = useLocaleContext() || { locale: 'en' };
15
- const result = locale || localeFromContext;
16
- return translations[result] ? result : 'en';
17
- };
18
-
19
- export type CommonResultProps = { locale: Locale } & Omit<ResultProps, 'icon' | 'title' | 'description'>;
20
-
21
- // 404
22
- export function PageNotFound({ locale, ...rest }: CommonResultProps) {
23
- locale = useLocale(locale);
24
- return (
25
- <Result
26
- icon={<StyledErrorIcon />}
27
- title={translations[locale]['404'].title}
28
- description={translations[locale]['404'].description}
29
- {...rest}
30
- />
31
- );
32
- }
33
- PageNotFound.status = '404';
34
-
35
- // 403
36
- export function Forbidden({ locale, ...rest }: CommonResultProps) {
37
- locale = useLocale(locale);
38
- return (
39
- <Result
40
- icon={<StyledErrorIcon />}
41
- title={translations[locale][403].title}
42
- description={translations[locale][403].description}
43
- {...rest}
44
- />
45
- );
46
- }
47
- Forbidden.status = '403';
48
-
49
- // 500
50
- export function InternalServerError({ locale, ...rest }: CommonResultProps) {
51
- locale = useLocale(locale);
52
- return (
53
- <Result
54
- icon={<StyledErrorIcon />}
55
- title={translations[locale][500].title}
56
- description={translations[locale][500].description}
57
- {...rest}
58
- />
59
- );
60
- }
61
- InternalServerError.status = '500';
62
-
63
- // 通用错误
64
- export function Error({ locale, ...rest }: CommonResultProps) {
65
- locale = useLocale(locale);
66
- return (
67
- <Result
68
- icon={<StyledErrorIcon />}
69
- title={translations[locale].error.title}
70
- description={translations[locale].error.description}
71
- {...rest}
72
- />
73
- );
74
- }
75
- Error.status = 'error';
76
-
77
- // under maintenance
78
- export function Maintenance({ locale, ...rest }: CommonResultProps) {
79
- locale = useLocale(locale);
80
- return (
81
- <Result
82
- icon={<StyledInfoIcon />}
83
- title={translations[locale].maintenance.title}
84
- description={translations[locale].maintenance.description}
85
- {...rest}
86
- />
87
- );
88
- }
89
- Maintenance.status = 'maintenance';
90
-
91
- // coming soon
92
- export function ComingSoon({ locale, ...rest }: CommonResultProps) {
93
- locale = useLocale(locale);
94
- return (
95
- <Result
96
- icon={<StyledInfoIcon />}
97
- title={translations[locale].comingSoon.title}
98
- description={translations[locale].comingSoon.description}
99
- {...rest}
100
- />
101
- );
102
- }
103
- ComingSoon.status = 'comingSoon';
104
-
105
- // info, 与其它 status 不同, title/description 需要使用方自己传入
106
- export function Info(props: Omit<ResultProps, 'icon'>) {
107
- return <Result icon={<StyledInfoIcon />} {...props} />;
108
- }
109
- Info.status = 'info';
110
-
111
- function StyledErrorIcon(props: SvgIconProps) {
112
- const theme = useTheme();
113
- return <CancelRoundedIcon style={{ color: theme.palette.error.main, fontSize: 72 }} {...props} />;
114
- }
115
-
116
- function StyledInfoIcon(props: SvgIconProps) {
117
- const theme = useTheme();
118
- return <InfoIcon style={{ color: theme.palette.info.main, fontSize: 72 }} {...props} />;
119
- }
@@ -1,30 +0,0 @@
1
- import Result, { type ResultProps } from './result';
2
- import * as common from './common';
3
-
4
- type ComponentNames = keyof typeof common;
5
-
6
- const componentsKeyByStatus = Object.keys(common).reduce<Record<string, React.ComponentType<ResultProps>>>(
7
- (acc, cur) => ({ ...acc, [common[cur as ComponentNames].status || cur]: common[cur as ComponentNames] as any }),
8
- {}
9
- );
10
-
11
- export interface ResultWrapperProps extends ResultProps {
12
- status?: string | number;
13
- }
14
-
15
- function ResultWrapper({ status = '', ...rest }: ResultWrapperProps) {
16
- if (status) {
17
- if (componentsKeyByStatus[status]) {
18
- const Component = componentsKeyByStatus[status];
19
- return <Component {...rest} />;
20
- }
21
- throw new Error(
22
- `Please provide a valid status for Result.status. Valid values are: ${Object.keys(componentsKeyByStatus).join(
23
- ', '
24
- )}`
25
- );
26
- }
27
- return <Result {...rest} />;
28
- }
29
-
30
- export default ResultWrapper;
@@ -1,65 +0,0 @@
1
- import { Box } from '@mui/material';
2
-
3
- import { styled } from '../Theme';
4
-
5
- export interface ResultProps {
6
- icon?: React.ReactNode;
7
- title?: React.ReactNode;
8
- description?: React.ReactNode;
9
- extra?: React.ReactNode;
10
- }
11
-
12
- function Result({ icon = null, title = '', description = '', extra = null, ...rest }: ResultProps) {
13
- return (
14
- <Root {...rest}>
15
- {icon}
16
- {typeof title === 'string' ? (
17
- <Box
18
- sx={{
19
- mt: 3,
20
- fontSize: 22,
21
- fontWeight: 400,
22
- color: 'text.primary',
23
- textAlign: 'center',
24
- }}>
25
- {title}
26
- </Box>
27
- ) : (
28
- title
29
- )}
30
- {typeof description === 'string' ? (
31
- <Box
32
- sx={{
33
- mt: 1,
34
- fontSize: 14,
35
- color: 'text.secondary',
36
- textAlign: 'center',
37
- }}>
38
- {description}
39
- </Box>
40
- ) : (
41
- description
42
- )}
43
- <Box
44
- sx={{
45
- mt: 3,
46
- }}>
47
- {extra}
48
- </Box>
49
- </Root>
50
- );
51
- }
52
-
53
- const Root = styled('div')`
54
- box-sizing: border-box;
55
- display: flex;
56
- flex-direction: column;
57
- justify-content: center;
58
- align-items: center;
59
- height: 100%;
60
- padding: 16px;
61
-
62
- background-color: ${({ theme }) => theme.palette?.background?.default || '#F7F8F8'};
63
- `;
64
-
65
- export default Result;
@@ -1,57 +0,0 @@
1
- import type { Translations } from '../type';
2
-
3
- export default {
4
- en: {
5
- 404: {
6
- title: '404 - Page Not Found',
7
- description: 'Sorry about that, the page you are looking for does not exist or has been moved.',
8
- },
9
- 403: {
10
- title: '403 – Forbidden',
11
- description: 'Sorry, you are not authorized to access this page.',
12
- },
13
- 500: {
14
- title: '500 - Internal Server Error',
15
- description: 'An internal server error has occurred. Please try again later.',
16
- },
17
- error: {
18
- title: 'Application Error',
19
- description: 'Something went wrong. Please try again later.',
20
- },
21
- maintenance: {
22
- title: 'Offline for maintenance',
23
- description: 'This app is undergoing maintenance right now. Please check back later.',
24
- },
25
- comingSoon: {
26
- title: 'Coming Soon',
27
- description: "Our website is under construction. We'll be here soon with our new website.",
28
- },
29
- },
30
-
31
- zh: {
32
- 404: {
33
- title: '404 - 页面未找到',
34
- description: '很抱歉,您正在寻找的页面不存在或已被移动。',
35
- },
36
- 403: {
37
- title: '403 – 禁止访问',
38
- description: '很抱歉,您没有权限访问此页面。',
39
- },
40
- 500: {
41
- title: '500 - 内部服务器错误',
42
- description: '发生了一个内部服务器错误。请稍后再试。',
43
- },
44
- error: {
45
- title: 'Application Error',
46
- description: '出错了, 请稍后再试。',
47
- },
48
- maintenance: {
49
- title: '维护中',
50
- description: '应用程序正在进行维护。请稍后再查看。',
51
- },
52
- comingSoon: {
53
- title: '即将上线',
54
- description: '我们的网站正在建设中。我们很快就会在这里推出我们的新网站。',
55
- },
56
- },
57
- } as Translations;