View fulldotdev/ui on GitHub

Avatar

An image element with a fallback for representing the user.

Installation

npx shadcn@latest add @fulldev/avatar

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
<Avatar>
  <AvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />
  <AvatarFallback>CN</AvatarFallback>
</Avatar>

AvatarImage renders Astro’s Image from astro:assets, so src takes an imported image or a URL. It renders nothing without src, and AvatarFallback sits behind the image, so always include it for a missing or broken image.

Composition

Use the following composition to build an Avatar:

Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge

Use the following composition to build an AvatarGroup:

AvatarGroup
├── Avatar
│   ├── AvatarImage
│   ├── AvatarFallback
│   └── AvatarBadge
├── Avatar
│   ├── AvatarImage
│   ├── AvatarFallback
│   └── AvatarBadge
└── AvatarGroupCount

Basic

A basic avatar with an image and a fallback.

Badge

AvatarBadge sits at the bottom right of the avatar. Use class for custom colors, such as bg-green-600 dark:bg-green-800.

Badge with Icon

Avatar Group

Avatar Group Count

Use AvatarGroupCount to add a count to the group.

Avatar Group with Icon

Sizes

Use the size prop to change the size of the avatar.

Put the Avatar inside a DropdownMenuTrigger styled with buttonVariants. See Dropdown Menu.

RTL

API Reference

Source: src/components/ui/avatar

Avatar

PropTypeDefault
size"default" | "sm" | "lg""default"

Renders a span with data-size, which AvatarFallback and AvatarBadge read through group/avatar.

AvatarImage

Accepts the props of Astro’s Image.

PropTypeDefault
srcImageMetadata | string-
altstring""
widthnumber44
heightnumber44
sizesstring"44px"
widthsnumber[][44, 88, 176]

AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount

These take the attributes of their element (span for AvatarFallback and AvatarBadge, div for AvatarGroup and AvatarGroupCount) and a class.