@arcblock/ux 2.13.1 → 2.13.3
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/UserCard/Cards/basic-info.d.ts +0 -1
- package/lib/UserCard/Cards/basic-info.js +2 -14
- package/lib/UserCard/Container/dialog.js +1 -1
- package/lib/UserCard/Content/basic.js +11 -23
- package/lib/UserCard/Content/minimal.d.ts +4 -7
- package/lib/UserCard/Content/minimal.js +7 -2
- package/lib/UserCard/Content/shorten-label.d.ts +9 -0
- package/lib/UserCard/Content/shorten-label.js +37 -0
- package/lib/UserCard/components.d.ts +1 -1
- package/lib/UserCard/components.js +1 -1
- package/lib/UserCard/index.js +4 -2
- package/lib/UserCard/types.d.ts +4 -1
- package/package.json +5 -5
- package/src/UserCard/Cards/basic-info.tsx +2 -27
- package/src/UserCard/Container/dialog.tsx +1 -1
- package/src/UserCard/Content/basic.tsx +16 -30
- package/src/UserCard/Content/minimal.tsx +7 -8
- package/src/UserCard/Content/shorten-label.tsx +32 -0
- package/src/UserCard/components.tsx +1 -1
- package/src/UserCard/index.tsx +8 -2
- package/src/UserCard/types.ts +6 -1
@@ -4,7 +4,6 @@ interface BasicCardProps extends UserCardProps {
|
|
4
4
|
shouldShowHoverCard: boolean;
|
5
5
|
renderCardContent?: () => React.ReactNode | null;
|
6
6
|
isFull?: boolean;
|
7
|
-
avatarProps?: UserCardProps['avatarProps'];
|
8
7
|
}
|
9
8
|
declare function BasicCard(props: BasicCardProps): import("react/jsx-runtime").JSX.Element;
|
10
9
|
export default BasicCard;
|
@@ -9,16 +9,10 @@ function BasicCard(props) {
|
|
9
9
|
const {
|
10
10
|
user,
|
11
11
|
avatarSize = 40,
|
12
|
-
showDid = false,
|
13
|
-
didProps = {},
|
14
|
-
shouldShowHoverCard,
|
15
|
-
renderCardContent,
|
16
|
-
renderTopRightContent,
|
17
|
-
topRightMaxWidth = 100,
|
18
12
|
renderCustomContent,
|
19
13
|
isFull = true,
|
20
14
|
infoType = InfoType.Minimal,
|
21
|
-
|
15
|
+
...rest
|
22
16
|
} = props;
|
23
17
|
return /*#__PURE__*/_jsxs(Box, {
|
24
18
|
display: "flex",
|
@@ -30,14 +24,8 @@ function BasicCard(props) {
|
|
30
24
|
},
|
31
25
|
children: [/*#__PURE__*/_jsx(MinimalContent, {
|
32
26
|
user: user,
|
33
|
-
showDid: showDid,
|
34
|
-
didProps: didProps,
|
35
27
|
avatarSize: avatarSize,
|
36
|
-
|
37
|
-
shouldShowHoverCard: shouldShowHoverCard,
|
38
|
-
renderCardContent: renderCardContent,
|
39
|
-
renderTopRightContent: renderTopRightContent,
|
40
|
-
topRightMaxWidth: topRightMaxWidth
|
28
|
+
...rest
|
41
29
|
}), infoType === InfoType.Basic && /*#__PURE__*/_jsx(BasicContent, {
|
42
30
|
user: user,
|
43
31
|
isFull: isFull
|
@@ -44,7 +44,7 @@ function BasicContent({
|
|
44
44
|
gap: 1,
|
45
45
|
children: [/*#__PURE__*/_jsx(TimezoneIcon, {
|
46
46
|
...iconSize
|
47
|
-
}), /*#__PURE__*/_jsx(
|
47
|
+
}), /*#__PURE__*/_jsx(LineText, {
|
48
48
|
variant: "body2",
|
49
49
|
color: "grey.800",
|
50
50
|
children: /*#__PURE__*/_jsx(Clock, {
|
@@ -60,17 +60,9 @@ function BasicContent({
|
|
60
60
|
display: "flex",
|
61
61
|
flexDirection: "column",
|
62
62
|
gap: 1.5,
|
63
|
-
children: [user.metadata?.bio && /*#__PURE__*/_jsx(
|
63
|
+
children: [user.metadata?.bio && /*#__PURE__*/_jsx(LineText, {
|
64
64
|
variant: "body2",
|
65
65
|
color: "grey.800",
|
66
|
-
sx: {
|
67
|
-
lineHeight: 1.5,
|
68
|
-
display: '-webkit-box',
|
69
|
-
WebkitLineClamp: 1,
|
70
|
-
WebkitBoxOrient: 'vertical',
|
71
|
-
overflow: 'hidden',
|
72
|
-
textOverflow: 'ellipsis'
|
73
|
-
},
|
74
66
|
children: user.metadata.bio
|
75
67
|
}), /*#__PURE__*/_jsxs(Box, {
|
76
68
|
display: "flex",
|
@@ -82,7 +74,7 @@ function BasicContent({
|
|
82
74
|
gap: 1,
|
83
75
|
children: [/*#__PURE__*/_jsx(LinkIcon, {
|
84
76
|
...iconSize
|
85
|
-
}), /*#__PURE__*/_jsx(
|
77
|
+
}), /*#__PURE__*/_jsx(LineText, {
|
86
78
|
children: /*#__PURE__*/_jsx(Typography, {
|
87
79
|
component: "a",
|
88
80
|
href: firstLink.url,
|
@@ -102,7 +94,7 @@ function BasicContent({
|
|
102
94
|
gap: 1,
|
103
95
|
children: [/*#__PURE__*/_jsx(LocationIcon, {
|
104
96
|
...iconSize
|
105
|
-
}), /*#__PURE__*/_jsx(
|
97
|
+
}), /*#__PURE__*/_jsx(LineText, {
|
106
98
|
variant: "body2",
|
107
99
|
color: "grey.800",
|
108
100
|
children: metadata.location
|
@@ -113,7 +105,7 @@ function BasicContent({
|
|
113
105
|
gap: 1,
|
114
106
|
children: [/*#__PURE__*/_jsx(EmailIcon, {
|
115
107
|
...iconSize
|
116
|
-
}), /*#__PURE__*/_jsx(
|
108
|
+
}), /*#__PURE__*/_jsx(LineText, {
|
117
109
|
variant: "body2",
|
118
110
|
color: "grey.800",
|
119
111
|
children: metadata.email || user.email
|
@@ -123,17 +115,13 @@ function BasicContent({
|
|
123
115
|
});
|
124
116
|
}
|
125
117
|
export default BasicContent;
|
126
|
-
const
|
118
|
+
const LineText = styled(Typography)`
|
127
119
|
flex: 1;
|
128
|
-
|
120
|
+
display: -webkit-box;
|
121
|
+
line-height: 1.5;
|
122
|
+
-webkit-line-clamp: 1;
|
123
|
+
-webkit-box-orient: vertical;
|
129
124
|
overflow: hidden;
|
130
125
|
text-overflow: ellipsis;
|
131
|
-
|
132
|
-
& > * {
|
133
|
-
word-break: break-all;
|
134
|
-
}
|
135
|
-
|
136
|
-
.status {
|
137
|
-
margin-left: 8px;
|
138
|
-
}
|
126
|
+
word-break: break-word;
|
139
127
|
`;
|
@@ -1,15 +1,12 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import {
|
3
|
-
interface MinimalContentProps {
|
4
|
-
user:
|
5
|
-
showDid: boolean;
|
2
|
+
import { UserCardProps } from '../types';
|
3
|
+
interface MinimalContentProps extends UserCardProps {
|
4
|
+
user: UserCardProps['user'];
|
6
5
|
avatarSize: number;
|
7
6
|
shouldShowHoverCard: boolean;
|
8
7
|
renderCardContent?: () => React.ReactNode | null;
|
9
|
-
didProps: Record<string, any>;
|
10
|
-
renderTopRightContent?: () => React.ReactNode;
|
11
|
-
topRightMaxWidth: number;
|
12
8
|
avatarProps?: UserCardProps['avatarProps'];
|
9
|
+
shortenLabelProps?: UserCardProps['shortenLabelProps'];
|
13
10
|
}
|
14
11
|
declare function MinimalContent(props: MinimalContentProps): import("react/jsx-runtime").JSX.Element;
|
15
12
|
declare const _default: React.MemoExoticComponent<typeof MinimalContent>;
|
@@ -4,6 +4,7 @@ import { Typography, Box } from '@mui/material';
|
|
4
4
|
import DID from '../../DID';
|
5
5
|
import TooltipAvatar from './tooltip-avatar';
|
6
6
|
import { renderTopRight } from '../components';
|
7
|
+
import ShortenLabel from './shorten-label';
|
7
8
|
function MinimalContent(props) {
|
8
9
|
const {
|
9
10
|
user,
|
@@ -14,7 +15,8 @@ function MinimalContent(props) {
|
|
14
15
|
renderCardContent,
|
15
16
|
renderTopRightContent,
|
16
17
|
topRightMaxWidth,
|
17
|
-
avatarProps
|
18
|
+
avatarProps,
|
19
|
+
shortenLabelProps
|
18
20
|
} = props;
|
19
21
|
return /*#__PURE__*/_jsxs(Box, {
|
20
22
|
display: "flex",
|
@@ -43,7 +45,10 @@ function MinimalContent(props) {
|
|
43
45
|
sx: {
|
44
46
|
lineHeight: 1.1
|
45
47
|
},
|
46
|
-
children:
|
48
|
+
children: /*#__PURE__*/_jsx(ShortenLabel, {
|
49
|
+
...shortenLabelProps,
|
50
|
+
children: user.fullName || user.email || user.did
|
51
|
+
})
|
47
52
|
}), showDid && user.did ? /*#__PURE__*/_jsx(DID, {
|
48
53
|
did: user.did,
|
49
54
|
size: 14,
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { TypographyProps } from '@mui/material';
|
2
|
+
export interface ShortenLabelProps {
|
3
|
+
children: string;
|
4
|
+
maxLength?: number;
|
5
|
+
sx?: TypographyProps['sx'];
|
6
|
+
hiddenTip?: boolean;
|
7
|
+
}
|
8
|
+
declare function ShortenLabel({ children, maxLength, sx, hiddenTip }: ShortenLabelProps): import("react/jsx-runtime").JSX.Element;
|
9
|
+
export default ShortenLabel;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { Tooltip, Typography } from '@mui/material';
|
3
|
+
import { useMemo } from 'react';
|
4
|
+
function shortenString(str, maxLength = 10) {
|
5
|
+
if (!str) return '';
|
6
|
+
if (str.length <= maxLength) return str;
|
7
|
+
return `${str.slice(0, maxLength - 1)}...${str.slice(-2)}`;
|
8
|
+
}
|
9
|
+
function ShortenLabel({
|
10
|
+
children,
|
11
|
+
maxLength = 10,
|
12
|
+
sx = undefined,
|
13
|
+
hiddenTip = false
|
14
|
+
}) {
|
15
|
+
const shortenedText = useMemo(() => shortenString(children, maxLength), [children, maxLength]);
|
16
|
+
if (children?.length <= maxLength) {
|
17
|
+
return /*#__PURE__*/_jsx(Typography, {
|
18
|
+
sx: sx,
|
19
|
+
children: children
|
20
|
+
});
|
21
|
+
}
|
22
|
+
if (hiddenTip) {
|
23
|
+
return /*#__PURE__*/_jsx(Typography, {
|
24
|
+
sx: sx,
|
25
|
+
children: shortenedText
|
26
|
+
});
|
27
|
+
}
|
28
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
29
|
+
title: children,
|
30
|
+
placement: "top",
|
31
|
+
children: /*#__PURE__*/_jsx(Typography, {
|
32
|
+
sx: sx,
|
33
|
+
children: shortenedText
|
34
|
+
})
|
35
|
+
});
|
36
|
+
}
|
37
|
+
export default ShortenLabel;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { UserCardProps } from './types';
|
3
3
|
export declare const renderAvatar: (user: UserCardProps["user"], avatarSize?: number, avatarProps?: UserCardProps["avatarProps"]) => import("react/jsx-runtime").JSX.Element;
|
4
|
-
export declare const renderTopRight: (renderTopRightContent: (() => React.ReactNode) | undefined, topRightMaxWidth
|
4
|
+
export declare const renderTopRight: (renderTopRightContent: (() => React.ReactNode) | undefined, topRightMaxWidth?: number) => import("react/jsx-runtime").JSX.Element | null;
|
@@ -37,7 +37,7 @@ export const renderAvatar = (user, avatarSize = 48, avatarProps = undefined) =>
|
|
37
37
|
};
|
38
38
|
|
39
39
|
// 渲染右上角内容
|
40
|
-
export const renderTopRight = (renderTopRightContent, topRightMaxWidth) => {
|
40
|
+
export const renderTopRight = (renderTopRightContent, topRightMaxWidth = 120) => {
|
41
41
|
if (renderTopRightContent) {
|
42
42
|
return /*#__PURE__*/_jsx(Box, {
|
43
43
|
sx: {
|
package/lib/UserCard/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import
|
2
|
+
import { useRef } from 'react';
|
3
3
|
import { CardType } from './types';
|
4
4
|
import AvatarOnlyCard from './Cards/avatar-only';
|
5
5
|
import DetailedCard from './Cards';
|
@@ -40,12 +40,14 @@ function UserCard(props) {
|
|
40
40
|
// 渲染卡片内容(用于Tooltip)
|
41
41
|
const renderCardContent = () => {
|
42
42
|
const _avatarProps = props.popupAvatarProps || props.avatarProps;
|
43
|
+
const _shortenLabelProps = props.popupShortenLabelProps || props.shortenLabelProps;
|
43
44
|
return /*#__PURE__*/_jsx(DialogContainer, {
|
44
45
|
sx: props.popupSx,
|
45
46
|
children: /*#__PURE__*/_jsx(DetailedCard, {
|
46
47
|
...props,
|
47
48
|
shouldShowHoverCard: false,
|
48
|
-
avatarProps: _avatarProps
|
49
|
+
avatarProps: _avatarProps,
|
50
|
+
shortenLabelProps: _shortenLabelProps
|
49
51
|
})
|
50
52
|
});
|
51
53
|
};
|
package/lib/UserCard/types.d.ts
CHANGED
@@ -2,6 +2,7 @@ import React from 'react';
|
|
2
2
|
import { SxProps, Theme, TooltipProps } from '@mui/material';
|
3
3
|
import { DIDProps } from '../DID';
|
4
4
|
import { AvatarProps } from '../Avatar';
|
5
|
+
import { ShortenLabelProps } from './Content/shorten-label';
|
5
6
|
type UserPublicInfo = {
|
6
7
|
avatar: string;
|
7
8
|
did: string;
|
@@ -97,12 +98,14 @@ export interface UserCardProps {
|
|
97
98
|
avatarSize?: number;
|
98
99
|
showHoverCard?: boolean;
|
99
100
|
showDid?: boolean;
|
100
|
-
didProps?: DIDProps
|
101
|
+
didProps?: Partial<DIDProps>;
|
101
102
|
avatarProps?: Partial<AvatarProps>;
|
102
103
|
popupAvatarProps?: Partial<AvatarProps>;
|
103
104
|
tooltipProps?: Omit<TooltipProps, 'title'>;
|
104
105
|
sx?: SxProps<Theme>;
|
105
106
|
popupSx?: SxProps<Theme>;
|
107
|
+
shortenLabelProps?: Partial<ShortenLabelProps>;
|
108
|
+
popupShortenLabelProps?: Partial<ShortenLabelProps>;
|
106
109
|
renderTopRightContent?: () => React.ReactNode;
|
107
110
|
topRightMaxWidth?: number;
|
108
111
|
renderCustomContent?: () => React.ReactNode;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.13.
|
3
|
+
"version": "2.13.3",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -70,12 +70,12 @@
|
|
70
70
|
"react": ">=18.2.0",
|
71
71
|
"react-router-dom": ">=6.22.3"
|
72
72
|
},
|
73
|
-
"gitHead": "
|
73
|
+
"gitHead": "22439fa4a1d2b412279cbb61eadb1981f62dc7a5",
|
74
74
|
"dependencies": {
|
75
75
|
"@arcblock/did-motif": "^1.1.13",
|
76
|
-
"@arcblock/icons": "^2.13.
|
77
|
-
"@arcblock/nft-display": "^2.13.
|
78
|
-
"@arcblock/react-hooks": "^2.13.
|
76
|
+
"@arcblock/icons": "^2.13.3",
|
77
|
+
"@arcblock/nft-display": "^2.13.3",
|
78
|
+
"@arcblock/react-hooks": "^2.13.3",
|
79
79
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
80
80
|
"@fontsource/roboto": "~5.1.1",
|
81
81
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { Box } from '@mui/material';
|
3
3
|
import { InfoType, UserCardProps } from '../types';
|
4
|
-
import LeftLayout from '../Content/left-layout';
|
5
4
|
import MinimalContent from '../Content/minimal';
|
6
5
|
import BasicContent from '../Content/basic';
|
7
6
|
|
@@ -9,39 +8,15 @@ interface BasicCardProps extends UserCardProps {
|
|
9
8
|
shouldShowHoverCard: boolean;
|
10
9
|
renderCardContent?: () => React.ReactNode | null;
|
11
10
|
isFull?: boolean;
|
12
|
-
avatarProps?: UserCardProps['avatarProps'];
|
13
11
|
}
|
14
12
|
|
15
13
|
// 详细卡片模式下的Basic渲染组件
|
16
14
|
function BasicCard(props: BasicCardProps) {
|
17
|
-
const {
|
18
|
-
user,
|
19
|
-
avatarSize = 40,
|
20
|
-
showDid = false,
|
21
|
-
didProps = {},
|
22
|
-
shouldShowHoverCard,
|
23
|
-
renderCardContent,
|
24
|
-
renderTopRightContent,
|
25
|
-
topRightMaxWidth = 100,
|
26
|
-
renderCustomContent,
|
27
|
-
isFull = true,
|
28
|
-
infoType = InfoType.Minimal,
|
29
|
-
avatarProps,
|
30
|
-
} = props;
|
15
|
+
const { user, avatarSize = 40, renderCustomContent, isFull = true, infoType = InfoType.Minimal, ...rest } = props;
|
31
16
|
|
32
17
|
return (
|
33
18
|
<Box display="flex" flexDirection="column" width="100%" sx={{ flex: 1, minWidth: 0 }}>
|
34
|
-
<MinimalContent
|
35
|
-
user={user}
|
36
|
-
showDid={showDid}
|
37
|
-
didProps={didProps}
|
38
|
-
avatarSize={avatarSize}
|
39
|
-
avatarProps={avatarProps}
|
40
|
-
shouldShowHoverCard={shouldShowHoverCard}
|
41
|
-
renderCardContent={renderCardContent}
|
42
|
-
renderTopRightContent={renderTopRightContent}
|
43
|
-
topRightMaxWidth={topRightMaxWidth}
|
44
|
-
/>
|
19
|
+
<MinimalContent user={user} avatarSize={avatarSize} {...rest} />
|
45
20
|
|
46
21
|
{infoType === InfoType.Basic && <BasicContent user={user} isFull={isFull} />}
|
47
22
|
{renderCustomContent && <Box sx={{ mt: 1.5 }}>{renderCustomContent()}</Box>}
|
@@ -48,9 +48,9 @@ function BasicContent({ user, isFull = false }: BasicContentProps) {
|
|
48
48
|
return metadata.timezone ? (
|
49
49
|
<Box display="flex" alignItems="center" gap={1}>
|
50
50
|
<TimezoneIcon {...iconSize} />
|
51
|
-
<
|
51
|
+
<LineText variant="body2" color="grey.800">
|
52
52
|
<Clock value={metadata.timezone} variant="body2" color="grey.800" />
|
53
|
-
</
|
53
|
+
</LineText>
|
54
54
|
</Box>
|
55
55
|
) : null;
|
56
56
|
};
|
@@ -58,26 +58,16 @@ function BasicContent({ user, isFull = false }: BasicContentProps) {
|
|
58
58
|
return (
|
59
59
|
<Box mt={1} display="flex" flexDirection="column" gap={1.5}>
|
60
60
|
{user.metadata?.bio && (
|
61
|
-
<
|
62
|
-
variant="body2"
|
63
|
-
color="grey.800"
|
64
|
-
sx={{
|
65
|
-
lineHeight: 1.5,
|
66
|
-
display: '-webkit-box',
|
67
|
-
WebkitLineClamp: 1,
|
68
|
-
WebkitBoxOrient: 'vertical',
|
69
|
-
overflow: 'hidden',
|
70
|
-
textOverflow: 'ellipsis',
|
71
|
-
}}>
|
61
|
+
<LineText variant="body2" color="grey.800">
|
72
62
|
{user.metadata.bio}
|
73
|
-
</
|
63
|
+
</LineText>
|
74
64
|
)}
|
75
65
|
<Box display="flex" flexDirection="column" gap={0.5}>
|
76
66
|
{/* 显示第一个链接(如果有) */}
|
77
67
|
{firstLink && (
|
78
68
|
<Box display="flex" alignItems="center" gap={1}>
|
79
69
|
<LinkIcon {...iconSize} />
|
80
|
-
<
|
70
|
+
<LineText>
|
81
71
|
<Typography
|
82
72
|
component="a"
|
83
73
|
href={firstLink.url}
|
@@ -88,15 +78,15 @@ function BasicContent({ user, isFull = false }: BasicContentProps) {
|
|
88
78
|
rel="noopener noreferrer">
|
89
79
|
{formatLinkDisplay(firstLink.url)}
|
90
80
|
</Typography>
|
91
|
-
</
|
81
|
+
</LineText>
|
92
82
|
</Box>
|
93
83
|
)}
|
94
84
|
{metadata.location && (
|
95
85
|
<Box display="flex" alignItems="center" gap={1}>
|
96
86
|
<LocationIcon {...iconSize} />
|
97
|
-
<
|
87
|
+
<LineText variant="body2" color="grey.800">
|
98
88
|
{metadata.location}
|
99
|
-
</
|
89
|
+
</LineText>
|
100
90
|
</Box>
|
101
91
|
)}
|
102
92
|
|
@@ -106,9 +96,9 @@ function BasicContent({ user, isFull = false }: BasicContentProps) {
|
|
106
96
|
{(metadata.email || user.email) && (
|
107
97
|
<Box display="flex" alignItems="center" gap={1}>
|
108
98
|
<EmailIcon {...iconSize} />
|
109
|
-
<
|
99
|
+
<LineText variant="body2" color="grey.800">
|
110
100
|
{metadata.email || user.email}
|
111
|
-
</
|
101
|
+
</LineText>
|
112
102
|
</Box>
|
113
103
|
)}
|
114
104
|
</Box>
|
@@ -118,17 +108,13 @@ function BasicContent({ user, isFull = false }: BasicContentProps) {
|
|
118
108
|
|
119
109
|
export default BasicContent;
|
120
110
|
|
121
|
-
const
|
111
|
+
const LineText = styled(Typography)`
|
122
112
|
flex: 1;
|
123
|
-
|
113
|
+
display: -webkit-box;
|
114
|
+
line-height: 1.5;
|
115
|
+
-webkit-line-clamp: 1;
|
116
|
+
-webkit-box-orient: vertical;
|
124
117
|
overflow: hidden;
|
125
118
|
text-overflow: ellipsis;
|
126
|
-
|
127
|
-
& > * {
|
128
|
-
word-break: break-all;
|
129
|
-
}
|
130
|
-
|
131
|
-
.status {
|
132
|
-
margin-left: 8px;
|
133
|
-
}
|
119
|
+
word-break: break-word;
|
134
120
|
`;
|
@@ -1,20 +1,18 @@
|
|
1
1
|
import React, { memo } from 'react';
|
2
2
|
import { Typography, Box } from '@mui/material';
|
3
3
|
import DID from '../../DID';
|
4
|
-
import {
|
4
|
+
import { UserCardProps } from '../types';
|
5
5
|
import TooltipAvatar from './tooltip-avatar';
|
6
6
|
import { renderTopRight } from '../components';
|
7
|
+
import ShortenLabel from './shorten-label';
|
7
8
|
|
8
|
-
interface MinimalContentProps {
|
9
|
-
user:
|
10
|
-
showDid: boolean;
|
9
|
+
interface MinimalContentProps extends UserCardProps {
|
10
|
+
user: UserCardProps['user'];
|
11
11
|
avatarSize: number;
|
12
12
|
shouldShowHoverCard: boolean;
|
13
13
|
renderCardContent?: () => React.ReactNode | null;
|
14
|
-
didProps: Record<string, any>;
|
15
|
-
renderTopRightContent?: () => React.ReactNode;
|
16
|
-
topRightMaxWidth: number;
|
17
14
|
avatarProps?: UserCardProps['avatarProps'];
|
15
|
+
shortenLabelProps?: UserCardProps['shortenLabelProps'];
|
18
16
|
}
|
19
17
|
|
20
18
|
function MinimalContent(props: MinimalContentProps) {
|
@@ -28,6 +26,7 @@ function MinimalContent(props: MinimalContentProps) {
|
|
28
26
|
renderTopRightContent,
|
29
27
|
topRightMaxWidth,
|
30
28
|
avatarProps,
|
29
|
+
shortenLabelProps,
|
31
30
|
} = props;
|
32
31
|
|
33
32
|
return (
|
@@ -48,7 +47,7 @@ function MinimalContent(props: MinimalContentProps) {
|
|
48
47
|
fontSize={18}
|
49
48
|
noWrap
|
50
49
|
sx={{ lineHeight: 1.1 }}>
|
51
|
-
{user.fullName || user.email || user.did}
|
50
|
+
<ShortenLabel {...shortenLabelProps}>{user.fullName || user.email || user.did}</ShortenLabel>
|
52
51
|
</Typography>
|
53
52
|
|
54
53
|
{showDid && user.did ? (
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Tooltip, Typography, TypographyProps } from '@mui/material';
|
2
|
+
import { useMemo } from 'react';
|
3
|
+
|
4
|
+
function shortenString(str: string | undefined, maxLength: number = 10): string {
|
5
|
+
if (!str) return '';
|
6
|
+
if (str.length <= maxLength) return str;
|
7
|
+
return `${str.slice(0, maxLength - 1)}...${str.slice(-2)}`;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface ShortenLabelProps {
|
11
|
+
children: string;
|
12
|
+
maxLength?: number;
|
13
|
+
sx?: TypographyProps['sx'];
|
14
|
+
hiddenTip?: boolean;
|
15
|
+
}
|
16
|
+
|
17
|
+
function ShortenLabel({ children, maxLength = 10, sx = undefined, hiddenTip = false }: ShortenLabelProps) {
|
18
|
+
const shortenedText = useMemo(() => shortenString(children, maxLength), [children, maxLength]);
|
19
|
+
if (children?.length <= maxLength) {
|
20
|
+
return <Typography sx={sx}>{children}</Typography>;
|
21
|
+
}
|
22
|
+
if (hiddenTip) {
|
23
|
+
return <Typography sx={sx}>{shortenedText}</Typography>;
|
24
|
+
}
|
25
|
+
return (
|
26
|
+
<Tooltip title={children} placement="top">
|
27
|
+
<Typography sx={sx}>{shortenedText}</Typography>
|
28
|
+
</Tooltip>
|
29
|
+
);
|
30
|
+
}
|
31
|
+
|
32
|
+
export default ShortenLabel;
|
@@ -48,7 +48,7 @@ export const renderAvatar = (
|
|
48
48
|
// 渲染右上角内容
|
49
49
|
export const renderTopRight = (
|
50
50
|
renderTopRightContent: (() => React.ReactNode) | undefined,
|
51
|
-
topRightMaxWidth: number
|
51
|
+
topRightMaxWidth: number = 120
|
52
52
|
) => {
|
53
53
|
if (renderTopRightContent) {
|
54
54
|
return <Box sx={{ maxWidth: topRightMaxWidth }}>{renderTopRightContent()}</Box>;
|
package/src/UserCard/index.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import { useRef } from 'react';
|
2
2
|
import type { User } from './types';
|
3
3
|
import { UserCardProps, CardType } from './types';
|
4
4
|
import AvatarOnlyCard from './Cards/avatar-only';
|
@@ -39,9 +39,15 @@ function UserCard(props: UserCardProps) {
|
|
39
39
|
// 渲染卡片内容(用于Tooltip)
|
40
40
|
const renderCardContent = () => {
|
41
41
|
const _avatarProps = props.popupAvatarProps || props.avatarProps;
|
42
|
+
const _shortenLabelProps = props.popupShortenLabelProps || props.shortenLabelProps;
|
42
43
|
return (
|
43
44
|
<DialogContainer sx={props.popupSx}>
|
44
|
-
<DetailedCard
|
45
|
+
<DetailedCard
|
46
|
+
{...props}
|
47
|
+
shouldShowHoverCard={false}
|
48
|
+
avatarProps={_avatarProps}
|
49
|
+
shortenLabelProps={_shortenLabelProps}
|
50
|
+
/>
|
45
51
|
</DialogContainer>
|
46
52
|
);
|
47
53
|
};
|
package/src/UserCard/types.ts
CHANGED
@@ -2,6 +2,7 @@ import React from 'react';
|
|
2
2
|
import { SxProps, Theme, TooltipProps } from '@mui/material';
|
3
3
|
import { DIDProps } from '../DID';
|
4
4
|
import { AvatarProps } from '../Avatar';
|
5
|
+
import { ShortenLabelProps } from './Content/shorten-label';
|
5
6
|
|
6
7
|
type UserPublicInfo = {
|
7
8
|
avatar: string;
|
@@ -114,7 +115,7 @@ export interface UserCardProps {
|
|
114
115
|
avatarSize?: number;
|
115
116
|
showHoverCard?: boolean;
|
116
117
|
showDid?: boolean;
|
117
|
-
didProps?: DIDProps
|
118
|
+
didProps?: Partial<DIDProps>;
|
118
119
|
|
119
120
|
avatarProps?: Partial<AvatarProps>;
|
120
121
|
popupAvatarProps?: Partial<AvatarProps>;
|
@@ -126,6 +127,10 @@ export interface UserCardProps {
|
|
126
127
|
sx?: SxProps<Theme>;
|
127
128
|
popupSx?: SxProps<Theme>;
|
128
129
|
|
130
|
+
// fullName 相关属性
|
131
|
+
shortenLabelProps?: Partial<ShortenLabelProps>;
|
132
|
+
popupShortenLabelProps?: Partial<ShortenLabelProps>;
|
133
|
+
|
129
134
|
// 右上角内容相关属性
|
130
135
|
renderTopRightContent?: () => React.ReactNode;
|
131
136
|
topRightMaxWidth?: number;
|