- Docs
- Components
- Data display
Avatar
A person, or an organisation, application or tenant: their photo or logo, or their initials.
- Import
- @qeetrix/react
- Status
- StableSince 0.0.2
- Renders
<span role="img">Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// From the package: a build keeps only what it uses.
import { Avatar } from "@qeetrix/react";
// Or from its own path.
import { Avatar } from "@qeetrix/react/avatar";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
name | string | required | The text alternative, and the initials: the first word's letter and the last's. A legal form (Pvt Ltd, LLP, Inc) doesn't count. |
src | string | — | The photo or logo; the initials show while it loads, and if it fails. |
size | "sm" | "md" | "lg" | "xl" | "md" | 24, 32, 40 or 48px. |
shape | "circle" | "square" | "circle" | Circle for a person; square, with a control's corners, for anything else. |
status | AvatarStatus: { label: string; tone?: AvatarStatusTone } | — | A dot on the bottom-end corner, 8 to 14px with the size. label is read with the name: "Priya Sharma, Online". |
status.tone | AvatarStatusTone: "neutral" | "brand" | "info" | "success" | "warning" | "danger" | "neutral" | Badge's tones: success for online, warning for away. |
decorative | boolean | false | The name is shown beside it: hidden from assistive technology, its status too. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
avatar | <span role="img"> | data-size, data-shape, data-status; aria-label. |
avatar-image | <img alt=""> | The photo, once loaded. |
avatar-fallback | <span> | The initials, aria-hidden. |
avatar-status | <span> | The status dot, aria-hidden; data-tone. |
04
In a list
Beside the name, the avatar adds nothing to hear: AvatarItem hides it and keeps the two lines a md avatar's height.
import { AvatarItem } from "@qeetrix/react/experimental";
<AvatarItem name={user.name} description={user.email} src={user.photoUrl} />05
Presence from your data
Map each state to an AvatarStatus once, and pass it.
import { Avatar, type AvatarStatus } from "@qeetrix/react";
const PRESENCE: Record<Presence, AvatarStatus> = {
online: { label: "Online", tone: "success" },
away: { label: "Away", tone: "warning" },
offline: { label: "Offline" },
};
<Avatar name={user.name} src={user.photoUrl} status={PRESENCE[user.presence]} />