refactor: Avatar.jsx -> .tsx
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
export default function Avatar({ src, text, icon = 'person', ...props } = {}) {
|
|
||||||
return (
|
|
||||||
src ? <mdui-avatar {...props}>
|
|
||||||
<img src={src} alt={'(头像)' + text || ''} />
|
|
||||||
</mdui-avatar>
|
|
||||||
: (
|
|
||||||
text ? <mdui-avatar {...props}>
|
|
||||||
{
|
|
||||||
text.substring(0, 0)
|
|
||||||
}
|
|
||||||
</mdui-avatar>
|
|
||||||
: <mdui-avatar icon={icon} {...props} />
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
25
client/ui/Avatar.tsx
Normal file
25
client/ui/Avatar.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
|
src?: string
|
||||||
|
text?: string
|
||||||
|
icon?: string
|
||||||
|
avatarRef?: React.LegacyRef<HTMLElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Avatar({
|
||||||
|
src,
|
||||||
|
text,
|
||||||
|
icon = 'person',
|
||||||
|
avatarRef,
|
||||||
|
...props
|
||||||
|
}: Args) {
|
||||||
|
if (src != null)
|
||||||
|
return <mdui-avatar ref={avatarRef} {...props} src={src} />
|
||||||
|
else if (text != null)
|
||||||
|
return <mdui-avatar ref={avatarRef} {...props}>
|
||||||
|
{
|
||||||
|
text.substring(0, 0)
|
||||||
|
}
|
||||||
|
</mdui-avatar>
|
||||||
|
else
|
||||||
|
return <mdui-avatar icon={icon} ref={avatarRef} {...props} />
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user