@arcblock/ux 2.11.50 → 2.12.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 (82) hide show
  1. package/lib/CloseButton/index.d.ts +5 -0
  2. package/lib/CloseButton/index.js +29 -0
  3. package/lib/Colors/index.d.ts +1 -0
  4. package/lib/Colors/index.js +2 -1
  5. package/lib/Colors/themes/did-connect.d.ts +55 -0
  6. package/lib/Colors/themes/did-connect.js +55 -0
  7. package/lib/Header/demo/images/boards.svg +3 -0
  8. package/lib/Header/demo/images/chatbot.svg +3 -0
  9. package/lib/Header/demo/images/gallery.svg +3 -0
  10. package/lib/NavMenu/images/OCAP.svg +16 -0
  11. package/lib/NavMenu/images/abt-network.svg +18 -0
  12. package/lib/NavMenu/images/ai-kit.svg +46 -0
  13. package/lib/NavMenu/images/aigne.svg +8 -0
  14. package/lib/NavMenu/images/aistro.svg +14 -0
  15. package/lib/NavMenu/images/blocklet-framework.svg +25 -0
  16. package/lib/NavMenu/images/blocklet-launcher.svg +9 -0
  17. package/lib/NavMenu/images/blocklet-server.svg +19 -0
  18. package/lib/NavMenu/images/blocklet-store.svg +11 -0
  19. package/lib/NavMenu/images/creator-studio.svg +42 -0
  20. package/lib/NavMenu/images/did-connect.svg +26 -0
  21. package/lib/NavMenu/images/did-name-service.svg +3 -0
  22. package/lib/NavMenu/images/did-wallet.svg +33 -0
  23. package/lib/NavMenu/images/did.svg +3 -0
  24. package/lib/NavMenu/images/nft-studio.svg +19 -0
  25. package/lib/NavMenu/images/vc.svg +7 -0
  26. package/lib/NavMenu/images/web3-kit.svg +56 -0
  27. package/lib/NavMenu/index.d.ts +1 -0
  28. package/lib/NavMenu/index.js +2 -1
  29. package/lib/NavMenu/nav-menu-context.d.ts +17 -0
  30. package/lib/NavMenu/nav-menu-context.js +19 -0
  31. package/lib/NavMenu/nav-menu.d.ts +10 -5
  32. package/lib/NavMenu/nav-menu.js +76 -36
  33. package/lib/NavMenu/products.d.ts +5 -0
  34. package/lib/NavMenu/products.js +1639 -0
  35. package/lib/NavMenu/style.d.ts +8 -3
  36. package/lib/NavMenu/style.js +215 -175
  37. package/lib/NavMenu/sub-item-group.d.ts +5 -0
  38. package/lib/NavMenu/sub-item-group.js +44 -0
  39. package/lib/RelativeTime/index.js +1 -0
  40. package/lib/SessionUser/components/quick-login-item.d.ts +19 -0
  41. package/lib/SessionUser/components/quick-login-item.js +122 -0
  42. package/lib/SessionUser/components/un-login.d.ts +2 -1
  43. package/lib/SessionUser/components/un-login.js +173 -30
  44. package/lib/SessionUser/index.js +1 -0
  45. package/lib/SessionUser/libs/translation.js +4 -2
  46. package/lib/Typography/index.js +6 -2
  47. package/lib/Util/style.d.ts +2 -0
  48. package/lib/Util/style.js +14 -0
  49. package/package.json +5 -5
  50. package/src/CloseButton/index.tsx +30 -0
  51. package/src/Colors/index.ts +1 -0
  52. package/src/Colors/themes/did-connect.ts +56 -0
  53. package/src/NavMenu/images/OCAP.svg +16 -0
  54. package/src/NavMenu/images/abt-network.svg +18 -0
  55. package/src/NavMenu/images/ai-kit.svg +46 -0
  56. package/src/NavMenu/images/aigne.svg +8 -0
  57. package/src/NavMenu/images/aistro.svg +14 -0
  58. package/src/NavMenu/images/blocklet-framework.svg +25 -0
  59. package/src/NavMenu/images/blocklet-launcher.svg +9 -0
  60. package/src/NavMenu/images/blocklet-server.svg +19 -0
  61. package/src/NavMenu/images/blocklet-store.svg +11 -0
  62. package/src/NavMenu/images/creator-studio.svg +42 -0
  63. package/src/NavMenu/images/did-connect.svg +26 -0
  64. package/src/NavMenu/images/did-name-service.svg +3 -0
  65. package/src/NavMenu/images/did-wallet.svg +33 -0
  66. package/src/NavMenu/images/did.svg +3 -0
  67. package/src/NavMenu/images/nft-studio.svg +19 -0
  68. package/src/NavMenu/images/vc.svg +7 -0
  69. package/src/NavMenu/images/web3-kit.svg +56 -0
  70. package/src/NavMenu/index.ts +1 -0
  71. package/src/NavMenu/nav-menu-context.tsx +30 -0
  72. package/src/NavMenu/nav-menu.tsx +98 -61
  73. package/src/NavMenu/products.tsx +378 -0
  74. package/src/NavMenu/style.ts +220 -183
  75. package/src/NavMenu/sub-item-group.tsx +36 -0
  76. package/src/RelativeTime/index.tsx +1 -0
  77. package/src/SessionUser/components/quick-login-item.tsx +131 -0
  78. package/src/SessionUser/components/un-login.tsx +179 -25
  79. package/src/SessionUser/index.tsx +1 -1
  80. package/src/SessionUser/libs/translation.ts +2 -0
  81. package/src/Typography/index.tsx +2 -2
  82. package/src/Util/style.ts +17 -0
