43 lines
907 B
TypeScript
Raw Permalink Normal View History

2024-04-30 23:34:44 -04:00
import { cn } from "@/lib/utils"
import Image from "next/image"
2024-04-30 23:34:44 -04:00
export default function Avatar({
name,
avatarUrl,
2024-04-30 23:34:44 -04:00
className,
}: {
name: string
avatarUrl?: string | null
2024-04-30 23:34:44 -04:00
className?: string
}) {
// Generate initials from name if no avatarUrl is provided
const initials = name
? name
.split(" ")
.slice(0, 2)
.map((letter) => letter[0].toUpperCase())
.join("")
: "?"
2024-04-30 23:34:44 -04:00
return (
<div
className={cn(
className,
"w-9 h-9 font-mono rounded-full overflow-hidden bg-gradient-to-t from-neutral-800 to-neutral-600 flex items-center justify-center text-sm font-medium"
2024-04-30 23:34:44 -04:00
)}
>
{avatarUrl ? (
<Image
src={avatarUrl}
alt={name || "User"}
width={20}
height={20}
className="w-full h-full object-cover"
/>
) : (
initials
)}
2024-04-30 23:34:44 -04:00
</div>
)
}