style: 优化UserAvatar 和 UserName 的props,允许接受更多的参数

pull/64/head
moonrailgun 2 years ago
parent 356e7edd58
commit e27094d0f2

@ -2,19 +2,24 @@ import React from 'react';
import { Avatar } from 'tailchat-design'; import { Avatar } from 'tailchat-design';
import { useCachedUserInfo } from 'tailchat-shared'; import { useCachedUserInfo } from 'tailchat-shared';
interface UserAvatarProps {
userId: string;
className?: string;
style?: React.CSSProperties;
size?: 'large' | 'small' | 'default' | number;
}
/** /**
* *
*/ */
export const UserAvatar: React.FC<{ export const UserAvatar: React.FC<UserAvatarProps> = React.memo((props) => {
userId: string; const cachedUserInfo = useCachedUserInfo(props.userId);
className?: string;
}> = React.memo((props) => {
const { userId, className } = props;
const cachedUserInfo = useCachedUserInfo(userId);
return ( return (
<Avatar <Avatar
className={className} className={props.className}
style={props.style}
size={props.size}
src={cachedUserInfo.avatar} src={cachedUserInfo.avatar}
name={cachedUserInfo.nickname} name={cachedUserInfo.nickname}
/> />

@ -1,13 +1,20 @@
import React from 'react'; import React from 'react';
import { useCachedUserInfo } from 'tailchat-shared'; import { useCachedUserInfo } from 'tailchat-shared';
export const UserName: React.FC<{ interface UserNameProps {
userId: string; userId: string;
className?: string; className?: string;
}> = React.memo((props) => { style?: React.CSSProperties;
const { userId, className } = props; }
export const UserName: React.FC<UserNameProps> = React.memo((props) => {
const { userId, className, style } = props;
const cachedUserInfo = useCachedUserInfo(userId); const cachedUserInfo = useCachedUserInfo(userId);
return <span className={className}>{cachedUserInfo.nickname}</span>; return (
<span className={className} style={style}>
{cachedUserInfo.nickname}
</span>
);
}); });
UserName.displayName = 'UserName'; UserName.displayName = 'UserName';

@ -474,11 +474,17 @@ declare module '@capital/component' {
export const ErrorBoundary: any; export const ErrorBoundary: any;
export const UserAvatar: any; export const UserAvatar: React.FC<{
userId: string;
className?: string;
style?: React.CSSProperties;
size?: 'large' | 'small' | 'default' | number;
}>;
export const UserName: React.FC<{ export const UserName: React.FC<{
userId: string; userId: string;
className?: string; className?: string;
style?: React.CSSProperties;
}>; }>;
export const Markdown: any; export const Markdown: any;

Loading…
Cancel
Save