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.
Preview
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.
npx shadcn@latest add https://ds.interlace.tools/r/badge.jsonnpx shadcn@latest add @interlace/badgeBehavior
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.
Measured contrast
packages/ui/__tests__/theme-contract-lock.test.ts ↗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.
| Pair | interlacelight | interlacedark | harborlight | harbordark | Floor |
|---|---|---|---|---|---|
| destructive on backgrounddestructive tint on the page surface | 8.31:1 | 10.43:1 | 7.60:1 | 10.03:1 | 3.0:1SC 1.4.11 |
| destructive-foreground on destructivecopy on a destructive face | 8.31:1 | 10.43:1 | 8.02:1 | 10.03:1 | 4.5:1SC 1.4.3 |
| destructive on carddestructive tint inside a card | 8.31:1 | 9.66:1 | 8.02:1 | 9.09:1 | 3.0:1SC 1.4.11 |
| ring on backgroundfocus ring (SC 2.4.13) | 8.80:1 | 11.79:1 | 8.39:1 | 10.03:1 | 3.0:1SC 1.4.11 |
| primary on backgroundprimary tint on the page surface | 8.80:1 | 11.79:1 | 8.39:1 | 10.03:1 | 3.0:1SC 1.4.11 |
| ring on cardfocus ring inside a card | 8.80:1 | 10.92:1 | 8.86:1 | 9.10:1 | 3.0:1SC 1.4.11 |
| primary-foreground on primarycopy on a primary face | 8.80:1 | 11.79:1 | 8.86:1 | 10.03:1 | 4.5:1SC 1.4.3 |
| primary on cardprimary tint inside a card | 8.80:1 | 10.92:1 | 8.86:1 | 9.10:1 | 3.0:1SC 1.4.11 |
| accent-foreground on accenthover/highlight face | 8.98:1 | 10.46:1 | 8.95:1 | 9.65:1 | 4.5:1SC 1.4.3 |
| secondary-foreground on secondarysecondary button face | 15.58:1 | 14.51:1 | 14.63:1 | 14.04:1 | 4.5:1SC 1.4.3 |
| foreground on backgroundbody copy | 19.65:1 | 16.97:1 | 17.74:1 | 16.19:1 | 4.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.
Runtime contract
packages/ui/vitest.config.ts ↗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 componentRenders 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 declaredNo width floor: it takes the width it is given. Its container owns the layout question.
- Coverage gate
100% × 4Inside 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 readvar(--color-meteor-glow)while itscssVarsdeclare--meteor-glow;--color-*is the Tailwind@themenamespace and onlycssVars.themepopulates it, so the wholebox-shadowwas invalid at computed-value time. **This was broken only for registry consumers** — our own docs site hand-declares the--color-form. **ArticleCardcropped 28% off every cover.**h-44is 176px; at a ~302px tile that is a 1.72:1 box against a 2.381:1 image. Nowaspect-[1000/420]— the ratio the card already declared on its<img>. It also gains arenderImageslot, because every Next.js consumer was re-patching the same line to usenext/imageand the design system cannot depend on it. **BorderBeamandStarsBackgroundhad noaria-hiddenat all** — six purely decorative nodes a screen reader walked. **CloudParticlesdefaultedbodyColortocurrentColor**, painting volumetric clouds in the inherited text colour. **NumberTickergainsnotation**, because six-figure metrics overflow a tile at 320px. Also:SheetComposeandDialogComposeeach mounted a second backdrop, so a composed dialog dimmed the page twice as much as the hand-composed tree the docs show;AccordiondroppedclassNameon the animated Panel;Tooltipaccepteddelayand discarded it;PopoverAnchorwas a second trigger. **useReducedMotionwas one frame late.** The canonicaluseState(false)plus effect returnsfalseon the first render, so every gated component painted one frame of exactly the motion the user turned off.useSyncExternalStorereads during render and closes that on client renders; on hydration the server cannot know the preference, which is what the stylesheet reset is for.Badgedrops'use client'— verified with a real server-component build.
@interlace/ui 1.0.01 entry
- Addedminor
The component floor reaches every tier: form, overlay, navigation and display primitives were modelled to the portable 26-rule floor with skeletons, locked breakpoints, and AA contrast measured per composite rather than eyeballed.
Components- @interlace/input
- @interlace/textarea
- @interlace/select
- @interlace/checkbox
- @interlace/radio-group
- @interlace/switch
- @interlace/slider
- @interlace/number-field
- @interlace/form
- @interlace/label
- @interlace/dialog
- @interlace/alert-dialog
- @interlace/sheet
- @interlace/popover
- @interlace/tooltip
- @interlace/hover-card
- @interlace/dropdown-menu
- @interlace/context-menu
- @interlace/tabs
- @interlace/accordion
- @interlace/collapsible
- @interlace/breadcrumb
- @interlace/pagination
- @interlace/toast
- @interlace/card
- @interlace/avatar
- @interlace/alert
- @interlace/separator
- @interlace/progress
- @interlace/skeleton
Import
2 named exports — pull the parts you need.
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.
| Prop | Type | Description |
|---|---|---|
| render | useRender.RenderProp | — |
| loading | boolean | When 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={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.
| Rule | Concept | Where |
|---|---|---|
| R4 | Extends native el | `React.ComponentProps<'span'>` |
| R6 | data-slot + data-variant on root | `'data-slot': 'badge'`, `'data-variant': variant` |
| R7 | cva + cn + ...rest | `cn(badgeVariants({ variant }), className)` + `...props` |
| R8 | Enum for variant | default / secondary / destructive / outline / ghost / link |
| R10 | Composition seam | `render` — Base UI's `useRender`, not an `as` prop |
| R19 | Tokens only | `bg-primary`, `bg-secondary`, `bg-destructive`, `bg-accent` |
| R20 | AA contrast | every variant composited by `composite-contrast-lock` |
| R25 | Client component | Not required — server component, see the note above |
Dependencies
- Base UI primitive
- @base-ui/react/use-render
- Lucide icons
- none
- NPM dependencies
@base-ui/reactclass-variance-authority
- Registry dependencies
Source
The full implementation — components/ui/badge.tsx once installed.
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.