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.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/avatar.jsonAdds 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:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/avatarUsage
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.
Team members
A list with status dots; alt="" because the name is written beside each avatar.
API reference
Avatar
Also takes every prop of Radix Avatar(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
src | stringThe photo. | — |
name | stringWho it is: the alt text, and the initials shown while the photo loads or without one. | — |
alt | stringThe image's alt text; "" when the name is written beside it. | name |
fallback | ReactNodeReplaces 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. | — |
className | stringExtra classes, merged with cn() so yours win. | — |
AvatarGroup
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
items | { src?, name?, fallback?, id? }[]The people. Required. | — |
max | numberAvatars shown before the rest collapse into “+N”. | — |
size | "xs" | "sm" | "md" | "lg" | "xl" | "md" |
showNames | booleanEach avatar shows its name in a tooltip, and “+N” lists the rest. | false |
className | stringExtra 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.