@@ -1,22 +1,52 @@
1
- import { Box, CircularProgress, IconButton } from '@mui/material';
1
+ import {
2
+ Box,
3
+ CircularProgress,
4
+ Divider,
5
+ Fade,
6
+ IconButton,
7
+ LinearProgress,
8
+ MenuItem,
9
+ MenuList,
10
+ Paper,
11
+ Popper,
12
+ } from '@mui/material';
2
13
  import { Icon } from '@iconify/react';
3
14
  import UserIcon from '@iconify-icons/tabler/user';
4
- import { useRef } from 'react';
5
- import { useMemoizedFn } from 'ahooks';
15
+ import { useEffect, useRef } from 'react';
16
+ import { useMemoizedFn, useReactive } from 'ahooks';
6
17
  import noop from 'lodash/noop';
18
+ import DIDWalletIcon from '@arcblock/icons/lib/DidWallet';
7
19
 
8
20
  import { Session } from '../../type';
21
+ import { temp as colors, didConnectColors } from '../../Colors';
22
+ import CloseButton from '../../CloseButton';
23
+ import { translate } from '../../Locale/util';
24
+ import { translations } from '../libs/translation';
25
+ import Typography from '../../Typography';
26
+ import QuickLoginItem from './quick-login-item';
9
27
 
10
28
  export interface UnLoginProps {
11
29
  session: Session;
12
30
  onLogin?: () => void;
13
31
  size?: number;
14
32
  dark?: false | true;
33
+ locale?: string;
15
34
  }
16
35
 
