Skip to content
nexubDesign System
v12.7.0

Components · Avatar

Avatar

StableAdded v0.0.1

Displays a user's profile picture with initials fallback.

import { Avatar } from '@nexub/react';
View as Markdown

Playground

Props

TSX
<Avatar name="Alex Johnson" />

Examples

Default

Sizes

With image

Alex Johnson

With badge

Agent avatar

AgentAvatar (12.2, beta) is for AI agents, so an agent never looks like a colleague: a rounded-square app tile, like the `@nexub/brand` tiles, with a sparkle in the bottom inline-end corner. Same sizes as Avatar. Screen readers hear "Payhub agent, AI agent".

States

  • default
  • size="sm"
  • size="md"
  • size="xs"
  • size="lg"
  • size="xl"

Props

Props
PropTypeDefaultDescription
srcstring—URL of the profile image.
namestring—Full name used to generate initials when no image is provided.
size'sm' | 'md' | 'xs' | 'lg' | 'xl''md'Controls avatar dimensions.
badgeboolean—Shows a status badge on the avatar.
badgeColorstring—Colour of the status badge.
fallbackReact.ReactNode—Custom fallback rendered when the image fails to load and no name is provided.
AgentAvatar iconReact.ReactNode—AgentAvatar (12.2, beta): the app glyph inside the tile, e.g. an @nexub/icons icon. Default: a bot.
AgentAvatar srcstring—AgentAvatar: an image for the tile instead of icon (e.g. an @nexub/brand app tile). Falls back to icon if it fails.
AgentAvatar namestring—AgentAvatar: who the agent is ("Payhub agent"). Read as "Payhub agent, AI agent" (messages.aiAgent).
AgentAvatar size'sm' | 'md' | 'xs' | 'lg' | 'xl''md'AgentAvatar: the same size scale as Avatar.
AgentAvatar category'accent' | 'blue' | 'amber' | 'emerald' | 'pink' | 'violet' | 'cyan' | 'red' | 'lime'—AgentAvatar: a category colour for the tile. Default: the brand tile look, a primary glyph on a surface tile.
category'accent' | 'auto' | 'blue' | 'amber' | 'emerald' | 'pink' | 'violet' | 'cyan' | 'red' | 'lime'—10.3: colour of the initials fallback. 'auto' picks a stable colour from name, so a list of people is easier to scan. Images are not affected.
status'online' | 'away' | 'busy' | 'offline'—Presence dot, added to the accessible name ("Ada Lovelace, Away"). Replaces badge when both are set.

Design tokens

Avatar reads these component tokens. Each one is unset by default and falls back to the semantic role it aliases, so nothing changes until you set it. Set one on any element to restyle every Avatar below it, and leave the roles other components share alone. See the three token tiers.

Avatar design tokens
TokenAliasesNotes
--avatar-bg--color-surface-container-high—
--avatar-fg--color-on-surface-muted—
--avatar-radius9999pxA circle.
CSS
/* One area of your app */
.checkout {
  --avatar-bg: var(--color-secondary);
}

Accessibility

ARIA roles

img (when named)

Screen reader

  • Avatar reads its `name`, plus the `status` ("Ada Lovelace, Away"). Without a name it is decorative and hidden.

  • AgentAvatar is always `role="img"` and its name says it is an AI agent ("Payhub agent, AI agent", from `messages.aiAgent`). The glyph and the sparkle are hidden.