When to use
- A short status on a row or a card: Operational, Degraded, Beta, Draft.
- An unread or pending count on a nav item or a tab, which should disappear at zero.
- A label with a number: "Queued 4".
When not to use
- A message that needs a sentence or an action: use an Alert.
- Something a person can click, toggle or remove: use a Button or a Toggle Group.
- A large standalone number: use Number Roll at the size you need.
Installation
pnpm dlx shadcn add https://eased.dev/r/badge.jsonnpx shadcn add https://eased.dev/r/badge.jsonyarn dlx shadcn add https://eased.dev/r/badge.jsonbunx --bun shadcn add https://eased.dev/r/badge.jsonThe command adds Badge, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add motionnpm install motionyarn add motionbun add motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/badge/badge.tsxTSX "use client";import { AnimatePresence, motion, useInView } from "motion/react";import { useRef, type ReactNode } from "react";import { NumberRoll } from "../_primitives/number-roll/number-roll";import { exitFast, reducedFade, snappy, useSafeReducedMotion } from "../lib/motion";export type BadgeTone = "neutral" | "brand" | "success" | "warning" | "danger" | "info";export type BadgeProps = { /** The label, e.g. "Beta" or "Operational". Optional when the badge is only a count. */ children?: ReactNode; /** A number that rolls when it changes. Shown after the label. */ count?: number; /** Counts above this show as `max+`. Default 99. */ max?: number; /** * A count-only badge leaves (scale and fade) when its count is 0, and returns when it rises. * Keep it mounted and let this drive presence. Default false. */ showZero?: boolean; /** A status dot before the label. `"live"` breathes slowly (2.4s) and stops under reduced motion. */ dot?: boolean | "live"; tone?: BadgeTone; /** 20px (`sm`, default) or 24px (`md`) tall. */ size?: "sm" | "md"; locale?: Intl.LocalesArgument; /** Spoken in place of the visible text, e.g. "3 unread messages". */ "aria-label"?: string; className?: string;};// Status badges are subtle fill + state text (R31); the dot takes the text colour.const TONES: Record<BadgeTone, string> = { neutral: "bg-surface-active text-text-secondary", brand: "bg-brand-subtle text-brand-text", success: "bg-success-subtle text-success-text", warning: "bg-warning-subtle text-warning-text", danger: "bg-danger-subtle text-danger-text", info: "bg-info-subtle text-info-text",};const SIZES = { sm: { box: "h-5 gap-1 px-1.5 text-ui-xs", count: "min-w-5", dot: "size-1.5" }, md: { box: "h-6 gap-1.5 px-2 text-ui-sm", count: "min-w-6", dot: "size-2" },} as const;/** * A status or count chip. Counts roll their digits in the direction of change; a count-only * badge pops in when it rises above zero and leaves when it is cleared; a live dot breathes. */export function Badge({ children, count, max = 99, showZero = false, dot = false, tone = "neutral", size = "sm", locale, "aria-label": ariaLabel, className = "",}: BadgeProps) { const reduced = useSafeReducedMotion(); const s = SIZES[size]; const hasLabel = children !== undefined && children !== null && children !== false; const countOnly = !hasLabel && count !== undefined; const visible = !countOnly || showZero || (count ?? 0) > 0; const shown = count === undefined ? undefined : Math.min(count, max); const over = count !== undefined && count > max; return ( <AnimatePresence initial={false}> {visible && ( <motion.span initial={reduced ? { opacity: 0 } : { opacity: 0, scale: 0.85 }} animate={{ opacity: 1, scale: 1 }} exit={reduced ? { opacity: 0, transition: reducedFade } : { opacity: 0, scale: 0.9, transition: exitFast }} transition={reduced ? reducedFade : snappy} className={`inline-flex shrink-0 items-center justify-center font-medium whitespace-nowrap tabular-nums transition-colors duration-150 ease-standard ${s.box} ${ countOnly ? `${s.count} rounded-pill` : "rounded-control-xs" } ${TONES[tone]} ${className}`} > {ariaLabel && <span className="sr-only">{ariaLabel}</span>} {dot && <Dot live={dot === "live"} className={s.dot} />} {hasLabel && ( <span aria-hidden={ariaLabel ? true : undefined} className="min-w-0 truncate"> {children} </span> )} {shown !== undefined && ( <span aria-hidden={ariaLabel ? true : undefined} className="inline-flex"> <NumberRoll value={shown} locale={locale} aria-hidden={!!ariaLabel} /> {over && "+"} </span> )} </motion.span> )} </AnimatePresence> );}function Dot({ live, className }: { live: boolean; className: string }) { const ref = useRef<HTMLSpanElement>(null); const inView = useInView(ref); return ( <span ref={ref} aria-hidden className={`relative shrink-0 rounded-pill bg-current ${className}`}> {live && ( <> {/* A halo the dot's colour that swells and fades back; it pauses off-screen and under reduced motion. */} <span className="absolute inset-0 animate-[eased-breathe_2400ms_var(--eased-ease-in-out)_infinite] rounded-pill bg-current opacity-0 reduced:animate-none" style={{ animationPlayState: inView ? "running" : "paused" }} /> <style href="eased-badge" precedence="default"> {"@keyframes eased-breathe { 0%, 100% { opacity: 0; scale: 1; } 50% { opacity: 0.35; scale: 2.25; } }"} </style> </> )} </span> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Badge } from "@/components/eased/badge/badge";export function ServiceStatus({ unread }: { unread: number }) { return ( <div className="flex items-center gap-2"> <Badge tone="success" dot="live">Operational</Badge> <Badge count={unread} tone="brand" aria-label={`${unread} unread`} /> </div> );}Examples
Tones and dots
Six tones, each a subtle fill with text in the state colour. dot adds a status dot in the text colour.
<Badge tone="warning" dot>Degraded</Badge><Badge tone="info">Beta</Badge><Badge tone="danger" dot>Failed</Badge>Counts
A badge with a label shows its count after the label. A count-only badge leaves at 0 unless showZero is set; keep it mounted and let the count drive it.
<Badge count={4}>Queued</Badge><Badge count={128} max={99} /> {/* shows 99+ */}<Badge count={0} showZero />API reference
Badge
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | The label. Optional for count-only badges. | |
count | number | Rolls when it changes. Shown after the label. | |
max | number | 99 | Counts above this show as max+. |
showZero | boolean | false | Keep a count-only badge at 0; otherwise it leaves. |
dot | boolean | "live" | false | A status dot before the label; "live" breathes. |
tone | "neutral" | "brand" | "success" | "warning" | "danger" | "info" | "neutral" | |
size | "sm" | "md" | "sm" | 20px or 24px tall. |
locale | Intl.LocalesArgument | Formats the count. | |
aria-label | string | Spoken instead of the visible text. | |
className | string | "" | Appended to the badge's classes. |
Accessibility
- With
aria-label, the label is read and the visible text and count are hidden from assistive tech, so "3 unread" is read instead of "3". - Without it, the visible text and the formatted count are read as they are.
- The dot is decorative and hidden; the tone colour is never the only signal, so the label must say the state.
- The badge is not a live region: a changing count is not announced on its own.
Motion
Counts roll their digits in the direction of change on the snappy spring. A count-only badge pops in from 0.85 scale on the snappy spring and leaves in 100ms to 0.9, faster than it came. The live dot's halo swells to 2.25× and fades back every 2.4s, and pauses while off-screen. Reduced motion: the badge fades in and out in 100ms with no scale, the count changes without rolling, and the halo stops.
Notes for AI
Use Badge for short statuses and counts. Pass count rather than putting a number in children, so it rolls and respects max, and give count-only badges an aria-label that says what is counted.
Do not wrap a count-only badge in your own conditional to hide it at zero: keep it mounted so it can animate out. Do not use the tone alone to carry meaning; the label should name the state.
Related components
- Animated Number Counter: the rolling digits on their own.
- Avatar and Avatar Group: a picture to pair with a status badge.
- Animated Alert: a status that needs a sentence.