Dashral Pro is on the wayGet 30% off at launch

Dashral

Avatar

An image element with a fallback for representing a user, and a group that stacks several.

$ pnpm dlx shadcn@latest add https://dashral.com/r/avatar.json
OMOMOMOMOM
LJonlineBSBudi SantosoawayACAva Chen

Installation

$ pnpm dlx shadcn@latest add https://dashral.com/r/avatar.json

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:

components.json
{
  "registries": {
    "@dashral": "https://dashral.com/r/{name}.json"
  }
}

Then add components by name:

$ pnpm dlx shadcn@latest add @dashral/avatar

Usage

example.tsx
import { Avatar, AvatarGroup } from "@/components/dashral/avatar"

<>
  <Avatar src="/avatars/olivia.jpg" name="Olivia Martin" status="online" />
  <AvatarGroup
    items={[{ name: "Olivia Martin" }, { name: "Jackson Lee" }, { name: "Ayu Lestari" }]}
    max={2}
    aria-label="3 people on this project"
  />
</>

Examples

Group

AvatarGroup takes items, overlaps them and collapses the rest into +N; showNames puts each name in a tooltip.

OMLJSDBSBudi Santoso+3

Team members

A list with status dots; alt="" because the name is written beside each avatar.

  • Olivia Martin

    olivia@acme.com

    Owner
  • Liam Johnson

    liam@acme.com

    Admin
  • Budi Santoso

    budi@acme.com

    Member
  • Sofia Davis

    sofia@acme.com

    Member

Account menu

The avatar as the header's account button, opening a DropdownMenu.

Acme Inc.

Assignees on a task

A small AvatarGroup in a card's footer, with names on hover.

High priority
Redesign the onboarding flow
Fewer steps from sign-up to the first dashboard, with a checklist that remembers progress.
OMLJSD+2
12comments Oct 24

API reference

Avatar

Also takes every prop of Radix Avatar(opens in a new tab).

PropTypeDefault
srcstring

The photo.

—
namestring

Who it is: the alt text, and the initials shown while the photo loads or without one.

—
altstring

The image's alt text; "" when the name is written beside it.

name
fallbackReactNode

Replaces the initials, e.g. an icon.

the initials
size"xs" | "sm" | "md" | "lg" | "xl"

24, 28, 32, 40 or 64px.

"md"
shape"circle" | "square""circle"
status"online" | "away" | "busy" | "offline"

A dot in the corner, read out too.

—
classNames{ image, fallback, status }

Classes for each part.

—
classNamestring

Extra classes, merged with cn() so yours win.

—

AvatarGroup

Also takes every prop of <div>(opens in a new tab).

PropTypeDefault
items{ src?, name?, fallback?, id? }[]

The people. Required.

—
maxnumber

Avatars shown before the rest collapse into “+N”.

—
size"xs" | "sm" | "md" | "lg" | "xl""md"
showNamesboolean

Each avatar shows its name in a tooltip, and “+N” lists the rest.

false
classNamestring

Extra classes, merged with cn() so yours win.

—

Accessibility

  • name is the photo's alt text; without a photo the name is still read out.
  • AvatarGroup is role="group": label it, e.g. aria-label="7 people on this project".
  • With showNames, each avatar and “+N” can be reached with Tab, and the tooltip shows on focus too.