Avatar
A round image or initials that stand for a user, an analyst or a tenant.
<>
<Avatar>
<AvatarImage src="/favicon.svg" alt="Zenox" />
<AvatarFallback>ZX</AvatarFallback>
</Avatar>
<Avatar>
<AvatarFallback>MR</AvatarFallback>
</Avatar>
</>Usage
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@zenoxai/ui/components/avatar"
export function UserAvatar({ user }: { user: User }) {
return (
<Avatar>
<AvatarImage src={user.pictureUrl} alt={user.name} />
<AvatarFallback>{user.initials}</AvatarFallback>
</Avatar>
)
}
Always give a fallback. The image shows only once it has loaded; until then, and when the URL is missing or broken, the fallback shows instead. Use two initials, uppercase, computed in the app from the name.
An avatar identifies someone; it does not replace their name. In tables, assignee fields and audit logs, print the name next to it.
Sizes
default (32px) fits lists and table rows. sm (24px) fits dense tables and inline mentions;
lg (40px) fits profile headers and the account menu.
<>
<Avatar size="sm">
<AvatarFallback>MR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarFallback>MR</AvatarFallback>
</Avatar>
<Avatar size="lg">
<AvatarFallback>MR</AvatarFallback>
</Avatar>
</>Group
AvatarGroup overlaps the avatars and rings each one with the background color.
AvatarGroupCount closes the row with the number of people not shown. Show three or four
avatars at most.
<AvatarGroup role="group" aria-label="Assigned analysts">
<Avatar>
<AvatarFallback>MR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarFallback>JL</AvatarFallback>
</Avatar>
<Avatar>
<AvatarFallback>PS</AvatarFallback>
</Avatar>
<AvatarGroupCount>+3</AvatarGroupCount>
</AvatarGroup>With a badge
AvatarBadge places a dot on the bottom-right edge, sized to the avatar. It is bg-primary by
default; pass a token class such as bg-success for presence. The dot is only a hint: say the
state in text next to the avatar.
<div className="flex items-center gap-2">
<Avatar>
<AvatarFallback>MR</AvatarFallback>
<AvatarBadge className="bg-success" />
</Avatar>
<div className="flex flex-col">
<span className="text-sm font-medium">Marina Rocha</span>
<span className="text-xs text-text-secondary">On call</span>
</div>
</div>Accessibility
- Set
altonAvatarImageto the person’s or tenant’s name. When the name is printed next to the avatar,alt=""avoids reading it twice. - Screen readers read the fallback initials as letters. When the name is not visible, label the
surrounding element, as the group example does with
role="group"andaria-label. AvatarBadgehas no text. Never let it be the only place a state appears.
API reference
Generated from the TypeScript source. className, style and children are accepted everywhere and omitted below.
Avatar
Avatar is the round picture of a person or an account. AvatarFallback, initials or an icon, shows while AvatarImage loads or when it fails; AvatarBadge adds a status dot and AvatarGroup overlaps several avatars.
| Prop | Type | Default |
|---|---|---|
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, AvatarRootState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. | - |
size | "default" | "sm" | "lg"Diameter: `sm` 24px, `default` 32px, `lg` 40px. | default |
AvatarImage
| Prop | Type | Default |
|---|---|---|
keepMounted | booleanWhether the image element stays mounted and loads in place instead of being preloaded. Supports `loading="lazy"` and optimized image components such as `next/image`. | false |
onLoadingStatusChange | ((status: ImageLoadingStatus) => void)Callback fired when the loading status changes. | - |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, AvatarImageState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. | - |
AvatarFallback
| Prop | Type | Default |
|---|---|---|
delay | numberHow long to wait before showing the fallback. Specified in milliseconds. | 0 |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, AvatarFallbackState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. | - |
AvatarGroup
AvatarGroup overlaps a row of avatars, each ringed to keep it distinct.
No props of its own. Accepts the props of the element it renders.
AvatarGroupCount
AvatarGroupCount is the trailing "+N" circle of an AvatarGroup, sized to match the avatars in it.
No props of its own. Accepts the props of the element it renders.
AvatarBadge
AvatarBadge is a dot pinned to the avatar's bottom-right corner, for presence or status. Its color means nothing to a screen reader: state the status in text as well.
No props of its own. Accepts the props of the element it renders.