Avatar

A circular image with a text fallback. Wraps @base-ui/react/avatar: Base UI owns the image load/error state machine that decides when the fallback shows, and we own the surface.

data displayclientuiv1.2.0

Preview

Avatar — live renderprimitives-avatar--default

Rendered from the story the storybook (a11y) CI gate runs axe against — the preview can't show something that hasn't been verified.

Install

Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.

Via shadcn URL
npx shadcn@latest add https://ds.interlace.tools/r/avatar.json
With the @interlace alias
npx shadcn@latest add @interlace/avatar

History

This component is at v1.2.0, first shipped in @interlace/ui 1.0.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.

Import

3 named exports — pull the parts you need.

Public API
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';

Anatomy

Extracted from the primitive's JSDoc header. The source is the only documentation that can't drift.

Avatar                           (Avatar.Root — size-8, rounded-full, overflow-hidden)
    ├─ AvatarImage                 (Avatar.Image — aspect-square size-full)
    └─ AvatarFallback              (Avatar.Fallback — bg-muted, centred initials)
`size-8` is a default, not a constraint: it is merged through `cn`, so
`className="size-12"` wins. The `loading` skeleton is given the same
`size-8` and the same `className`, so an overridden size survives the swap.

API reference

Parsed from the type declarations in the source — the same file the install writes into your tree, so this table can't drift from the component you get.

AvatarProps

Also accepts every prop of Base UI's <Avatar.Root> — behaviour we compose rather than reimplement.

PropTypeDescription
loadingbooleanWhen true, render a `<Skeleton variant="avatar" />` in place of the normal Avatar surface. Idiomatic state-contract entry — the loading silhouette is shape-matched (size-8 rounded-full — the same size the Root renders) so the layout doesn't shift when the real image lands.

Skeleton

Pass loading and the component renders a shape-matched <Skeleton /> in its own place — same box, so nothing reflows when the data lands. Below is the same story with loading={true}.

Avatar — loading stateprimitives-avatar--loading
Usage
<Avatar loading={isPending} />

Accessibility

Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.

What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.

Focus + keyboard behaviour
Owned by @base-ui/react/avatar — focus trapping, dismissal and typeahead come from the headless primitive, not from us.
Focus ring (WCAG 2.2 SC 2.4.13)
Not focusable — no focus indicator required.
Reduced motion
No animation to gate.
ARIA in the source
None — semantics come from the element or the Base UI primitive rather than hand-written ARIA.

Examples

2 more states from the same story file.

R-rule compliance

Every primitive in @interlace/ui models to the portable 26-rule floor enforced by the componentApi ESLint preset. The cells below pin exactly where each rule applies in this file.

RuleConceptWhere
R4Extends Base UI part props`React.ComponentProps<typeof BaseAvatar.Root/Image/Fallback>`
R6data-slot per partavatar / avatar-image / avatar-fallback
R7cn + ...rest`cn('… size-8 …', className)` + `{...props}`
R12Reuse over wrapBase UI owns the image load/error machine
R19Tokens only`bg-muted` on the fallback face
R25Client componentRequired — Base UI Avatar ships client hooks

Dependencies

Base UI primitive
@base-ui/react/avatar
Lucide icons
none
NPM dependencies
  • @base-ui/react

Source

The full implementation — components/ui/avatar.tsx once installed.

121 lines · TypeScript
'use client';

import * as React from 'react';

// @interlace/avatar v1.2.0 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/avatar
// What changed since: https://ds.interlace.tools/c/avatar#history
// Generated banner — keep it, the upgrade diff reads this version.

// Mirrors the shadcn Avatar canon, built on Base UI primitives.
// Upstream: https://base-ui.com/react/components/avatar

/**
 * @interlace/ui — Avatar
 *
 * A circular image with a text fallback. Wraps @base-ui/react/avatar: Base UI
 * owns the image load/error state machine that decides when the fallback
 * shows, and we own the surface.
 *
 * Ours is the `size-8` clipped circle, the muted fallback face, and a

…101 more lines…

Registry JSON

The raw registry record — what the shadcn CLI fetches.