54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { cn } from "cn"
|
|
import { Avatar as AvatarPrimitive } from "radix-ui"
|
|
|
|
// Radix Avatar keeps the image load handling: the Image renders only after it loads, otherwise the Fallback shows
|
|
// (with an optional `delayMs`). `size` is the shadcn API (sm | default | lg); the dimensions and the fallback look come from
|
|
// src/theme/avatar.css.
|
|
function Avatar({
|
|
className,
|
|
size = "default",
|
|
...props
|
|
}: React.ComponentProps<typeof AvatarPrimitive.Root> & {
|
|
size?: "default" | "sm" | "lg"
|
|
}) {
|
|
return (
|
|
<AvatarPrimitive.Root
|
|
data-slot="avatar"
|
|
data-size={size}
|
|
className={cn("relative flex shrink-0 overflow-hidden select-none", className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function AvatarImage({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
|
return (
|
|
<AvatarPrimitive.Image
|
|
data-slot="avatar-image"
|
|
className={cn("aspect-square size-full object-cover", className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function AvatarFallback({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
|
return (
|
|
<AvatarPrimitive.Fallback
|
|
data-slot="avatar-fallback"
|
|
className={cn("flex size-full items-center justify-center", className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export { Avatar, AvatarImage, AvatarFallback }
|