apx-dsv0.1Local renderer · live
K
Foundations4
  • Getting started
  • Theming
  • Templates
  • Icons
  • Avatar
  • Badge
  • DataGrid
  • Scheduler
  • Stat
  • Table
  • Timeline
  • TreeView
  • Accordion
  • Alert
  • EmptyState
  • Progress
  • Skeleton
  • Spinner
  • SplashScreen
  • Toast
  • ColorPicker
  • FileUpload
  • Form
  • Rating
  • TagsInput
  • Combobox
  • Field
  • Select
  • Toggle
  • Button
  • Calendar
  • Checkbox
  • DatePicker
  • Input
  • NumberInput
  • Radio
  • Slider
  • Switch
  • Textarea
  • AppShell
  • Div
  • Divider
  • Sidebar
  • Stack
  • Typography
  • Image
  • Breadcrumbs
  • Carousel
  • NavigationMenu
  • Pagination
  • Stepper
  • Tabs
  • Toolbar
  • CommandPalette
  • Confirm
  • Drawer
  • HoverCard
  • Menu
  • Modal
  • Popover
  • Tooltip
  • Icon
  • Card
  • PricingCard
60 componentsapx-ds/renderer
Avatar
Variant↳ other

Data Display

Avatar

User-identity glyph with image, initials, and icon fallback. Ships with deterministic name → color hashing, status indicator, accent ring, and an AvatarGroup that overlaps children into a stack with an optional

Avatar

<Avatar /> is the canonical user-identity glyph in apx-ds. It handles the three states every profile tile has to deal with — image loads, image fails, no image at all — without spreading that logic across the consuming app.

Overview — with image, initials, custom color

Loading preview…
Overview.tsx

<AvatarGroup /> stacks several avatars with a configurable overlap and an optional +N overflow tile. Use it for "assigned to" lists, project members, viewers/typing indicators — anywhere a small set of identities collapses into a single inline glyph.

State machine

Avatar is the first DS component whose rendered tree depends on async state. The decision tree lives in a tiny isolated hook (useAvatarImage):

  • src missing → render fallback immediately
  • src set, loading → wait delayMs (default 600 ms), then show fallback
  • src loaded → render <img>
  • src errored → render fallback

delayMs is the "don't flash the initials if the image is about to arrive" debounce — same semantics as Radix Avatar.

Variants

The variant prop describes how the fallback looks. Once an image loads, it covers the tile, so loaded avatars look identical across variants (modulo outline's border).

  • solid — opaque palette fill, contrast text. Default. Loud, readable on any background.
  • outline — paper background + 2px palette-colored border + role-colored text.
  • soft — palette -subtle background + role-colored text. Calm, editorial.

Colors

Seven palette roles plus 'auto'. auto deterministically hashes the name prop into one of the seven roles, so the same person consistently lands on the same color across the app — no random fallbacks, no inconsistent UI between lists and detail pages. Explicit color props always win over the hash.

Sizes

Six sizes — broader than Badge or Button — because real product surfaces range from list-cell glyphs (xs, 24 px) to hero profile photos (2xl, 96 px). The status dot and fallback icon scale alongside the avatar; you set one size token and everything responds.

Status indicator

Pass status for a presence dot — online, offline, away, busy. Position with statusPlacement (four corners). The busy tone pulses via the shared badge-pulse keyframe and respects prefers-reduced-motion. The dot is aria-hidden — the wrapper's label remains the source of truth.

Examples

Basic usage — image, initials, icon fallback

Loading preview…
Basic.tsx

Variants — solid / outline / soft

Loading preview…
Variants.tsx

Sizes — xs through 2xl

Loading preview…
Sizes.tsx

Colors — palette + auto hash by name

Loading preview…
Colors.tsx

Shapes — circle / rounded / square

Loading preview…
Shapes.tsx

Fallback — initials, icon, error state

Loading preview…
Fallback.tsx

Status indicator — online / offline / away / busy

Loading preview…
WithStatus.tsx

Accent ring — colored offset

Loading preview…
WithRing.tsx

AvatarGroup — overlap + overflow

Loading preview…
Group.tsx

Profile card — avatar + identity

Loading preview…
ProfileCard.tsx

asChild — render as a link / button

Loading preview…
AsChild.tsx

AvatarGroup

The group propagates size / shape / variant defaults to nested Avatars via context. Per- Avatar props still win. Children beyond max collapse into a single +N overflow tile — which is just another <Avatar> with name="+3". One render path, one accessible name, no parallel implementation. Use renderOverflow to wrap the overflow tile in a tooltip / popover.

RTL

  • The avatar's status placement is physical on purpose (bottom-right stays bottom-right in RTL). Designers expect a fixed corner.
  • The group's overlap direction does flip in RTL via margin-inline-start.

Accessibility

  • role="img" + aria-label={alt ?? name ?? 'avatar'} on the wrapper (unless asChild, where the wrapped element's native role wins).
  • Inner <img> always has alt="" — wrapper carries the name.
  • Initials, fallback icon, and status dot are aria-hidden.
  • Overflow tile in AvatarGroup carries aria-label="N more".
  • axe-core: zero violations across every variant × color × state cell.

Bundle

Target: < 3.5 KB gzipped — heaviest in this batch (image state machine + group composition). No lucide-react import; the default icon is inline SVG.

Props

PropTypeDefaultDescription
altstring—Accessible label override. Defaults to `name` when omitted. The label sits on the wrapper `<span role="img">`; the inner `<img>` always has `alt=""` to avoid double announcement.
asChildboolean—Radix-style polymorphism. When `true`, Avatar merges its props/className/ref onto the single child element (e.g. wrap an `<a>` to render a clickable profile avatar).
colorenum'auto'Palette role for the fallback tile. `'auto'` deterministically hashes `name` into one of the seven roles so a person consistently lands on the same color across the app.
delayMsnumber600Milliseconds to wait before painting the initials/icon fallback while an `src` is loading. Avoids the "initials → image" flash on fast connections. Set to 0 to disable.
fallbackIconReactNode—Custom fallback icon used when there is neither `src` nor a usable `name`.
labelReactNode—Optional label rendered below the avatar. When provided, Avatar auto-wraps itself in a flex column container with the label as a `<Typography variant="caption">` underneath. Omit to render just the avatar (original behavior preserved). Incompatible with `asChild`.
namestring—Person/entity name. Drives initials, the deterministic color hash (when `color="auto"`), and the default `aria-label`.
ringenum'none'Accent ring color (sits outside the circle in the offset gap).
shapeenum'circle'Border-radius family.
sizeResponsiveValue<AvatarSize>'md'Visual diameter + initials font size + status-dot/icon size.
srcstring—Primary image source. Omit to render initials / icon fallback.
srcSetstring—Optional density set forwarded to the underlying `<img>`.
statusenum—Optional presence status — renders a small colored dot in the chosen corner.
statusPlacementenum'bottom-right'Corner the status dot is anchored to.
sxSx—Theme-aware inline style object.
variantResponsiveValue<AvatarVariant>'solid'Stylistic family.