@blocklet/ui-react 2.9.17 → 2.9.18

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.
@@ -2,10 +2,9 @@ import { useContext } from 'react';
2
2
  import { Box, CircularProgress, IconButton, Paper, Typography } from '@mui/material';
3
3
  import type { PaperProps } from '@mui/material';
4
4
  import { useCreation, useMemoizedFn, useMount, useRequest } from 'ahooks';
5
- import { Icon } from '@iconify/react';
6
- import SettingsOutlineRoundedIcon from '@iconify-icons/material-symbols/settings-outline-rounded';
5
+
7
6
  import { SessionContext } from '@arcblock/did-connect/lib/Session';
8
- import Avatar from '@arcblock/ux/lib/Avatar';
7
+
9
8
  import Tabs from '@arcblock/ux/lib/Tabs';
10
9
  import Empty from '@arcblock/ux/lib/Empty';
11
10
  import { temp as colors } from '@arcblock/ux/lib/Colors';
@@ -17,10 +16,8 @@ import cloneDeep from 'lodash/cloneDeep';
17
16
  import { getQuery, withQuery } from 'ufo';
18
17
  import type { AxiosError } from 'axios';
19
18
 
20
- // @ts-ignore
21
- import Header from '../../Header';
19
+ import { Header, Footer } from '../../';
22
20
  import { translations } from '../libs/locales';
23
- import banner from '../assets/banner.png';
24
21
  import UserInfo from './user-info';
25
22
  import UserBasicInfo from './user-basic-info';
26
23
  import type { SessionContext as TSessionContext, UserCenterTab } from '../../@types';
@@ -36,12 +33,18 @@ export default function UserCenter({
36
33
  contentProps = {},
37
34
  disableAutoRedirect = false,
38
35
  autoPopupSetting = false,
36
+ hideFooter = false,
37
+ headerProps = {},
38
+ footerProps = {},
39
39
  }: {
40
- children: any;
41
- currentTab: string;
42
- contentProps?: PaperProps;
43
- disableAutoRedirect?: boolean;
44
- autoPopupSetting?: boolean;
40
+ readonly children: any;
41
+ readonly currentTab: string;
42
+ readonly contentProps?: PaperProps;
43
+ readonly disableAutoRedirect?: boolean;
44
+ readonly autoPopupSetting?: boolean;
45
+ readonly hideFooter?: boolean;
46
+ readonly headerProps?: object;
47
+ readonly footerProps?: object;
45
48
  }) {
46
49
  const { locale } = useLocaleContext();
47
50
  const t = useMemoizedFn((key, data = {}) => {
@@ -157,27 +160,6 @@ export default function UserCenter({
157
160
  });
158
161
  }
159
162
  });
160
- const xsGridTemplateAreas = useCreation(() => {
161
- return [
162
- '"avatar settings"',
163
- '"basicInfo basicInfo"',
164
- userCenterTabs.length > 0 || !isMyself ? '"tabs tabs"' : null,
165
- isMyself ? '"passport passport"' : null,
166
- isMyself ? '"extraInfo extraInfo"' : null,
167
- ];
168
- }, [userCenterTabs, isMyself]);
169
-
170
- const mdGridTemplateAreas = useCreation(() => {
171
- if (!isMyself) {
172
- return ['"avatar"', '"basicInfo"', '"tabs"'];
173
- }
174
- return [
175
- '"avatar settings"',
176
- '"basicInfo extraInfo"',
177
- userCenterTabs.length > 0 ? '"tabs extraInfo"' : null,
178
- '"passport extraInfo"',
179
- ];
180
- }, [userCenterTabs, isMyself]);
181
163
 
