GitHub

Avatar

Compact identity marker. Falls back image → initials → user icon, with a deterministic background hue derived from the name.

Stable .astro import EsaAvatar from '@esa/ecology/esa-avatar.astro';

Preview

AL
<Avatar name="Ada Lovelace" />

Sizes

AL AL AL AL
<Avatar name="Ada Lovelace" size="xs" />
<Avatar name="Ada Lovelace" size="sm" />
<Avatar name="Ada Lovelace" size="md" />
<Avatar name="Ada Lovelace" size="lg" />

Shapes

GH GH
<Avatar name="Grace Hopper" shape="circle" />
<Avatar name="Grace Hopper" shape="square" />

Fallbacks

The background hue is hashed from name, so each person gets a stable, distinct color. Resolution order is image → initials → user icon.

Photo User AT KJ S
<Avatar src="https://i.pravatar.cc/100?img=12" name="Photo User" />
<Avatar name="Alan Turing" />
<Avatar name="Single" />
<Avatar />

API

PropTypeDefaultDescription
name string '' Used to derive initials and a deterministic background hue.
src string '' Image URL. When set, renders the photo instead of initials.
icon string '' Lucide icon name for an icon fallback (defaults to a user glyph).
size 'xs' | 'sm' | 'md' | 'lg' 'md' Avatar diameter (20 / 28 / 40 / 56px).
shape 'circle' | 'square' 'circle' Fully rounded or rounded-square.
initials string — Explicit initials, overriding the first+last derivation from name. For callers that carry their own rule — esa-header-nav takes the first letter of every word capped at two, so "Mary Jane Watson" is MJ there and MW by default here.

Accessibility

  • Image fallback uses name (or "Avatar") as its alt text.
  • The icon fallback is aria-hidden — pair the avatar with a visible name nearby for screen readers.
  • Content is non-selectable (user-select: none) so initials don't interfere with text selection.

Theming surface

Every public token this component reads, extracted from its source at build time, split by blast radius: the hooks that belong to this component, then the shared and system tokens it consumes alongside everything else. The Resolves to column walks each token's real lineage — component → semantic → primitive → raw value — so you can see exactly where re-pointing it lands. A spoke re-skins by overriding these in its theme-<slug>.css; component internals are never edited. No hook for what you need? File it with /request-lego.

Type roles it names

This component does not set a size, weight, face or tracking of its own — it names a composite, and the composite carries all five. A composite is a class rather than a token, so none of it appears in the tables below; re-theme text by re-pointing the token family, not by editing the component.

RoleRe-pointReach
.typography-label-2xs-strong
  • --typography-label-2xs-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-label-2xs-strong-font-size clamp(0.5rem, 0.44rem + 0.3vw, 0.625rem) via --font-size-050
  • --typography-label-2xs-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-label-2xs-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-label-2xs-strong-line-height 1.6 via --line-height-normal
only here
.typography-label-md-strong
  • --typography-label-md-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-label-md-strong-font-size clamp(0.75rem, 0.66rem + 0.44vw, 0.9375rem) via --font-size-200
  • --typography-label-md-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-label-md-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-label-md-strong-line-height 1.6 via --line-height-normal
+3 more components esa-empty-state, esa-error-summary, esa-header-nav
.typography-label-xs-strong
  • --typography-label-xs-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-label-xs-strong-font-size clamp(0.625rem, 0.56rem + 0.32vw, 0.75rem) via --font-size-100
  • --typography-label-xs-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-label-xs-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-label-xs-strong-line-height 1.6 via --line-height-normal
+1 more component esa-empty-state
.typography-title
  • --typography-title-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-title-font-size clamp(1rem, 0.88rem + 0.6vw, 1.25rem) via --font-size-400
  • --typography-title-font-weight 500 via --typography-font-weight-medium → --font-weight-500
  • --typography-title-letter-spacing 0.01em via --letter-spacing-default
  • --typography-title-line-height 1.6 via --line-height-normal
+4 more components esa-confirm-dialog, esa-dialog, esa-empty-state, esa-side-dialog

Wired to this component

No other component reads these — re-point them and esa-avatar is the only thing that moves.

Token Tier Resolves to
--avatar-size-lg component 56px
--avatar-size-md component 40px
--avatar-size-sm component 28px
--avatar-size-xs component 20px

Shared tokens it reads

Owned by a family or by the semantic layer. Still overridable — but scope the override (esa-foo { --form-border-color: … }) unless you mean to move everything that reads it. Reach says what else that is.

Token Reach Resolves to
--color-content-default-knockout semantic every component #fcfcfc via --color-gray-1
--radius-md semantic every component 0.5rem via --radius-200
--radius-pill semantic every component 9999px via --radius-full
--typography-label-2xs-strong-font-size semantic every component clamp(0.5rem, 0.44rem + 0.3vw, 0.625rem) via --font-size-050
--typography-label-md-strong-font-size semantic every component clamp(0.75rem, 0.66rem + 0.44vw, 0.9375rem) via --font-size-200
--typography-label-xs-strong-font-size semantic every component clamp(0.625rem, 0.56rem + 0.32vw, 0.75rem) via --font-size-100
--typography-title-font-size semantic every component clamp(1rem, 0.88rem + 0.6vw, 1.25rem) via --font-size-400