/** * Avatar Component - Lynx 版 MUI Avatar * 头像组件 */ import './Avatar.css' export type AvatarVariant = 'circular' | 'rounded' | 'square' export interface AvatarProps { /** 头像图片地址 */ src?: string /** 替代文本 */ alt?: string /** 变体 */ variant?: AvatarVariant /** 宽度 */ width?: number /** 高度 */ height?: number /** 背景颜色 */ bgcolor?: string /** 子元素 (通常是文字或图标) */ children?: any /** 自定义类名 */ className?: string /** 内联样式 */ style?: Record /** sx 属性 */ sx?: Record /** 点击事件 */ bindtap?: () => void } // 变体边框半径 const variantRadius: Record = { circular: '50%', rounded: 8, square: 0, } export function Avatar({ src, alt, variant = 'circular', width = 40, height = 40, bgcolor = '#667eea', children, className, style, sx, ...props }: AvatarProps) { const borderRadius = variantRadius[variant] const computedStyle: Record = { display: 'flex', alignItems: 'center', justifyContent: 'center', width, height, borderRadius, backgroundColor: src ? 'transparent' : bgcolor, overflow: 'hidden', ...sx, ...style, } const classes = [ 'MuiAvatar-root', `MuiAvatar-${variant}`, src && 'MuiAvatar-img', className, ].filter(Boolean).join(' ') return ( {src ? ( ) : children ? ( {children} ) : ( ? )} ) } export default Avatar