Badge

A small pill for a status, a count, a label or a tag. Renders a `<span>` by default, or whatever Base UI's `render` prop is given, so the same badge can be an anchor without losing its shape.

feedbackserveruiv1.3.0

Preview

Badge — live renderprimitives-badge--variants

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/badge.json
With the @interlace alias
npx shadcn@latest add @interlace/badge

Behavior

What this component does — the keyboard path, the measured colour, the text equivalent and the states it can be in. Every figure below is read out of the test or the source that enforces it by scripts/build-behavior-map.mjs, so nothing here can outlive the gate that keeps it true.

Every semantic colour pair this component's own source uses, measured against the shipped hexes in all 4 theme × scheme combinations. The tightest is destructive on background at 7.60:1 (harbor · light), against a floor of 3:1.

Measured WCAG contrast ratios per token pair and theme
PairinterlacelightinterlacedarkharborlightharbordarkFloor
destructive on backgrounddestructive tint on the page surface8.31:110.43:17.60:110.03:13.0:1SC 1.4.11
destructive-foreground on destructivecopy on a destructive face8.31:110.43:18.02:110.03:14.5:1SC 1.4.3
destructive on carddestructive tint inside a card8.31:19.66:18.02:19.09:13.0:1SC 1.4.11
ring on backgroundfocus ring (SC 2.4.13)8.80:111.79:18.39:110.03:13.0:1SC 1.4.11
primary on backgroundprimary tint on the page surface8.80:111.79:18.39:110.03:13.0:1SC 1.4.11
ring on cardfocus ring inside a card8.80:110.92:18.86:19.10:13.0:1SC 1.4.11
primary-foreground on primarycopy on a primary face8.80:111.79:18.86:110.03:14.5:1SC 1.4.3
primary on cardprimary tint inside a card8.80:110.92:18.86:19.10:13.0:1SC 1.4.11
accent-foreground on accenthover/highlight face8.98:110.46:18.95:19.65:14.5:1SC 1.4.3
secondary-foreground on secondarysecondary button face15.58:114.51:114.63:114.04:14.5:1SC 1.4.3
foreground on backgroundbody copy19.65:116.97:117.74:116.19:14.5:1SC 1.4.3

Text pairs are held to 4.5:1 (WCAG 2.2 SC 1.4.3); borders, rings and chart axes to 3:1 (SC 1.4.11 non-text). Bold is the worst cell in the row — the one a brand fork has to keep an eye on.

Where it renders, how narrow it survives, and whether its lines are inside the coverage gate — three answers a consumer needs before the paste, not after the bug.

Render boundary
server component

Renders during SSR / RSC with no hydration cost. It can be imported from a server component without pulling the page into the client.

Minimum viewport
none declared

No width floor: it takes the width it is given. Its container owns the layout question.

Coverage gate
100% × 4

Inside the v8 gate: lines 100, statements 100, functions 100, branches 100. A threshold under 100 only records how much you stopped caring, so there isn't one.

History

This component is at v1.3.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.

@interlace/ui 1.1.01 entry

  • Changedpatch

    Six defects found by upgrading a real consumer, plus five found by reading the components closely enough to document them. **Meteors' glow never painted.** It read var(--color-meteor-glow) while its cssVars declare --meteor-glow; --color-* is the Tailwind @theme namespace and only cssVars.theme populates it, so the whole box-shadow was invalid at computed-value time. **This was broken only for registry consumers** — our own docs site hand-declares the --color- form. **ArticleCard cropped 28% off every cover.** h-44 is 176px; at a ~302px tile that is a 1.72:1 box against a 2.381:1 image. Now aspect-[1000/420] — the ratio the card already declared on its <img>. It also gains a renderImage slot, because every Next.js consumer was re-patching the same line to use next/image and the design system cannot depend on it. **BorderBeam and StarsBackground had no aria-hidden at all** — six purely decorative nodes a screen reader walked. **CloudParticles defaulted bodyColor to currentColor**, painting volumetric clouds in the inherited text colour. **NumberTicker gains notation**, because six-figure metrics overflow a tile at 320px. Also: SheetCompose and DialogCompose each mounted a second backdrop, so a composed dialog dimmed the page twice as much as the hand-composed tree the docs show; Accordion dropped className on the animated Panel; Tooltip accepted delay and discarded it; PopoverAnchor was a second trigger. **useReducedMotion was one frame late.** The canonical useState(false) plus effect returns false on the first render, so every gated component painted one frame of exactly the motion the user turned off. useSyncExternalStore reads during render and closes that on client renders; on hydration the server cannot know the preference, which is what the stylesheet reset is for. Badge drops 'use client' — verified with a real server-component build.

@interlace/ui 1.0.01 entry

Import

2 named exports — pull the parts you need.

Public API
import { Badge, badgeVariants } from '@/components/ui/badge';

Anatomy

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

Badge                            (span by default, or the `render` element)
    └─ children                    (text and/or an svg, sized to size-3 here)

Variants

Closed prop unions enforced by class-variance-authority. See Storybook's Variants story for the rendered matrix.

  • variant
    • defaultdefault
    • secondary
    • destructive
    • outline
    • ghost
    • link

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.

BadgeProps

Also accepts every <span> attribute. Plus the variant props listed above.

PropTypeDescription
renderuseRender.RenderProp
loadingbooleanWhen true, render a `<Skeleton variant="badge" />` in place of the normal Badge surface. Shape-matched placeholder (h-5 w-16 rounded-full) so the row layout doesn't shift on data arrival.

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}.

Badge — loading stateprimitives-badge--loading
Usage
<Badge 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/use-render — focus trapping, dismissal and typeahead come from the headless primitive, not from us.
Focus ring (WCAG 2.2 SC 2.4.13)
Inherited from the preflight focus contract shipped in @interlace/theme.
Reduced motion
No animation to gate.
ARIA in the source
  • aria-invalid

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 native el`React.ComponentProps<'span'>`
R6data-slot + data-variant on root`'data-slot': 'badge'`, `'data-variant': variant`
R7cva + cn + ...rest`cn(badgeVariants({ variant }), className)` + `...props`
R8Enum for variantdefault / secondary / destructive / outline / ghost / link
R10Composition seam`render` — Base UI's `useRender`, not an `as` prop
R19Tokens only`bg-primary`, `bg-secondary`, `bg-destructive`, `bg-accent`
R20AA contrastevery variant composited by `composite-contrast-lock`
R25Client componentNot required — server component, see the note above

Dependencies

Base UI primitive
@base-ui/react/use-render
Lucide icons
none
NPM dependencies
  • @base-ui/react
  • class-variance-authority

Source

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

185 lines · TypeScript
import * as React from 'react';

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

/**
 * @interlace/ui — Badge
 *
 * A small pill for a status, a count, a label or a tag. Renders a `<span>` by
 * default, or whatever Base UI's `render` prop is given, so the same badge can
 * be an anchor without losing its shape.
 *
 * Six variants, and every one that names a text colour also paints an opaque
 * surface under it — see the rule below.
 *
 * ## Anatomy
 *
 *   Badge                            (span by default, or the `render` element)

…165 more lines…

Registry JSON

The raw registry record — what the shadcn CLI fetches.