17
- export default function UnLogin({ session, onLogin = noop, size = 24, dark = false }: UnLoginProps) {
36
+ export default function UnLogin({ session, onLogin = noop, size = 24, dark = false, locale = 'en' }: UnLoginProps) {
37
+ const t = useMemoizedFn((key, data = {}) => {
38
+ return translate(translations, key, locale, 'en', data);
39
+ });
18
40
  const isFirstLoading = false;
19
41
  const userAnchorRef = useRef(null);
42
+ const currentState = useReactive({
43
+ open: false,
44
+ userSessions: [] as Session[],
45
+ loadingSessionId: null,
46
+ });
47
+ const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
48
+ currentState.open = value;
49
+ });
20
50
  const _onLogin = useMemoizedFn(() => {
21
51
  if (isFirstLoading) {
22
52
  return;
@@ -24,28 +54,152 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
24
54
  session.login(onLogin);
25
55
  });
26
56
 
57
+ useEffect(() => {
58
+ const timer = setTimeout(async () => {
59
+ currentState.userSessions = await session.getUserSessions();
60
+ if (currentState.userSessions.length > 0) {
61
+ currentState.open = true;
62
+ }
63
+ }, 1500);
64
+
65
+ return () => {
66
+ clearTimeout(timer);
67
+ };
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, []);
70
+
71
+ const handleLogin = useMemoizedFn(async (userSession) => {
72
+ currentState.loadingSessionId = userSession.id;
73
+ try {
74
+ await session.loginUserSession({ ...userSession, appPid: blocklet?.appPid });
75
+ } catch (err) {
76
+ console.error('session.loginUserSession.error', err);
77
+ } finally {
78
+ currentState.loadingSessionId = null;
79
+ }
80
+ });
81
+
27
82
  return (
28
- <Box>
29
- <IconButton
30
- ref={userAnchorRef}
31
- onClick={_onLogin}
32
- data-cy="sessionManager-login"
33
- className="arc-session-user-unlogin"
34
- size="medium"
35
- aria-label="Login button">
36
- {isFirstLoading ? (
37
- <Box width={size} height={size} display="flex" justifyContent="center" alignItems="center">
38
- <CircularProgress style={{ width: size - 4, height: size - 4, color: dark ? '#fff' : '' }} />
39
- </Box>
40
- ) : (
41
- <Icon
42
- icon={UserIcon}
43
- fontSize={size}
44
- color={dark ? '#fff' : 'inherit'}
45
- style={{ transform: 'scale(1.25)' }}
46
- />
83
+ <>
84
+ <Box>
85
+ <IconButton
86
+ ref={userAnchorRef}
87
+ onClick={_onLogin}
88
+ data-cy="sessionManager-login"
89
+ className="arc-session-user-unlogin"
90
+ size="medium"
91
+ aria-label="Login button">
92
+ {isFirstLoading ? (
93
+ <Box width={size} height={size} display="flex" justifyContent="center" alignItems="center">
94
+ <CircularProgress style={{ width: size - 4, height: size - 4, color: dark ? '#fff' : '' }} />
95
+ </Box>
96
+ ) : (
97
+ <Icon
98
+ icon={UserIcon}
99
+ fontSize={size}
100
+ color={dark ? '#fff' : 'inherit'}
101
+ style={{ transform: 'scale(1.25)' }}
102
+ />
103
+ )}
104
+ </IconButton>
105
+ </Box>
106
+ <Popper
107
+ open={currentState.open}
108
+ anchorEl={userAnchorRef.current}
109
+ // @ts-expect-error
110
+ dark={dark}
111
+ transition
112
+ placement="bottom-end"
113
+ sx={{ zIndex: 1100 }}
114
+ modifiers={[
115
+ {
116
+ name: 'offset',
117
+ options: {
118
+ offset: [0, 10], // [水平偏移, 垂直偏移]
119
+ },
120
+ },
121
+ ]}>
122
+ {({ TransitionProps }) => (
123
+ <Fade {...TransitionProps}>
124
+ <Paper
125
+ variant="outlined"
126
+ sx={{
127
+ borderRadius: 2,
128
+ width: 400,
129
+ maxWidth: '90vw',
130
+ borderColor: colors.lineStep,
131
+ border: '0 !important',
132
+ boxShadow: `0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6}`,
133
+ }}>
134
+ <Box
135
+ sx={{
136
+ display: 'flex',
137
+ alignItems: 'center',
138
+ gap: 2,
139
+ p: 2,
140
+ borderBottom: '1px solid #eee',
141
+ }}>
142
+ <DIDWalletIcon width={24} height={24} />
143
+ <Typography
144
+ fontSize="auto"
145
+ sx={{
146
+ fontSize: '16',
147
+ flex: 1,
148
+ color: didConnectColors.text.secondary,
149
+ }}>
150
+ {t('useQuickLogin')}
151
+ </Typography>
152
+ <CloseButton onClose={() => onTogglePopper(false)} />
153
+ </Box>
154
+ <MenuList sx={{ p: 0, overflow: 'hidden' }}>
155
+ {currentState.userSessions.map((userSessionItem, index) => {
156
+ const isLoading = currentState.loadingSessionId === userSessionItem.id;
157
+
158
+ return (
159
+ <>
160
+ <MenuItem
161
+ key={userSessionItem.id}
162
+ sx={{
163
+ overflow: 'hidden',
164
+ position: 'relative',
165
+ p: 0,
166
+ '&:hover': {
167
+ backgroundColor: `${colors.surfacePrimarySubtitle} !important`,
168
+ },
169
+ }}
170
+ onClick={() => {
171
+ handleLogin(userSessionItem);
172
+ }}>
173
+ {isLoading && (
174
+ <LinearProgress
175
+ sx={{
176
+ height: '2px',
177
+ position: 'absolute',
178
+ top: 0,
179
+ left: 0,
180
+ right: 0,
181
+ }}
182
+ />
183
+ )}
184
+ <QuickLoginItem userSession={userSessionItem as unknown as any} locale={locale} />
185
+ </MenuItem>
186
+ {index < currentState.userSessions.length - 1 ? (
187
+ <Divider
188
+ sx={{
189
+ mx: 2,
190
+ my: '0px !important',
191
+ borderColor: '#e4e4e7',
192
+ }}
193
+ />
194
+ ) : null}
195
+ </>
196
+ );
197
+ })}
198
+ </MenuList>
199
+ </Paper>
200
+ </Fade>
47
201
  )}
48
- </IconButton>
49
- </Box>
202
+ </Popper>
203
+ </>
50
204
  );
51
205
  }
@@ -22,5 +22,5 @@ export default function SessionUser({ session, onBindWallet = noop, locale = 'en
22
22
  <LoggedIn isBlocklet={isBlocklet} session={session} onBindWallet={onBindWallet} locale={locale} size={size} />
23
23
  );
24
24
  }
25
- return <UnLogin session={session} size={size} />;
25
+ return <UnLogin session={session} locale={locale} size={size} />;
26
26
  }
@@ -13,6 +13,7 @@ export const translations: Translations = {
13
13
  logout: 'Sign Out',
14
14
  addAnotherAccount: 'Add another account',
15
15
  disconnected: 'Disconnected',
16
+ useQuickLogin: 'Use DID Connect account to login quickly',
16
17
  },
17
18
  zh: {
18
19
  connectDIDWallet: '连接你的 DID Wallet 获得更高的安全性',
@@ -24,5 +25,6 @@ export const translations: Translations = {
24
25
  logout: '退出登录',
25
26
  addAnotherAccount: '添加账户',
26
27
  disconnected: '未连接',
28
+ useQuickLogin: '使用 DID Connect 账号快速登录',
27
29
  },
28
30
  };
@@ -98,7 +98,7 @@ export default function Typography({
98
98
  {...rest}
99
99
  sx={{
100
100
  ...sx,
101
- fontSize: `${state.fontSize}px !important`,
101
+ ...(state.fontSize ? { fontSize: `${state.fontSize}px !important` } : {}),
102
102
  position: 'fixed',
103
103
  top: -1000,
104
104
  left: -1000,
@@ -112,7 +112,7 @@ export default function Typography({
112
112
  {...rest}
113
113
  sx={{
114
114
  ...sx,
115
- fontSize: `${state.fontSize}px !important`,
115
+ ...(state.fontSize ? { fontSize: `${state.fontSize}px !important` } : {}),
116
116
  }}>
117
117
  {children}
118
118
  </MuiTypography>
@@ -0,0 +1,17 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import type { SxProps } from '@mui/material';
3
+
4
+ export const mergeSx = (...sxList: Array<SxProps | undefined | null>) => {
5
+ const mergedSx = sxList.reduce((acc, sx) => {
6
+ if (!sx) {
7
+ return acc;
8
+ }
9
+
10
+ if (Array.isArray(sx)) {
11
+ return acc.concat(sx);
12
+ }
13
+
14
+ return acc.concat([sx]);
15
+ }, [] as SxProps[]);
16
+ return mergedSx as SxProps;
17
+ };