GitHub

Badge

A small pill for counts, statuses, and labels. Seven color intents, four sizes, plus a dot mode for compact status indicators.

Stable .astro import EsaBadge from '@esa/ecology/esa-badge.astro';

Preview

12
<Badge value="12" />

Variants

Neutral Primary Secondary Success Warning Danger Info
<Badge value="Neutral" />
<Badge value="Primary" variant="primary" />
<Badge value="Secondary" variant="secondary" />
<Badge value="Success" variant="success" />
<Badge value="Warning" variant="warning" />
<Badge value="Danger" variant="danger" />
<Badge value="Info" variant="info" />

Sizes

Extra small Small Medium Large
<Badge value="Extra small" size="xs" />
<Badge value="Small" size="sm" />
<Badge value="Medium" size="md" />
<Badge value="Large" size="lg" />

Dot mode

With dot, the badge collapses to an 8px circle — useful as an inline status indicator next to a label.

<Badge dot variant="success" />
<Badge dot variant="warning" />
<Badge dot variant="danger" />

API

PropTypeDefaultDescription
value string | number — Text or count shown inside the badge. Ignored in dot mode.
variant 'neutral' | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' 'neutral' Color intent. The default, neutral, is the quiet gray-border chip for counts; ask for primary when the badge should carry the brand.
size 'xs' | 'sm' | 'md' | 'lg' 'md' Badge height and text size.
dot boolean false Renders a small status dot with no text.
label string — Accessible name for `dot` mode, which renders no visible text. Ignored otherwise.

Accessibility

  • Purely presentational — pair with adjacent visible text so the count or status has a label.
  • Dot mode has no text content; convey its meaning through surrounding copy or an aria-label on the wrapper.
  • Color is not the only signal where possible — prefer text counts over color alone.

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-microcopy-2xs-strong
  • --typography-microcopy-2xs-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-microcopy-2xs-strong-font-size clamp(0.5rem, 0.44rem + 0.3vw, 0.625rem) via --font-size-050
  • --typography-microcopy-2xs-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-microcopy-2xs-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-microcopy-2xs-strong-line-height 1 via --line-height-none
+2 more components esa-button-toggle, esa-chip-group
.typography-microcopy-md-strong
  • --typography-microcopy-md-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-microcopy-md-strong-font-size clamp(0.75rem, 0.66rem + 0.44vw, 0.9375rem) via --font-size-200
  • --typography-microcopy-md-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-microcopy-md-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-microcopy-md-strong-line-height 1 via --line-height-none
+2 more components esa-button-toggle, esa-chip-group
.typography-microcopy-sm-strong
  • --typography-microcopy-sm-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-microcopy-sm-strong-font-size clamp(0.6875rem, 0.61rem + 0.38vw, 0.875rem) via --font-size-150
  • --typography-microcopy-sm-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-microcopy-sm-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-microcopy-sm-strong-line-height 1 via --line-height-none
+1 more component esa-snackbar-item
.typography-microcopy-xs-strong
  • --typography-microcopy-xs-strong-font-family 'DM Sans', sans-serif via --typography-font-family-sans → --font-family-dm-sans
  • --typography-microcopy-xs-strong-font-size clamp(0.625rem, 0.56rem + 0.32vw, 0.75rem) via --font-size-100
  • --typography-microcopy-xs-strong-font-weight 550 via --typography-font-weight-semibold → --font-weight-550
  • --typography-microcopy-xs-strong-letter-spacing 0.01em via --letter-spacing-default
  • --typography-microcopy-xs-strong-line-height 1 via --line-height-none
+5 more components esa-button-toggle, esa-chip-group, esa-filter-dropdown, esa-sidebar-nav, esa-tab-layout

Wired to this component

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

Token Tier Resolves to
--badge-bg component #fcfcfc via --color-background-elevation-raised → --color-gray-1
--badge-border-color component one role per property, so a theme can move the ring's weight and its colour independently. Tier 3's --focus-ring-width now reads this instead of holding a bare 2px, which is the same shape --focus-ring-color has always had (a thin tier-3 alias over a tier-2 role) — width was simply never given the tier-2 half. * * This role was rejected once, and the rejection is worth recording because its PREMISE was wrong rather than its reasoning. The argument against an `emphasis` width was that every 2px border in the kit is micro-geometry — spinner rings, the kbd keycap lip, a chevron. The focus ring was not in that enumeration and does not fit it: 33 components render it, more than read any other tier-3 token, and it is not micro-geometry but an accessibility affordance whose weight is a legitimate brand axis (a spoke that needs a heavier ring for contrast has to be able to reach it). It is also not a `border` in any component — every consumer paints it with `outline` or `box-shadow` — which is precisely why a survey of BORDERS missed it. The name still says `border` because tier 2 already calls the ring's colour --color-border-default-focus via --color-border-default
--badge-text-color component #646464 via --color-content-default-secondary → --color-gray-11

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-background-brand semantic every component #46a758 via --color-grass-9
--color-background-brand-hover semantic every component #3e9b4f via --color-grass-10
--color-background-brand-muted semantic every component #e9f6e9 via --color-grass-3
--color-background-utility-danger-hover semantic every component #641723 via --color-red-12
--color-background-utility-danger-muted semantic every component #feebec via --color-red-3
--color-background-utility-info-hover semantic every component #113264 via --color-blue-12
--color-background-utility-info-muted semantic every component #e6f4fe via --color-blue-3
--color-background-utility-success-hover semantic every component #193b2d via --color-green-12
--color-background-utility-success-muted semantic every component #e6f6eb via --color-green-3
--color-background-utility-warning-hover semantic every component #ffba18 via --color-yellow-10
--color-background-utility-warning-muted semantic every component #fff7c2 via --color-yellow-3
--color-border-utility-danger semantic every component #fdbdbe via --color-red-6
--color-border-utility-info semantic every component #acd8fc via --color-blue-6
--color-border-utility-success semantic every component #adddc0 via --color-green-6
--color-border-utility-warning semantic every component #f3d673 via --color-yellow-6
--color-content-default-knockout semantic every component #fcfcfc via --color-gray-1
--color-content-default-secondary semantic every component #646464 via --color-gray-11
--color-content-on-brand-muted semantic every component #203c25 via --color-grass-12
--color-content-utility-danger semantic every component #ce2c31 via --color-red-11
--color-content-utility-info semantic every component #0d74ce via --color-blue-11
--color-content-utility-success semantic every component #218358 via --color-green-11
--color-content-utility-warning semantic every component #ab6400 via --color-yellow-11
--radius-chip semantic every component 0.25rem via --radius-100
--radius-pill semantic every component 9999px via --radius-full
--spacing-100 primitive every component 0.25rem
--spacing-150 primitive every component 0.375rem
--spacing-200 primitive every component 0.5rem
--spacing-250 primitive every component 0.625rem
--spacing-300 primitive every component 0.75rem