@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.
@@ -33,7 +33,7 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
33
33
  (item) => ({
34
34
  title: item.title,
35
35
  url: item.link,
36
- icon: item.icon ? /* @__PURE__ */ jsx("iconify-icon", { icon: item.icon }) : null,
36
+ icon: item.icon ? /* @__PURE__ */ jsx("iconify-icon", { height: "100%", width: "100%", icon: item.icon }) : null,
37
37
  // https://github.com/ArcBlock/ux/issues/755#issuecomment-1208692620
38
38
  external: true,
39
39
  children: item.items
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import type { BoxProps } from '@mui/material';
3
3
  import type { User } from '../../@types';
4
- export default function UserBasicInfo({ user, isMyself, switchPassport, ...rest }: {
4
+ export default function UserBasicInfo({ user, isMyself, switchPassport, switchProfile, openSettings, ...rest }: {
5
5
  user: User;
6
6
  isMyself: boolean;
7
7
  switchPassport: () => void;
8
+ switchProfile: () => void;
9
+ openSettings: () => void;
8
10
  } & BoxProps): import("react").JSX.Element;
@@ -1,66 +1,153 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Box, Chip, Typography } from "@mui/material";
2
+ import { Box, Chip, IconButton, Typography } from "@mui/material";
3
3
  import { Icon } from "@iconify/react";
4
4
  import SwapHorizRoundedIcon from "@iconify-icons/material-symbols/swap-horiz-rounded";
5
+ import SettingsOutlineRoundedIcon from "@iconify-icons/material-symbols/settings-outline-rounded";
6
+ import Avatar from "@arcblock/ux/lib/Avatar";
5
7
  import { temp as colors } from "@arcblock/ux/lib/Colors";
8
+ import { useTheme } from "@arcblock/ux/lib/Theme";
6
9
  import DID from "@arcblock/ux/lib/DID";
7
- import { useCreation } from "ahooks";
10
+ import { useCreation, useMemoizedFn } from "ahooks";
11
+ import { translate } from "@arcblock/ux/lib/Locale/util";
12
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
13
+ import noop from "lodash/noop";
14
+ import { translations } from "../libs/locales.js";
8
15
  export default function UserBasicInfo({
9
16
  user,
10
17
  isMyself = true,
11
18
  switchPassport,
19
+ switchProfile,
20
+ openSettings,
12
21
  ...rest
13
22
  }) {
23
+ const { locale } = useLocaleContext();
24
+ const t = useMemoizedFn((key, data = {}) => {
25
+ return translate(translations, key, locale, "en", data);
26
+ });
14
27
  const currentRole = useCreation(
15
28
  () => (user?.passports || [])?.find((item) => item.name === user.role),
16
29
  [user?.passports, user?.role]
17
30
  );
18
- return /* @__PURE__ */ jsxs(Box, { ...rest, children: [
19
- /* @__PURE__ */ jsxs(
20
- Typography,
21
- {
22
- variant: "h4",
23
- sx: {
24
- fontWeight: "bold",
25
- display: "flex",
26
- alignItems: "center",
27
- gap: 1,
28
- mb: 1
29
- },
30
- children: [
31
- user?.fullName,
32
- isMyself ? /* @__PURE__ */ jsx(
33
- Chip,
34
- {
35
- label: currentRole?.title || user?.role || "Guest",
36
- size: "small",
37
- variant: "outlined",
38
- sx: {
39
- flexShrink: 0,
40
- fontWeight: "bold",
41
- fontSize: "12px",
42
- color: colors.textBase,
43
- borderColor: colors.strokeBorderStrong,
44
- backgroundColor: "white",
45
- textTransform: "capitalize",
46
- pr: 1,
47
- pl: 0.5,
31
+ const theme = useTheme();
32
+ const isSmallView = theme.breakpoints.down("md");
33
+ return /* @__PURE__ */ jsxs(
34
+ Box,
35
+ {
36
+ ...rest,
37
+ sx: {
38
+ position: "relative",
39
+ ...rest.sx
40
+ },
41
+ children: [
42
+ /* @__PURE__ */ jsx(
43
+ Avatar,
44
+ {
45
+ src: user?.avatar,
46
+ did: user?.did,
47
+ size: isSmallView ? 64 : 80,
48
+ variant: "circle",
49
+ shape: "circle",
50
+ sx: {
51
+ borderRadius: "100%",
52
+ backgroundColor: "#fff",
53
+ position: "relative",
54
+ overflow: "hidden",
55
+ ...isMyself ? {
56
+ cursor: "pointer",
48
57
  "&:hover": {
49
- backgroundColor: "rgba(0, 0, 0, 0.04)"
58
+ "&::after": {
59
+ content: `"${t("switchProfile")}"`
60
+ }
50
61
  },
51
- "&:active": {
52
- boxShadow: "none"
62
+ "&::after": {
63
+ color: "white",
64
+ position: "absolute",
65
+ fontSize: "12px",
66
+ bottom: 0,
67
+ left: 0,
68
+ right: 0,
69
+ height: "50%",
70
+ backgroundColor: "rgba(0, 0, 0, 0.3)",
71
+ display: "flex",
72
+ justifyContent: "center",
73
+ alignItems: "center"
53
74
  }
75
+ } : {}
76
+ },
77
+ onClick: isMyself ? switchProfile : noop
78
+ }
79
+ ),
80
+ /* @__PURE__ */ jsxs(
81
+ Typography,
82
+ {
83
+ variant: "h5",
84
+ sx: {
85
+ fontWeight: "bold",
86
+ display: "flex",
87
+ alignItems: "center",
88
+ gap: 1,
89
+ fontSize: "24px !important"
90
+ },
91
+ children: [
92
+ user?.fullName,
93
+ isMyself ? /* @__PURE__ */ jsx(
94
+ Chip,
95
+ {
96
+ label: currentRole?.title || user?.role || "Guest",
97
+ size: "small",
98
+ variant: "outlined",
99
+ sx: {
100
+ flexShrink: 0,
101
+ fontWeight: "bold",
102
+ fontSize: "12px",
103
+ color: colors.textBase,
104
+ borderColor: colors.strokeBorderStrong,
105
+ backgroundColor: "white",
106
+ textTransform: "capitalize",
107
+ pr: 1,
108
+ pl: 0.5,
109
+ "&:hover": {
110
+ backgroundColor: "rgba(0, 0, 0, 0.04)"
111
+ },
112
+ "&:active": {
113
+ boxShadow: "none"
114
+ }
115
+ },
116
+ clickable: true,
117
+ deleteIcon: /* @__PURE__ */ jsx(Icon, { icon: SwapHorizRoundedIcon, color: colors.textBase }),
118
+ onDelete: switchPassport,
119
+ onClick: switchPassport
120
+ }
121
+ ) : null
122
+ ]
123
+ }
124
+ ),
125
+ /* @__PURE__ */ jsx(DID, { did: user.did, copyable: false }),
126
+ isMyself ? /* @__PURE__ */ jsx(
127
+ IconButton,
128
+ {
129
+ sx: {
130
+ borderRadius: 2,
131
+ color: colors.textBase,
132
+ backgroundColor: "white",
133
+ border: `1px solid ${colors.strokeBorderBase}`,
134
+ position: "absolute",
135
+ bottom: {
136
+ xs: "unset",
137
+ md: 0
138
+ },
139
+ top: {
140
+ xs: 0,
141
+ md: "unset"
54
142
  },
55
- clickable: true,
56
- deleteIcon: /* @__PURE__ */ jsx(Icon, { icon: SwapHorizRoundedIcon, color: colors.textBase }),
57
- onDelete: switchPassport,
58
- onClick: switchPassport
59
- }
60
- ) : null
61
- ]
62
- }
63
- ),
64
- /* @__PURE__ */ jsx(DID, { did: user.did, copyable: false })
65
- ] });
143
+ right: 0
144
+ },
145
+ disableFocusRipple: true,
146
+ onClick: openSettings,
147
+ children: /* @__PURE__ */ jsx(Icon, { icon: SettingsOutlineRoundedIcon })
148
+ }
149
+ ) : null
150
+ ]
151
+ }
152
+ );
66
153
  }
@@ -1,9 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { PaperProps } from '@mui/material';
3
- export default function UserCenter({ children, currentTab, contentProps, disableAutoRedirect, autoPopupSetting, }: {
4
- children: any;
5
- currentTab: string;
6
- contentProps?: PaperProps;
7
- disableAutoRedirect?: boolean;
8
- autoPopupSetting?: boolean;
3
+ export default function UserCenter({ children, currentTab, contentProps, disableAutoRedirect, autoPopupSetting, hideFooter, headerProps, footerProps, }: {
4
+ readonly children: any;
5
+ readonly currentTab: string;
6
+ readonly contentProps?: PaperProps;
7
+ readonly disableAutoRedirect?: boolean;
8
+ readonly autoPopupSetting?: boolean;
9
+ readonly hideFooter?: boolean;
10
+ readonly headerProps?: object;
11
+ readonly footerProps?: object;
9
12
  }): import("react").JSX.Element | null;
@@ -1,11 +1,8 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
- import { Box, CircularProgress, IconButton, Paper, Typography } from "@mui/material";
3
+ import { Box, CircularProgress, Paper, Typography } 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";
7
5
  import { SessionContext } from "@arcblock/did-connect/lib/Session";
8
- import Avatar from "@arcblock/ux/lib/Avatar";
9
6
  import Tabs from "@arcblock/ux/lib/Tabs";
10
7
  import Empty from "@arcblock/ux/lib/Empty";
11
8
  import { temp as colors } from "@arcblock/ux/lib/Colors";
@@ -15,9 +12,8 @@ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
15
12
  import { ErrorFallback } from "@arcblock/ux/lib/ErrorBoundary";
16
13
  import cloneDeep from "lodash/cloneDeep";
17
14
  import { getQuery, withQuery } from "ufo";
18
- import Header from "../../Header/index.js";
15
+ import { Header, Footer } from "../..//index.js";
19
16
  import { translations } from "../libs/locales.js";
20
- import banner from "../assets/banner.png";
21
17
  import UserInfo from "./user-info.js";
22
18
  import UserBasicInfo from "./user-basic-info.js";
23
19
  import { formatBlockletInfo, getLocalizedNavigation } from "../../blocklets.js";
@@ -29,7 +25,10 @@ export default function UserCenter({
29
25
  currentTab,
30
26
  contentProps = {},
31
27
  disableAutoRedirect = false,
32
- autoPopupSetting = false
28
+ autoPopupSetting = false,
29
+ hideFooter = false,
30
+ headerProps = {},
31
+ footerProps = {}
33
32
  }) {
34
33
  const { locale } = useLocaleContext();
35
34
  const t = useMemoizedFn((key, data = {}) => {
@@ -134,26 +133,6 @@ export default function UserCenter({
134
133
  });
135
134
  }
136
135
  });
137
- const xsGridTemplateAreas = useCreation(() => {
138
- return [
139
- '"avatar settings"',
140
- '"basicInfo basicInfo"',
141
- userCenterTabs.length > 0 || !isMyself ? '"tabs tabs"' : null,
142
- isMyself ? '"passport passport"' : null,
143
- isMyself ? '"extraInfo extraInfo"' : null
144
- ];
145
- }, [userCenterTabs, isMyself]);
146
- const mdGridTemplateAreas = useCreation(() => {
147
- if (!isMyself) {
148
- return ['"avatar"', '"basicInfo"', '"tabs"'];
149
- }
150
- return [
151
- '"avatar settings"',
152
- '"basicInfo extraInfo"',
153
- userCenterTabs.length > 0 ? '"tabs extraInfo"' : null,
154
- '"passport extraInfo"'
155
- ];
156
- }, [userCenterTabs, isMyself]);
157
136
  const openSettings = useMemoizedFn(() => {
158
137
  confirmApi.open({
159
138
  title: t("settings"),
@@ -196,77 +175,22 @@ export default function UserCenter({
196
175
  Box,
197
176
  {
198
177
  sx: {
199
- maxWidth: 1200,
178
+ maxWidth: 880,
200
179
  margin: "0 auto",
201
- px: 3,
202
- pb: 3,
203
- display: "grid",
180
+ p: 3,
181
+ display: "flex",
204
182
  gap: 2.5,
205
- gridTemplateAreas: {
206
- xs: xsGridTemplateAreas.filter(Boolean).join(" "),
207
- md: mdGridTemplateAreas.filter(Boolean).join(" ")
208
- },
209
- gridTemplateRows: {
210
- xs: "64px auto auto auto",
211
- md: "64px auto 1fr"
212
- },
213
- gridTemplateColumns: {
214
- xs: "1fr",
215
- md: isMyself ? "1fr 300px" : "1fr"
216
- }
183
+ flexDirection: "column"
217
184
  },
218
185
  children: [
219
- /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
220
- Avatar,
221
- {
222
- src: userState.data?.avatar,
223
- did: userState.data?.did,
224
- size: 120,
225
- variant: "circle",
226
- shape: "circle",
227
- style: {
228
- border: "4px solid #fff",
229
- transform: "translateY(-50%)",
230
- borderRadius: "100%",
231
- gridArea: "avatar",
232
- backgroundColor: "#fff"
233
- }
234
- }
235
- ) }),
236
- isMyself ? /* @__PURE__ */ jsx(
237
- Box,
238
- {
239
- sx: {
240
- gridArea: "settings",
241
- display: "flex",
242
- justifyContent: "flex-end",
243
- alignItems: "center"
244
- },
245
- children: /* @__PURE__ */ jsx(
246
- IconButton,
247
- {
248
- sx: {
249
- borderRadius: 2,
250
- color: colors.textBase,
251
- backgroundColor: "white",
252
- border: `1px solid ${colors.strokeBorderBase}`
253
- },
254
- disableFocusRipple: true,
255
- onClick: openSettings,
256
- children: /* @__PURE__ */ jsx(Icon, { icon: SettingsOutlineRoundedIcon })
257
- }
258
- )
259
- }
260
- ) : null,
261
186
  /* @__PURE__ */ jsx(
262
187
  UserBasicInfo,
263
188
  {
264
189
  isMyself,
265
190
  switchPassport: session.switchPassport,
266
- user: userState.data,
267
- sx: {
268
- gridArea: "basicInfo"
269
- }
191
+ switchProfile: session.switchProfile,
192
+ openSettings,
193
+ user: userState.data
270
194
  }
271
195
  ),
272
196
  userCenterTabs.length > 0 && currentTab ? /* @__PURE__ */ jsxs(
@@ -326,41 +250,28 @@ export default function UserCenter({
326
250
  }
327
251
  ) : null,
328
252
  isMyself ? /* @__PURE__ */ jsxs(Fragment, { children: [
329
- /* @__PURE__ */ jsxs(
330
- Box,
331
- {
332
- sx: {
333
- gridArea: "passport"
334
- },
335
- children: [
336
- /* @__PURE__ */ jsx(Typography, { variant: "h5", sx: { fontWeight: "bold", mb: 1.5 }, children: "Passport" }),
337
- /* @__PURE__ */ jsx(Passport, { user: userState.data })
338
- ]
339
- }
340
- ),
341
- /* @__PURE__ */ jsx(
342
- Box,
343
- {
344
- sx: {
345
- gridArea: "extraInfo"
346
- },
347
- children: /* @__PURE__ */ jsx(
348
- UserInfo,
349
- {
350
- user: userState.data,
351
- sx: {
352
- padding: 3,
353
- borderRadius: 3
354
- }
253
+ /* @__PURE__ */ jsxs(Box, { children: [
254
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", sx: { fontWeight: "bold", mb: 1.5 }, children: t("passport") }),
255
+ /* @__PURE__ */ jsx(Passport, { user: userState.data })
256
+ ] }),
257
+ /* @__PURE__ */ jsxs(Box, { children: [
258
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", sx: { fontWeight: "bold", mb: 1.5 }, children: t("userInfo") }),
259
+ /* @__PURE__ */ jsx(
260
+ UserInfo,
261
+ {
262
+ user: userState.data,
263
+ sx: {
264
+ padding: 3,
265
+ borderRadius: 3
355
266
  }
356
- )
357
- }
358
- )
267
+ }
268
+ )
269
+ ] })
359
270
  ] }) : null
360
271
  ]
361
272
  }
362
273
  );
363
- }, [userState, userCenterTabs, mdGridTemplateAreas, xsGridTemplateAreas]);
274
+ }, [userState, userCenterTabs]);
364
275
  if (!disableAutoRedirect && !currentTab && formattedBlocklet?.navigation?.userCenter?.length > 0) {
365
276
  window.location.replace(formattedBlocklet?.navigation?.userCenter[0]?.link);
366
277
  return null;
@@ -370,27 +281,17 @@ export default function UserCenter({
370
281
  {
371
282
  sx: {
372
283
  backgroundColor: colors.backgroundsBgSubtitle,
373
- minHeight: "100vh"
284
+ minHeight: "100vh",
285
+ display: "flex",
286
+ flexDirection: "column"
374
287
  },
375
288
  children: [
376
- /* @__PURE__ */ jsx(Header, {}),
377
- /* @__PURE__ */ jsx(
378
- Box,
379
- {
380
- sx: {
381
- pt: {
382
- xs: `${400 / 1280 * 100}%`,
383
- sm: `${300 / 1280 * 100}%`,
384
- md: `${200 / 1280 * 100}%`
385
- },
386
- backgroundImage: `url(${banner})`,
387
- backgroundSize: "cover",
388
- minHeight: "60px"
389
- }
390
- }
391
- ),
392
- content,
393
- confirmHolder
289
+ /* @__PURE__ */ jsx(Header, { ...headerProps }),
290
+ /* @__PURE__ */ jsxs(Box, { flex: 1, children: [
291
+ content,
292
+ confirmHolder
293
+ ] }),
294
+ hideFooter ? null : /* @__PURE__ */ jsx(Footer, { ...footerProps })
394
295
  ]
395
296
  }
396
297
  );
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { BoxProps } from '@mui/material';
2
3
  type TUserInfoItemProps = {
3
4
  data: {
4
5
  icon: any;
@@ -6,5 +7,5 @@ type TUserInfoItemProps = {
6
7
  content: any;
7
8
  };
8
9
  };
9
- export default function UserInfoItem({ data }: TUserInfoItemProps): import("react").JSX.Element;
10
+ export default function UserInfoItem({ data, ...rest }: TUserInfoItemProps & BoxProps): import("react").JSX.Element;
10
11
  export {};
@@ -1,17 +1,19 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Box, Typography } from "@mui/material";
3
3
  import { temp as colors } from "@arcblock/ux/lib/Colors";
4
- export default function UserInfoItem({ data }) {
4
+ export default function UserInfoItem({ data, ...rest }) {
5
5
  return /* @__PURE__ */ jsxs(
6
6
  Box,
7
7
  {
8
+ ...rest,
8
9
  sx: {
9
10
  display: "grid",
10
11
  gridTemplateColumns: "auto 1fr",
11
12
  gridTemplateAreas: `"icon title" ". content"`,
12
13
  alignItems: "center",
13
14
  rowGap: 0.75,
14
- columnGap: 1
15
+ columnGap: 1,
16
+ ...rest.sx
15
17
  },
16
18
  children: [
17
19
  /* @__PURE__ */ jsx(
@@ -58,11 +58,15 @@ export default function UserInfo({
58
58
  ...rest,
59
59
  sx: {
60
60
  display: "flex",
61
- flexDirection: "column",
61
+ flexDirection: {
62
+ xs: "column",
63
+ md: "row"
64
+ },
65
+ alignItems: "flex-start",
62
66
  gap: 3,
63
67
  ...rest?.sx
64
68
  },
65
- children: userInfoListData.map((item) => /* @__PURE__ */ jsx(UserInfoItem, { data: item }, item.title))
69
+ children: userInfoListData.map((item) => /* @__PURE__ */ jsx(UserInfoItem, { data: item, sx: { flex: 1 } }, item.title))
66
70
  }
67
71
  );
68
72
  }
@@ -33,6 +33,8 @@ export declare const translations: {
33
33
  };
34
34
  toPublic: string;
35
35
  currentPassport: string;
36
+ switchProfile: string;
37
+ userInfo: string;
36
38
  };
37
39
  en: {
38
40
  settings: string;
@@ -68,5 +70,7 @@ export declare const translations: {
68
70
  };
69
71
  toPublic: string;
70
72
  currentPassport: string;
73
+ switchProfile: string;
74
+ userInfo: string;
71
75
  };
72
76
  };
@@ -32,7 +32,9 @@ export const translations = {
32
32
  invalid: "\u65E0\u6548"
33
33
  },
34
34
  toPublic: "\u516C\u5F00 \u201C{name}\u201D \u9875\u9762",
35
- currentPassport: "\u5F53\u524D\u4F7F\u7528\u7684\u901A\u884C\u8BC1"
35
+ currentPassport: "\u5F53\u524D\u4F7F\u7528\u7684\u901A\u884C\u8BC1",
36
+ switchProfile: "\u5207\u6362",
37
+ userInfo: "\u4E2A\u4EBA\u4FE1\u606F"
36
38
  },
37
39
  en: {
38
40
  settings: "Settings",
@@ -67,6 +69,8 @@ export const translations = {
67
69
  invalid: "Invalid"
68
70
  },
69
71
  toPublic: 'Public "{name}" page',
70
- currentPassport: "Passport currently in use"
72
+ currentPassport: "Passport currently in use",
73
+ switchProfile: "Switch",
74
+ userInfo: "User Info"
71
75
  }
72
76
  };
@@ -53,6 +53,8 @@ function Dashboard({
53
53
  title: item.title,
54
54
  url: item.link,
55
55
  icon: item.icon ? /* @__PURE__ */(0, _jsxRuntime.jsx)("iconify-icon", {
56
+ height: "100%",
57
+ width: "100%",
56
58
  icon: item.icon
57
59
  }) : null,
58
60
  // https://github.com/ArcBlock/ux/issues/755#issuecomment-1208692620
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import type { BoxProps } from '@mui/material';
3
3
  import type { User } from '../../@types';
4
- export default function UserBasicInfo({ user, isMyself, switchPassport, ...rest }: {
4
+ export default function UserBasicInfo({ user, isMyself, switchPassport, switchProfile, openSettings, ...rest }: {
5
5
  user: User;
6
6
  isMyself: boolean;
7
7
  switchPassport: () => void;
8
+ switchProfile: () => void;
9
+ openSettings: () => void;
8
10
  } & BoxProps): import("react").JSX.Element;