182
164
  const openSettings = useMemoizedFn(() => {
183
165
  confirmApi.open({
@@ -226,69 +208,19 @@ export default function UserCenter({
226
208
  return (
227
209
  <Box
228
210
  sx={{
229
- maxWidth: 1200,
211
+ maxWidth: 880,
230
212
  margin: '0 auto',
231
- px: 3,
232
- pb: 3,
233
- display: 'grid',
213
+ p: 3,
214
+ display: 'flex',
234
215
  gap: 2.5,
235
- gridTemplateAreas: {
236
- xs: xsGridTemplateAreas.filter(Boolean).join(' '),
237
- md: mdGridTemplateAreas.filter(Boolean).join(' '),
238
- },
239
- gridTemplateRows: {
240
- xs: '64px auto auto auto',
241
- md: '64px auto 1fr',
242
- },
243
- gridTemplateColumns: {
244
- xs: '1fr',
245
- md: isMyself ? '1fr 300px' : '1fr',
246
- },
216
+ flexDirection: 'column',
247
217
  }}>
248
- <Box>
249
- <Avatar
250
- src={userState.data?.avatar}
251
- did={userState.data?.did}
252
- size={120}
253
- variant="circle"
254
- shape="circle"
255
- style={{
256
- border: '4px solid #fff',
257
- transform: 'translateY(-50%)',
258
- borderRadius: '100%',
259
- gridArea: 'avatar',
260
- backgroundColor: '#fff',
261
- }}
262
- />
263
- </Box>
264
- {isMyself ? (
265
- <Box
266
- sx={{
267
- gridArea: 'settings',
268
- display: 'flex',
269
- justifyContent: 'flex-end',
270
- alignItems: 'center',
271
- }}>
272
- <IconButton
273
- sx={{
274
- borderRadius: 2,
275
- color: colors.textBase,
276
- backgroundColor: 'white',
277
- border: `1px solid ${colors.strokeBorderBase}`,
278
- }}
279
- disableFocusRipple
280
- onClick={openSettings}>
281
- <Icon icon={SettingsOutlineRoundedIcon} />
282
- </IconButton>
283
- </Box>
284
- ) : null}
285
218
  <UserBasicInfo
286
219
  isMyself={isMyself}
287
220
  switchPassport={session.switchPassport}
221
+ switchProfile={session.switchProfile}
222
+ openSettings={openSettings}
288
223
  user={userState.data}
289
- sx={{
290
- gridArea: 'basicInfo',
291
- }}
292
224
  />
293
225
  {userCenterTabs.length > 0 && currentTab ? (
294
226
  <Box
@@ -351,19 +283,16 @@ export default function UserCenter({
351
283
  ) : null}
352
284
  {isMyself ? (
353
285
  <>
354
- <Box
355
- sx={{
356
- gridArea: 'passport',
357
- }}>
286
+ <Box>
358
287
  <Typography variant="h5" sx={{ fontWeight: 'bold', mb: 1.5 }}>
359
- Passport
288
+ {t('passport')}
360
289
  </Typography>
361
290
  <Passport user={userState.data} />
362
291
  </Box>
363
- <Box
364
- sx={{
365
- gridArea: 'extraInfo',
366
- }}>
292
+ <Box>
293
+ <Typography variant="h5" sx={{ fontWeight: 'bold', mb: 1.5 }}>
294
+ {t('userInfo')}
295
+ </Typography>
367
296
  <UserInfo
368
297
  user={userState.data}
369
298
  sx={{
@@ -376,7 +305,7 @@ export default function UserCenter({
376
305
  ) : null}
377
306
  </Box>
378
307
  );
379
- }, [userState, userCenterTabs, mdGridTemplateAreas, xsGridTemplateAreas]);
308
+ }, [userState, userCenterTabs]);
380
309
 
381
310
  if (!disableAutoRedirect && !currentTab && formattedBlocklet?.navigation?.userCenter?.length > 0) {
382
311
  window.location.replace(formattedBlocklet?.navigation?.userCenter[0]?.link);
@@ -388,23 +317,15 @@ export default function UserCenter({
388
317
  sx={{
389
318
  backgroundColor: colors.backgroundsBgSubtitle,
390
319
  minHeight: '100vh',
320
+ display: 'flex',
321
+ flexDirection: 'column',
391
322
  }}>
392
- <Header />
393
- <Box
394
- sx={{
395
- pt: {
396
- xs: `${(400 / 1280) * 100}%`,
397
- sm: `${(300 / 1280) * 100}%`,
398
- md: `${(200 / 1280) * 100}%`,
399
- },
400
- backgroundImage: `url(${banner})`,
401
- backgroundSize: 'cover',
402
- minHeight: '60px',
403
- }}
404
- />
405
- {}
406
- {content}
407
- {confirmHolder}
323
+ <Header {...headerProps} />
324
+ <Box flex={1}>
325
+ {content}
326
+ {confirmHolder}
327
+ </Box>
328
+ {hideFooter ? null : <Footer {...footerProps} />}
408
329
  </Box>
409
330
  );
410
331
  }
@@ -1,4 +1,4 @@
1
- import { Box, Typography } from '@mui/material';
1
+ import { Box, BoxProps, Typography } from '@mui/material';
2
2
  import { temp as colors } from '@arcblock/ux/lib/Colors';
3
3
 
4
4
  type TUserInfoItemProps = {
@@ -9,9 +9,10 @@ type TUserInfoItemProps = {
9
9
  };
10
10
  };
11
11
 
12
- export default function UserInfoItem({ data }: TUserInfoItemProps) {
12
+ export default function UserInfoItem({ data, ...rest }: TUserInfoItemProps & BoxProps) {
13
13
  return (
14
14
  <Box
15
+ {...rest}
15
16
  sx={{
16
17
  display: 'grid',
17
18
  gridTemplateColumns: 'auto 1fr',
@@ -19,6 +20,7 @@ export default function UserInfoItem({ data }: TUserInfoItemProps) {
19
20
  alignItems: 'center',
20
21
  rowGap: 0.75,
21
22
  columnGap: 1,
23
+ ...rest.sx,
22
24
  }}>
23
25
  <Box
24
26
  sx={{
@@ -73,12 +73,16 @@ export default function UserInfo({
73
73
  {...rest}
74
74
  sx={{
75
75
  display: 'flex',
76
- flexDirection: 'column',
76
+ flexDirection: {
77
+ xs: 'column',
78
+ md: 'row',
79
+ },
80
+ alignItems: 'flex-start',
77
81
  gap: 3,
78
82
  ...rest?.sx,
79
83
  }}>
80
84
  {userInfoListData.map((item) => (
81
- <UserInfoItem key={item.title} data={item} />
85
+ <UserInfoItem key={item.title} data={item} sx={{ flex: 1 }} />
82
86
  ))}
83
87
  </Paper>
84
88
  );
@@ -33,6 +33,8 @@ export const translations = {
33
33
  },
34
34
  toPublic: '公开 “{name}” 页面',
35
35
  currentPassport: '当前使用的通行证',
36
+ switchProfile: '切换',
37
+ userInfo: '个人信息',
36
38
  },
37
39
  en: {
38
40
  settings: 'Settings',
@@ -68,5 +70,7 @@ export const translations = {
68
70
  },
69
71
  toPublic: 'Public "{name}" page',
70
72
  currentPassport: 'Passport currently in use',
73
+ switchProfile: 'Switch',
74
+ userInfo: 'User Info',
71
75
  },
72
76
  };
@@ -1,8 +0,0 @@
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: ['babel-plugin-inline-react-svg'],
7
- ignore: ['src/**/*.stories.js', 'src/**/demo'],
8
- };