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.6.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 info on background at 6.89:1 (harbor · light), against a floor of 4.5:1.

Measured WCAG contrast ratios per token pair and theme
PairinterlacelightinterlacedarkharborlightharbordarkFloor
info on backgroundtext-info on the page8.44:110.83:16.89:113.08:14.5:1SC 1.4.3
info-foreground on infocopy on a info face8.72:110.98:17.27:113.08:14.5:1SC 1.4.3
info on cardtext-info in a card8.72:110.17:17.27:111.86:14.5:1SC 1.4.3
success on backgroundtext-success on the page7.44:110.16:17.28:19.86:14.5:1SC 1.4.3
destructive on backgroundtext-destructive on the page8.05:110.29:17.60:110.03:14.5:1SC 1.4.3
success-foreground on successcopy on a success face7.68:17.75:17.68:17.75:14.5:1SC 1.4.3
success on cardtext-success in a card7.68:19.54:17.68:18.95:14.5:1SC 1.4.3
warning-foreground on warningcopy on a warning face9.07:17.81:19.07:18.65:14.5:1SC 1.4.3
warning on cardtext-warning in a card9.07:18.54:19.07:18.01:14.5:1SC 1.4.3
destructive-foreground on destructivecopy on a destructive face8.31:110.43:18.02:110.03:14.5:1SC 1.4.3
destructive on cardtext-destructive in a card8.31:19.66:18.02:19.09:14.5:1SC 1.4.3
ring on backgroundfocus ring (SC 2.4.13)8.52:111.63:18.39:110.03:13.0:1SC 1.4.11
primary on backgroundtext-primary on the page8.52:111.63:18.39:110.03:14.5:1SC 1.4.3
warning on backgroundtext-warning on the page8.78:19.09:18.60:18.83:14.5:1SC 1.4.3
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 cardtext-primary in a card8.80:110.92:18.86:19.10:14.5:1SC 1.4.3
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.02:116.73: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
not in the gate

The 100% gate currently covers src/charts/**/*.{ts,tsx} and pure cores: day keys, puzzle order, streak arithmetic. and , and , // DataTable: sort order, blanks last, page window, selection. and , // Photo upload: what a file is, what it says about its owner, the plan, the reducer. and , // The account control: names and initials, the return-path check, the reducer, the hook, the menu. and , and , and , // The five pure variant/model modules. and , // Booking: the slot picker and src/patterns/time-slot-model.ts and src/patterns/share-image-model.ts and src/patterns/{interest-model,commitment-model,session-plan-model,recap-model}.ts and src/primitives/{file-model.ts,file-drop.tsx} and src/patterns/avatar-upload.tsx and s first steps. and , // The 37 components with real render coverage. See the ledger above. and , // Patterns with full render coverage — the same ledger rule: a // file is in at 100 or it is out, and joining is a one-line diff. and , // Effects with full render coverage, on the same rule. and , . This file is outside it — the glob widens in phase 7.2.

History

This component is at v1.6.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 2.0.04 entries

@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
    • success
    • warning
    • info
    • highlight
    • secondary
    • destructive
    • outline
    • ghost
    • link
    • scrim
  • size
    • defaultdefault
    • sm

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)
Drawn by the component's own focus-visible classes, so it holds with or without the opt-in preflight.
Reduced motion
No animation to gate.
ARIA in the source
  • aria-invalid

Examples

4 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 / success / warning / info / highlight / 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.

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

// @interlace/badge v1.6.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.
 *
 * Ten 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)

…200 more lines…

Registry JSON

The raw registry record — what the shadcn CLI fetches.