Skip to content

Components / Badge

Badge

A compact, square, monospaced label for a status, category or count. Static text by default, with optional decorative icons and native link composition.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.

Usage playground

Choose an appearance and write a short, meaningful label. Appearance does not supply a status name or announce changes. Reset restores Published, default and no icon.

Published
React / TSX
import { Badge } from "@/components/ui/yads-badge";

export default function BadgeExample() {
  return (
    <Badge variant="default">{"Published"}</Badge>
  );

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/badge#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

This revision-pinned command installs yads-badge, its scoped stylesheet, Radix Slot 1.5.0 and JetBrains Mono. Import { Badge } from @/components/ui/yads-badge (adjust your alias). No Tailwind, reset, global CSS, provider or other YADS primitive is required. Light is the default; the nearest explicit .light or .dark boundary selects scoped colors.

Copy sample copies a complete React module, including icon markup, layout and recipe CSS, even when collapsed. All samples need only this registry item. Playground controls are documentation controls, not additional Badge props.

Variants

Default, secondary, destructive and outline change appearance only. Published, Draft, Failed and Archived carry the meaning in text, not just color. Badge is not an alert or an action button.

PublishedDraftFailedArchived
React / TSX
import { Badge } from "@/components/ui/yads-badge";

const layout = { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '.75rem', width: '100%', minWidth: 0 } as const;

export default function StatusExamples() {
  return <div style={layout}>

Icons, counts and long labels

Hide decorative icons from assistive technology and keep a visible label. Give counts context with surrounding text; these counts are static examples, not notifications. Long labels wrap, including unbroken words, rather than truncate. No icon library is required.

VerifiedUnread messages: 8Open issues: 99Results: 20+
Awaiting security review from the platform team
React / TSX
import { Badge } from "@/components/ui/yads-badge";

const layout = { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '.75rem', width: '100%', minWidth: 0 } as const;
function CheckIcon() {
  return <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true" focusable="false"><path d="m3 8 3 3 7-7" /></svg>;
}

className customization

Use ordinary CSS to adjust padding or border width while retaining scoped colors, wrapping and link focus. Inline style also passes through. The copied module includes the full recipe.

Documentation
React / TSX
import { Badge } from "@/components/ui/yads-badge";

export default function CustomBadge() {
  return <>
    <style>{`.categoryBadge.categoryBadge { padding: .25rem .75rem; border-width: 2px; }`}</style>
    <Badge variant="outline" className="categoryBadge">Documentation</Badge>

Accessibility

  • Text carries meaning. Use a readable status or category, not only a color or icon. Put count context in nearby text, such as Unread messages: 8. Empty labels are not useful; the playground permits them only to show your authored content.
  • Static by default. Badge renders a span without a role, tabIndex or aria-live. It is not a button, live region, alert, form field or validation message. It has no disabled, loading, selected or dismissal behavior. Your application owns changes and any separate, intentionally timed announcement.
  • Decorative icons. Use aria-hidden="true" and focusable="false" on the SVG; visible text supplies the meaning. The component sizes direct SVG children but does not automatically hide them.
  • Real links only. With asChild, supply one native anchor with a meaningful name and href. Native Tab, Shift+Tab and Enter behavior is preserved. Keep the underline and focus ring, and allow enough spacing around compact targets. Do not nest interactive elements, or add click handlers to a static badge to simulate a button.
  • Allow wrapping. Long labels wrap within their container, including unbroken text. Avoid fixed heights or clipping that hide meaning. Forced-colors mode retains a border and system focus outline.

Light is the standalone default. The nearest explicit .light or .dark ancestor selects the theme, including nested boundaries and live class changes. No provider or system-preference detection is included. Theme selection uses CSS @scope: use browsers with @scope support (Chrome/Edge 118+, Safari 17.4+, Firefox 146+). Older browsers retain light styling even inside dark boundaries.

API reference

Import { Badge, type BadgeProps, type BadgeVariant } from @/components/ui/yads-badge. Badge forwards native HTML attributes/events and its actual DOM ref. It does not depend on other YADS primitives.

On narrow screens, focus the table and scroll horizontally to read all columns.

Badge props, types, defaults and behavior
PropTypeDefaultDescription
variant'default' | 'secondary' | 'destructive' | 'outline''default'Appearance only; no implicit status or announcement.
childrenReactNodeNot setVisible text, optionally with a decorative icon. asChild requires exactly one direct native <a> element.
asChildbooleanfalseUse the child anchor instead of a span. Other elements, fragments, multiple children and custom components throw at runtime.
className / stylestring / CSSPropertiesNot setForwarded to the actual element while retaining scoped styles.
refReact.Ref<HTMLElement>Not setActual span, or actual anchor with asChild. This is not a polymorphically inferred ref type.
Native attributes / eventsReact.HTMLAttributes<HTMLElement>Not setid, title, data-*, aria-* and events pass through. Event currentTarget is typed HTMLElement. Anchor-specific props belong on the child.

Composition and ref typing

asChild uses Radix Slot 1.5.0 and adds no wrapper. TypeScript does not enforce the direct-anchor restriction; runtime does. href, target, rel and anchor-typed handlers belong on the child, not Badge. Badge-level event handlers have HTMLElement currentTarget regardless of asChild. The ref type is always HTMLElement, not HTMLAnchorElement inferred from the child; narrow it with instanceof HTMLAnchorElement before using anchor-specific properties. A span ref remains noninteractive; an anchor ref can focus the link.

Slot merges child and Badge classes and styles, with child inline styles winning. Both event handlers run, child first; preventing default in the child does not automatically skip the Badge handler, so check event.defaultPrevented when needed. Child and forwarded refs are composed. The asChild child cannot be a router component or fragment: use a direct native anchor.

Limits

There is no size, icon slot, count formatting, overflow cap, animation or automatic state management API. 20+ is authored text, not an automatic threshold. The four variants do not infer meaning or change semantics. Do not supply invalid native attributes or overwrite semantics with conflicting roles.