@arcblock/ux 2.13.6 → 2.13.8
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/Colors/index.d.ts +3 -1
- package/lib/Colors/index.js +4 -2
- package/lib/Config/config-provider.d.ts +7 -7
- package/lib/Config/config-provider.js +1 -1
- package/lib/Theme/theme.d.ts +7 -41
- package/lib/Theme/theme.js +50 -132
- package/lib/UserCard/Cards/avatar-only.d.ts +3 -2
- package/lib/UserCard/Cards/basic-info.d.ts +3 -2
- package/lib/UserCard/Cards/basic-info.js +12 -6
- package/lib/UserCard/Cards/index.d.ts +3 -2
- package/lib/UserCard/Cards/name-only.d.ts +4 -2
- package/lib/UserCard/Cards/name-only.js +3 -2
- package/lib/UserCard/Container/dialog.js +1 -1
- package/lib/UserCard/Content/basic.d.ts +2 -1
- package/lib/UserCard/Content/basic.js +195 -67
- package/lib/UserCard/Content/minimal.d.ts +2 -2
- package/lib/UserCard/Content/minimal.js +2 -0
- package/lib/UserCard/Content/tooltip-avatar.d.ts +4 -4
- package/lib/UserCard/Content/tooltip-avatar.js +4 -3
- package/lib/UserCard/components.d.ts +2 -2
- package/lib/UserCard/components.js +9 -3
- package/lib/UserCard/index.js +36 -4
- package/lib/UserCard/types.d.ts +7 -4
- package/lib/UserCard/utils.d.ts +2 -0
- package/lib/UserCard/utils.js +33 -0
- package/lib/type.d.ts +2 -3
- package/lib/withTheme/index.d.ts +2 -3
- package/package.json +6 -5
- package/src/Colors/index.ts +7 -2
- package/src/Config/config-provider.tsx +9 -9
- package/src/Theme/theme.ts +55 -166
- package/src/UserCard/Cards/avatar-only.tsx +3 -2
- package/src/UserCard/Cards/basic-info.tsx +17 -5
- package/src/UserCard/Cards/index.tsx +3 -2
- package/src/UserCard/Cards/name-only.tsx +4 -4
- package/src/UserCard/Container/dialog.tsx +1 -1
- package/src/UserCard/Content/basic.tsx +191 -57
- package/src/UserCard/Content/minimal.tsx +4 -3
- package/src/UserCard/Content/tooltip-avatar.tsx +10 -5
- package/src/UserCard/components.tsx +17 -7
- package/src/UserCard/index.tsx +41 -3
- package/src/UserCard/types.ts +11 -4
- package/src/UserCard/utils.ts +33 -0
- package/src/type.d.ts +2 -3
- package/src/withTheme/index.tsx +2 -3
@@ -1,15 +1,28 @@
|
|
1
|
-
import { Typography, Box } from '@mui/material';
|
1
|
+
import { Typography, Box, Grid } from '@mui/material';
|
2
2
|
import { useCreation } from 'ahooks';
|
3
3
|
import styled from '@emotion/styled';
|
4
|
+
import isArray from 'lodash/isArray';
|
5
|
+
import { Icon as IconifyIcon } from '@iconify/react';
|
6
|
+
import infoCircleIcon from '@iconify-icons/tabler/info-circle';
|
4
7
|
import LinkIcon from '@arcblock/icons/lib/Link';
|
8
|
+
import PhoneIcon from '@arcblock/icons/lib/Phone';
|
5
9
|
import LocationIcon from '@arcblock/icons/lib/Location';
|
6
10
|
import EmailIcon from '@arcblock/icons/lib/Email';
|
7
11
|
import TimezoneIcon from '@arcblock/icons/lib/Timezone';
|
8
|
-
import { withoutProtocol } from 'ufo';
|
12
|
+
import { joinURL, withoutProtocol } from 'ufo';
|
13
|
+
import { Fragment, useState, useMemo, useCallback } from 'react';
|
9
14
|
|
10
15
|
import { User } from '../types';
|
11
16
|
import Clock from './clock';
|
12
17
|
|
18
|
+
const IconMap = {
|
19
|
+
timezone: TimezoneIcon,
|
20
|
+
email: EmailIcon,
|
21
|
+
phone: PhoneIcon,
|
22
|
+
location: LocationIcon,
|
23
|
+
link: LinkIcon,
|
24
|
+
};
|
25
|
+
|
13
26
|
/**
|
14
27
|
* 格式化链接显示
|
15
28
|
* 对于 http/https 协议只显示域名,其他协议显示完整链接
|
@@ -25,9 +38,84 @@ const iconSize = {
|
|
25
38
|
interface BasicContentProps {
|
26
39
|
user: User;
|
27
40
|
isFull?: boolean;
|
41
|
+
renderFields?: string[];
|
42
|
+
}
|
43
|
+
|
44
|
+
function TimeZoneField({ value }: { value: string }) {
|
45
|
+
return (
|
46
|
+
<Box display="flex" alignItems="center" gap={1} className="user-card__timezone-field">
|
47
|
+
<TimezoneIcon {...iconSize} />
|
48
|
+
<LineText variant="body2" color="grey.800">
|
49
|
+
<Clock value={value} variant="body2" color="grey.800" />
|
50
|
+
</LineText>
|
51
|
+
</Box>
|
52
|
+
);
|
53
|
+
}
|
54
|
+
|
55
|
+
function LinkField({ value }: { value: string }) {
|
56
|
+
const [useFallback, setUseFallback] = useState(false);
|
57
|
+
const faviconUrl = useCreation(() => {
|
58
|
+
try {
|
59
|
+
const url = new URL(value);
|
60
|
+
return joinURL(url.origin, 'favicon.ico');
|
61
|
+
} catch (e) {
|
62
|
+
return '';
|
63
|
+
}
|
64
|
+
}, [value]);
|
65
|
+
|
66
|
+
const handleImageError = () => {
|
67
|
+
setUseFallback(true);
|
68
|
+
};
|
69
|
+
|
70
|
+
return (
|
71
|
+
<Box display="flex" alignItems="center" gap={1}>
|
72
|
+
{faviconUrl && !useFallback ? (
|
73
|
+
<img
|
74
|
+
src={faviconUrl}
|
75
|
+
alt="site icon"
|
76
|
+
style={{ width: 14, height: 14, objectFit: 'contain' }}
|
77
|
+
onError={handleImageError}
|
78
|
+
/>
|
79
|
+
) : (
|
80
|
+
<LinkIcon {...iconSize} />
|
81
|
+
)}
|
82
|
+
<LineText>
|
83
|
+
<Typography
|
84
|
+
component="a"
|
85
|
+
href={value}
|
86
|
+
style={{ textDecoration: 'none' }}
|
87
|
+
target="_blank"
|
88
|
+
variant="body2"
|
89
|
+
color="grey.800"
|
90
|
+
rel="noopener noreferrer">
|
91
|
+
{formatLinkDisplay(value)}
|
92
|
+
</Typography>
|
93
|
+
</LineText>
|
94
|
+
</Box>
|
95
|
+
);
|
96
|
+
}
|
97
|
+
|
98
|
+
function BasicField({ field, value }: { field: string; value: string }) {
|
99
|
+
const Icon = IconMap[field as keyof typeof IconMap];
|
100
|
+
return (
|
101
|
+
<Box key={field} display="flex" alignItems="center" gap={1} className={`user-card__${field}-field`}>
|
102
|
+
{Icon ? <Icon {...iconSize} /> : <IconifyIcon icon={infoCircleIcon} {...iconSize} />}
|
103
|
+
<LineText variant="body2" color="grey.800">
|
104
|
+
{value}
|
105
|
+
</LineText>
|
106
|
+
</Box>
|
107
|
+
);
|
28
108
|
}
|
29
109
|
|
30
|
-
function BasicContent({ user, isFull = false }: BasicContentProps) {
|
110
|
+
function BasicContent({ user, isFull = false, renderFields }: BasicContentProps) {
|
111
|
+
const fields = useCreation(() => {
|
112
|
+
return renderFields ?? ['bio', 'email', 'phone', 'location', 'timezone', 'link'];
|
113
|
+
}, [renderFields]);
|
114
|
+
|
115
|
+
const includeBio = useCreation(() => {
|
116
|
+
return fields.includes('bio');
|
117
|
+
}, [fields]);
|
118
|
+
|
31
119
|
const metadata = useCreation(() => {
|
32
120
|
return (
|
33
121
|
user.metadata ?? {
|
@@ -41,67 +129,113 @@ function BasicContent({ user, isFull = false }: BasicContentProps) {
|
|
41
129
|
);
|
42
130
|
}, [user]);
|
43
131
|
|
44
|
-
|
45
|
-
|
132
|
+
const address = useCreation(() => {
|
133
|
+
return user.address;
|
134
|
+
}, [user.address]);
|
46
135
|
|
47
|
-
const
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
136
|
+
const getFieldValue = useCallback(
|
137
|
+
(field: string) => {
|
138
|
+
if (!field) return '';
|
139
|
+
switch (field) {
|
140
|
+
case 'bio':
|
141
|
+
return user.metadata?.bio || '';
|
142
|
+
case 'email':
|
143
|
+
return metadata.email || user.email || '';
|
144
|
+
case 'phone':
|
145
|
+
return metadata.phone?.phoneNumber || user.phone || '';
|
146
|
+
case 'location':
|
147
|
+
return address?.city || metadata.location || '';
|
148
|
+
case 'timezone':
|
149
|
+
return metadata.timezone || '';
|
150
|
+
case 'link':
|
151
|
+
return metadata.links?.map((link) => link.url).filter(Boolean) || [];
|
152
|
+
default:
|
153
|
+
return user[field as keyof User] || '';
|
154
|
+
}
|
155
|
+
},
|
156
|
+
[user, metadata, address]
|
157
|
+
);
|
158
|
+
|
159
|
+
// 计算实际可见的字段数量
|
160
|
+
const visibleFields = useMemo(() => {
|
161
|
+
return fields.filter((field) => {
|
162
|
+
if (field === 'bio') return false; // bio field is handled separately
|
163
|
+
const value = getFieldValue(field);
|
164
|
+
|
165
|
+
if (value === undefined || value === null || value === '') return false;
|
166
|
+
|
167
|
+
if (isArray(value)) {
|
168
|
+
return value.length > 0;
|
169
|
+
}
|
170
|
+
|
171
|
+
return String(value).trim().length > 0;
|
172
|
+
});
|
173
|
+
}, [fields, getFieldValue]);
|
174
|
+
|
175
|
+
// 判断是否需要使用两列布局
|
176
|
+
const useDoubleColumn = visibleFields.length > 4;
|
177
|
+
|
178
|
+
if (fields.length === 0) {
|
179
|
+
return null;
|
180
|
+
}
|
181
|
+
|
182
|
+
const renderField = (field: string) => {
|
183
|
+
const value = getFieldValue(field);
|
184
|
+
if (!value || field === 'bio') {
|
185
|
+
return null;
|
186
|
+
}
|
187
|
+
|
188
|
+
if (isArray(value)) {
|
189
|
+
return (
|
190
|
+
<Fragment key={field}>
|
191
|
+
{field === 'link' ? (
|
192
|
+
<>
|
193
|
+
{value.map((link) => (
|
194
|
+
<LinkField key={link} value={link} />
|
195
|
+
))}
|
196
|
+
</>
|
197
|
+
) : (
|
198
|
+
<>
|
199
|
+
{value.map((item) => (
|
200
|
+
<BasicField key={item} field={field} value={item} />
|
201
|
+
))}
|
202
|
+
</>
|
203
|
+
)}
|
204
|
+
</Fragment>
|
205
|
+
);
|
206
|
+
}
|
207
|
+
|
208
|
+
if (field === 'timezone') {
|
209
|
+
return <TimeZoneField key={field} value={value as string} />;
|
210
|
+
}
|
211
|
+
|
212
|
+
return <BasicField key={field} field={field} value={value as string} />;
|
56
213
|
};
|
57
214
|
|
58
215
|
return (
|
59
|
-
<Box mt={1} display="flex" flexDirection="column" gap={1.5}>
|
60
|
-
{user.metadata?.bio && (
|
61
|
-
<LineText variant="body2" color="grey.800">
|
216
|
+
<Box mt={1} display="flex" flexDirection="column" gap={1.5} className="user-card__basic-content">
|
217
|
+
{includeBio && user.metadata?.bio && (
|
218
|
+
<LineText variant="body2" color="grey.800" className="user-card__bio-field">
|
62
219
|
{user.metadata.bio}
|
63
220
|
</LineText>
|
64
221
|
)}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
<
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
</Box>
|
83
|
-
)}
|
84
|
-
{metadata.location && (
|
85
|
-
<Box display="flex" alignItems="center" gap={1}>
|
86
|
-
<LocationIcon {...iconSize} />
|
87
|
-
<LineText variant="body2" color="grey.800">
|
88
|
-
{metadata.location}
|
89
|
-
</LineText>
|
90
|
-
</Box>
|
91
|
-
)}
|
92
|
-
|
93
|
-
{isFull && moreContent()}
|
94
|
-
|
95
|
-
{/* 显示邮箱 */}
|
96
|
-
{(metadata.email || user.email) && (
|
97
|
-
<Box display="flex" alignItems="center" gap={1}>
|
98
|
-
<EmailIcon {...iconSize} />
|
99
|
-
<LineText variant="body2" color="grey.800">
|
100
|
-
{metadata.email || user.email}
|
101
|
-
</LineText>
|
102
|
-
</Box>
|
103
|
-
)}
|
104
|
-
</Box>
|
222
|
+
{/* 其他字段 */}
|
223
|
+
{useDoubleColumn ? (
|
224
|
+
<Grid container spacing={0.5}>
|
225
|
+
{fields.map((field) => {
|
226
|
+
if (field === 'bio' || !getFieldValue(field)) return null;
|
227
|
+
return (
|
228
|
+
<Grid item xs={6} key={field}>
|
229
|
+
{renderField(field)}
|
230
|
+
</Grid>
|
231
|
+
);
|
232
|
+
})}
|
233
|
+
</Grid>
|
234
|
+
) : (
|
235
|
+
<Box display="flex" flexDirection="column" gap={0.5}>
|
236
|
+
{fields.map((field) => renderField(field))}
|
237
|
+
</Box>
|
238
|
+
)}
|
105
239
|
</Box>
|
106
240
|
);
|
107
241
|
}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import React, { memo } from 'react';
|
2
2
|
import { Typography, Box } from '@mui/material';
|
3
3
|
import DID from '../../DID';
|
4
|
-
import { UserCardProps } from '../types';
|
4
|
+
import { User, UserCardProps } from '../types';
|
5
5
|
import TooltipAvatar from './tooltip-avatar';
|
6
6
|
import { renderTopRight } from '../components';
|
7
7
|
import ShortenLabel from './shorten-label';
|
8
8
|
|
9
9
|
interface MinimalContentProps extends UserCardProps {
|
10
|
-
user:
|
10
|
+
user: User;
|
11
11
|
avatarSize: number;
|
12
12
|
shouldShowHoverCard: boolean;
|
13
13
|
renderCardContent?: () => React.ReactNode | null;
|
@@ -30,7 +30,7 @@ function MinimalContent(props: MinimalContentProps) {
|
|
30
30
|
} = props;
|
31
31
|
|
32
32
|
return (
|
33
|
-
<Box display="flex" justifyContent="space-between" alignItems="center">
|
33
|
+
<Box display="flex" justifyContent="space-between" alignItems="center" className="user-card__avatar-content">
|
34
34
|
<Box display="flex" justifyContent="flex-start" alignItems="center" gap={2} flex={1} minWidth={0}>
|
35
35
|
<TooltipAvatar
|
36
36
|
user={user}
|
@@ -44,6 +44,7 @@ function MinimalContent(props: MinimalContentProps) {
|
|
44
44
|
variant="subtitle1"
|
45
45
|
fontWeight={500}
|
46
46
|
color="text.primary"
|
47
|
+
className="user-card__full-name-label"
|
47
48
|
fontSize={18}
|
48
49
|
noWrap
|
49
50
|
sx={{ lineHeight: 1.1 }}>
|
@@ -2,11 +2,11 @@ import React from 'react';
|
|
2
2
|
import { Box, Tooltip } from '@mui/material';
|
3
3
|
|
4
4
|
import Zoom from '@mui/material/Zoom';
|
5
|
-
import { UserCardProps } from '../types';
|
5
|
+
import { User, UserCardProps } from '../types';
|
6
6
|
import { renderAvatar } from '../components';
|
7
7
|
|
8
|
-
interface TooltipAvatarProps {
|
9
|
-
user:
|
8
|
+
interface TooltipAvatarProps extends UserCardProps {
|
9
|
+
user: User;
|
10
10
|
avatarSize: number;
|
11
11
|
shouldShowHoverCard: boolean;
|
12
12
|
renderCardContent?: () => React.ReactNode | null;
|
@@ -27,8 +27,13 @@ function TooltipAvatar({
|
|
27
27
|
tooltipTitle,
|
28
28
|
tooltipProps,
|
29
29
|
avatarProps,
|
30
|
+
onAvatarClick,
|
30
31
|
}: TooltipAvatarProps) {
|
31
|
-
const avatarElement =
|
32
|
+
const avatarElement = (
|
33
|
+
<Box display="inline-block">
|
34
|
+
{renderAvatar(user, avatarSize, avatarProps, onAvatarClick, shouldShowHoverCard || !!tooltipTitle)}
|
35
|
+
</Box>
|
36
|
+
);
|
32
37
|
// 使用普通文本Tooltip
|
33
38
|
if (tooltipTitle) {
|
34
39
|
return (
|
@@ -52,7 +57,7 @@ function TooltipAvatar({
|
|
52
57
|
'& .MuiTooltip-tooltip': {
|
53
58
|
backgroundColor: 'transparent',
|
54
59
|
p: 0,
|
55
|
-
maxWidth:
|
60
|
+
maxWidth: 500,
|
56
61
|
zIndex: 1000,
|
57
62
|
},
|
58
63
|
},
|
@@ -1,27 +1,32 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { Box } from '@mui/material';
|
3
3
|
import Avatar from '../Avatar';
|
4
|
-
import { UserCardProps } from './types';
|
4
|
+
import { User, UserCardProps } from './types';
|
5
5
|
import { createNameOnlyAvatar } from './utils';
|
6
6
|
|
7
7
|
// 渲染头像
|
8
8
|
export const renderAvatar = (
|
9
|
-
user:
|
9
|
+
user: User,
|
10
10
|
avatarSize: number = 48,
|
11
|
-
avatarProps: UserCardProps['avatarProps'] = undefined
|
11
|
+
avatarProps: UserCardProps['avatarProps'] = undefined,
|
12
|
+
onAvatarClick: UserCardProps['onAvatarClick'] = undefined,
|
13
|
+
shouldShowHoverCard: boolean = false
|
12
14
|
) => {
|
15
|
+
const onClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
16
|
+
onAvatarClick?.(user, e);
|
17
|
+
};
|
13
18
|
// 如果用户没有头像,则显示名称首字母头像
|
14
19
|
if (!user.avatar) {
|
15
20
|
const avatarContent = createNameOnlyAvatar(user);
|
16
|
-
|
17
21
|
return (
|
18
22
|
<Avatar
|
19
23
|
size={avatarSize}
|
20
24
|
did={user.did}
|
21
25
|
variant="circle"
|
26
|
+
onClick={onClick}
|
22
27
|
sx={{
|
23
28
|
fontSize: avatarSize * 0.4,
|
24
|
-
cursor: 'pointer',
|
29
|
+
cursor: shouldShowHoverCard || onAvatarClick ? 'pointer' : 'default',
|
25
30
|
}}
|
26
31
|
{...(avatarProps || {})}>
|
27
32
|
{avatarContent}
|
@@ -36,8 +41,9 @@ export const renderAvatar = (
|
|
36
41
|
did={user.did}
|
37
42
|
variant="circle"
|
38
43
|
style={{
|
39
|
-
cursor: 'pointer',
|
44
|
+
cursor: shouldShowHoverCard || onAvatarClick ? 'pointer' : 'default',
|
40
45
|
}}
|
46
|
+
onClick={onClick}
|
41
47
|
src={user.avatar}
|
42
48
|
alt={user.fullName || ''}
|
43
49
|
{...(avatarProps || {})}
|
@@ -51,7 +57,11 @@ export const renderTopRight = (
|
|
51
57
|
topRightMaxWidth: number = 120
|
52
58
|
) => {
|
53
59
|
if (renderTopRightContent) {
|
54
|
-
return
|
60
|
+
return (
|
61
|
+
<Box sx={{ maxWidth: topRightMaxWidth }} className="user-card__top-right-content">
|
62
|
+
{renderTopRightContent()}
|
63
|
+
</Box>
|
64
|
+
);
|
55
65
|
}
|
56
66
|
|
57
67
|
return null;
|
package/src/UserCard/index.tsx
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
import { useRef } from 'react';
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
2
|
+
import { toTypeInfo } from '@arcblock/did';
|
2
3
|
import type { User } from './types';
|
3
4
|
import { UserCardProps, CardType } from './types';
|
4
5
|
import AvatarOnlyCard from './Cards/avatar-only';
|
5
6
|
import DetailedCard from './Cards';
|
6
7
|
import DialogContainer from './Container/dialog';
|
7
8
|
import CardContainer from './Container/card';
|
9
|
+
import Avatar from '../Avatar';
|
10
|
+
import { getUserByDid, isUserDid } from './utils';
|
8
11
|
|
9
12
|
// 创建仅显示名称首字母的头像
|
10
13
|
export function createNameOnlyAvatar(user: User) {
|
@@ -35,7 +38,30 @@ function UserCard(props: UserCardProps) {
|
|
35
38
|
const shouldShowHoverCard = showHoverCard !== undefined ? showHoverCard : cardType === CardType.AvatarOnly;
|
36
39
|
|
37
40
|
const containerRef = useRef<HTMLDivElement>(null);
|
41
|
+
const [user, setUser] = useState<User | null>(null);
|
38
42
|
|
43
|
+
useEffect(() => {
|
44
|
+
let isSubscribed = true;
|
45
|
+
if (props.user) {
|
46
|
+
setUser(props.user);
|
47
|
+
} else if (props.did && isUserDid(props.did) && !props.user) {
|
48
|
+
getUserByDid(props.did).then((_user) => {
|
49
|
+
if (isSubscribed) {
|
50
|
+
setUser(_user);
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
return () => {
|
55
|
+
isSubscribed = false;
|
56
|
+
};
|
57
|
+
}, [props.did, props.user]);
|
58
|
+
|
59
|
+
// 如果不存在,则使用 did 渲染头像
|
60
|
+
if (!user) {
|
61
|
+
return <Avatar did={props.did} size={props.avatarSize} {...props.avatarProps} />;
|
62
|
+
}
|
63
|
+
|
64
|
+
// user 存在,则使用 user 渲染头像
|
39
65
|
// 渲染卡片内容(用于Tooltip)
|
40
66
|
const renderCardContent = () => {
|
41
67
|
const _avatarProps = props.popupAvatarProps || props.avatarProps;
|
@@ -45,8 +71,10 @@ function UserCard(props: UserCardProps) {
|
|
45
71
|
<DetailedCard
|
46
72
|
{...props}
|
47
73
|
shouldShowHoverCard={false}
|
74
|
+
user={user!}
|
48
75
|
avatarProps={_avatarProps}
|
49
76
|
shortenLabelProps={_shortenLabelProps}
|
77
|
+
renderFields={props.popupRenderFields}
|
50
78
|
/>
|
51
79
|
</DialogContainer>
|
52
80
|
);
|
@@ -55,14 +83,24 @@ function UserCard(props: UserCardProps) {
|
|
55
83
|
// 根据卡片类型选择合适的组件
|
56
84
|
if (cardType === CardType.AvatarOnly) {
|
57
85
|
return (
|
58
|
-
<AvatarOnlyCard
|
86
|
+
<AvatarOnlyCard
|
87
|
+
{...props}
|
88
|
+
shouldShowHoverCard={shouldShowHoverCard}
|
89
|
+
renderCardContent={renderCardContent}
|
90
|
+
user={user!}
|
91
|
+
/>
|
59
92
|
);
|
60
93
|
}
|
61
94
|
|
62
95
|
// 详细卡片模式
|
63
96
|
return (
|
64
97
|
<CardContainer containerRef={containerRef} cardType={cardType} sx={props.sx}>
|
65
|
-
<DetailedCard
|
98
|
+
<DetailedCard
|
99
|
+
{...props}
|
100
|
+
shouldShowHoverCard={shouldShowHoverCard}
|
101
|
+
renderCardContent={renderCardContent}
|
102
|
+
user={user!}
|
103
|
+
/>
|
66
104
|
</CardContainer>
|
67
105
|
);
|
68
106
|
}
|
package/src/UserCard/types.ts
CHANGED
@@ -64,7 +64,6 @@ export type UserAddress = {
|
|
64
64
|
};
|
65
65
|
|
66
66
|
export type User = UserPublicInfo & {
|
67
|
-
role: string;
|
68
67
|
email?: string;
|
69
68
|
phone?: string;
|
70
69
|
sourceProvider?: string;
|
@@ -76,7 +75,7 @@ export type User = UserPublicInfo & {
|
|
76
75
|
didSpace?: Record<string, any>;
|
77
76
|
connectedAccounts?: any[];
|
78
77
|
locale?: string;
|
79
|
-
url
|
78
|
+
url?: string;
|
80
79
|
inviter?: string;
|
81
80
|
emailVerified?: boolean;
|
82
81
|
phoneVerified?: boolean;
|
@@ -109,7 +108,8 @@ export enum InfoType {
|
|
109
108
|
|
110
109
|
// 定义UserCard属性接口
|
111
110
|
export interface UserCardProps {
|
112
|
-
user
|
111
|
+
user?: User;
|
112
|
+
did?: string;
|
113
113
|
cardType?: CardType;
|
114
114
|
infoType?: InfoType;
|
115
115
|
avatarSize?: number;
|
@@ -121,7 +121,7 @@ export interface UserCardProps {
|
|
121
121
|
popupAvatarProps?: Partial<AvatarProps>;
|
122
122
|
|
123
123
|
// 弹出层相关属性
|
124
|
-
tooltipProps?:
|
124
|
+
tooltipProps?: Partial<TooltipProps>;
|
125
125
|
|
126
126
|
// 样式相关属性
|
127
127
|
sx?: SxProps<Theme>;
|
@@ -131,10 +131,17 @@ export interface UserCardProps {
|
|
131
131
|
shortenLabelProps?: Partial<ShortenLabelProps>;
|
132
132
|
popupShortenLabelProps?: Partial<ShortenLabelProps>;
|
133
133
|
|
134
|
+
// 自定义渲染字段
|
135
|
+
renderFields?: string[];
|
136
|
+
popupRenderFields?: string[];
|
137
|
+
|
134
138
|
// 右上角内容相关属性
|
135
139
|
renderTopRightContent?: () => React.ReactNode;
|
136
140
|
topRightMaxWidth?: number;
|
137
141
|
|
138
142
|
// 自定义内容渲染函数
|
139
143
|
renderCustomContent?: () => React.ReactNode;
|
144
|
+
|
145
|
+
// 头像点击事件
|
146
|
+
onAvatarClick?: (user: User, e?: React.MouseEvent<HTMLDivElement>) => void;
|
140
147
|
}
|
package/src/UserCard/utils.ts
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
import { toTypeInfo } from '@arcblock/did';
|
2
|
+
import { types } from '@ocap/mcrypto';
|
3
|
+
import { BlockletSDK } from '@blocklet/js-sdk';
|
1
4
|
import { User } from './types';
|
2
5
|
|
6
|
+
let client: BlockletSDK | null = null;
|
7
|
+
try {
|
8
|
+
client = new BlockletSDK();
|
9
|
+
} catch (error) {
|
10
|
+
console.error('Failed to initialize BlockletSDK:', error);
|
11
|
+
client = null;
|
12
|
+
}
|
13
|
+
|
3
14
|
// 创建仅显示名称首字母的头像
|
4
15
|
// eslint-disable-next-line import/prefer-default-export
|
5
16
|
export function createNameOnlyAvatar(user: User) {
|
@@ -20,3 +31,25 @@ export function createNameOnlyAvatar(user: User) {
|
|
20
31
|
|
21
32
|
return content;
|
22
33
|
}
|
34
|
+
|
35
|
+
export function isUserDid(did: string) {
|
36
|
+
if (!did || typeof did !== 'string') return false;
|
37
|
+
try {
|
38
|
+
const didInfo = toTypeInfo(did);
|
39
|
+
return didInfo.role !== undefined && didInfo.role !== types.RoleType.ROLE_APPLICATION;
|
40
|
+
} catch (error) {
|
41
|
+
console.error('Failed to check if did is user did:', error);
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
export async function getUserByDid(did: string): Promise<User | null> {
|
47
|
+
if (!client) return null;
|
48
|
+
try {
|
49
|
+
const user = await client.user.getUserPublicInfo({ did });
|
50
|
+
return user as User;
|
51
|
+
} catch (error) {
|
52
|
+
console.error('Failed to get user by did:', error);
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
}
|
package/src/type.d.ts
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
import type { Theme } from '@mui/material';
|
1
|
+
import type { Theme, PaletteMode } from '@mui/material';
|
2
2
|
import type { LiteralUnion } from 'type-fest';
|
3
3
|
|
4
4
|
export type $TSFixMe = any;
|
5
5
|
export type Translations = Record<string, Record<string, any>>;
|
6
6
|
export type Locale = LiteralUnion<'en' | 'zh', string>;
|
7
|
-
export type ThemeMode = 'light' | 'dark';
|
8
7
|
|
9
8
|
// TODO: 以下为 blocklet 应用专属的全局对象类型,可以更加具体
|
10
9
|
export type User = Record<string, any>;
|
@@ -26,7 +25,7 @@ export type Blocklet = {
|
|
26
25
|
version: string;
|
27
26
|
mode: string;
|
28
27
|
tenantMode: 'single' | 'multiple';
|
29
|
-
theme: Record<
|
28
|
+
theme: Record<PaletteMode, Theme>;
|
30
29
|
navigation: $TSFixMe[];
|
31
30
|
preferences: Record<string, any>;
|
32
31
|
languages: {
|
package/src/withTheme/index.tsx
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
import { useEffect } from 'react';
|
2
2
|
import { Global, css } from '@emotion/react';
|
3
3
|
import CssBaseline from '@mui/material/CssBaseline';
|
4
|
-
import { Breakpoint } from '@mui/material';
|
4
|
+
import { Breakpoint, type PaletteMode } from '@mui/material';
|
5
5
|
import { type PaletteOptions } from '@mui/material/styles/createPalette';
|
6
6
|
import { type TypographyOptions } from '@mui/material/styles/createTypography';
|
7
7
|
|
8
8
|
import { createTheme, ThemeProvider } from '../Theme';
|
9
|
-
import { ThemeMode } from '../type';
|
10
9
|
|
11
10
|
function withTheme<P extends object>(
|
12
11
|
Component: React.ComponentType<P>,
|
@@ -15,7 +14,7 @@ function withTheme<P extends object>(
|
|
15
14
|
pageWidth = 'md',
|
16
15
|
palette,
|
17
16
|
typography,
|
18
|
-
}: { mode?:
|
17
|
+
}: { mode?: PaletteMode; pageWidth?: Breakpoint; palette?: PaletteOptions; typography?: TypographyOptions } = {}
|
19
18
|
) {
|
20
19
|
const theme = createTheme({ mode, pageWidth, palette, typography });
|
21
20
|
|