'use client'
import { useState } from 'react'
import cn from '@/utils/classnames'
export type AvatarProps = {
name: string
avatar: string | null
size?: number
className?: string
textClassName?: string
onError?: (x: boolean) => void
}
const Avatar = ({
name,
avatar,
size = 30,
className,
textClassName,
onError,
}: AvatarProps) => {
const avatarClassName = 'shrink-0 flex items-center rounded-full bg-primary-600'
const style = { width: `${size}px`, height: `${size}px`, fontSize: `${size}px`, lineHeight: `${size}px` }
const [imgError, setImgError] = useState(false)
const handleError = () => {
setImgError(true)
onError?.(true)
}
if (avatar && !imgError) {
return (
onError?.(false)}
/>
)
}
return (