Avatar

PreviousNext

An easily stylable avatar component.

Docs
basecnui

Preview

Loading preview…
registry/components/ui/avatar.tsx
import { cn } from "@/lib/utils";
import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar";

function Avatar({ className, ...props }: AvatarPrimitive.Root.Props) {
  return (
    <AvatarPrimitive.Root
      data-slot="avatar"
      className={cn(
        "relative flex size-8 shrink-0 overflow-hidden rounded-full",
        className
      )}
      {...props}
    />
  );
}

function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
  return (
    <AvatarPrimitive.Image
      data-slot="avatar-image"
      className={cn("aspect-square size-full", className)}
      {...props}
    />
  );
}

function AvatarFallback({
  className,
  ...props
}: AvatarPrimitive.Fallback.Props) {
  return (
    <AvatarPrimitive.Fallback
      data-slot="avatar-fallback"
      className={cn(
        "bg-muted flex items-center justify-center size-full rounded-full text-sm",
        className
      )}
      {...props}
    />
  );
}

export { Avatar, AvatarImage, AvatarFallback };

Installation

npx shadcn@latest add @basecn/avatar

Usage

import { Avatar } from "@/components/ui/avatar"
<Avatar />