Core components / Badges & tags
Badge
A short label for status, category or count. Soft for most things, Outline when it sits on a tinted surface, Dot when a coloured dot says enough and the text should stay calm.
Code
The component itself, ready to drop into your project. Switch between React, Vue and plain HTML; every version uses the same Tailwind classes on Ochre's tokens.
"use client";
import * as React from "react";
import { animate } from "@/components/ochre/motion";
import { cx } from "@/components/ochre/utils";
export type BadgeTone =
| "neutral" | "accent" | "red" | "orange" | "amber" | "yellow" | "lime"
| "green" | "teal" | "cyan" | "blue" | "indigo" | "violet" | "pink";
export type BadgeVariant = "soft" | "outline" | "dot";
export type BadgeSize = "s" | "m" | "l";
export type BadgeProps = React.HTMLAttributes<HTMLSpanElement> & {
tone?: BadgeTone;
variant?: BadgeVariant;
size?: BadgeSize;
shape?: "pill" | "rounded";
icon?: React.ReactNode;
// Dot variant only: the dot breathes slowly, for things that are live right now.
live?: boolean;
};
// Each tone as literal classes, so Tailwind can see them: [soft, outline, dot colour].
const tones: Record<BadgeTone, [string, string, string]> = {
neutral: ["bg-tint-neutral-bg text-tint-neutral-text", "border-tint-neutral-border text-tint-neutral-text", "bg-tint-neutral-dot"],
accent: ["bg-status-accent-bg text-status-accent-text", "border-status-accent-border text-status-accent-text", "bg-action-primary"],
red: ["bg-tint-red-bg text-tint-red-text", "border-tint-red-border text-tint-red-text", "bg-tint-red-dot"],
orange: ["bg-tint-orange-bg text-tint-orange-text", "border-tint-orange-border text-tint-orange-text", "bg-tint-orange-dot"],
amber: ["bg-tint-amber-bg text-tint-amber-text", "border-tint-amber-border text-tint-amber-text", "bg-tint-amber-dot"],
yellow: ["bg-tint-yellow-bg text-tint-yellow-text", "border-tint-yellow-border text-tint-yellow-text", "bg-tint-yellow-dot"],
lime: ["bg-tint-lime-bg text-tint-lime-text", "border-tint-lime-border text-tint-lime-text", "bg-tint-lime-dot"],
green: ["bg-tint-green-bg text-tint-green-text", "border-tint-green-border text-tint-green-text", "bg-tint-green-dot"],
teal: ["bg-tint-teal-bg text-tint-teal-text", "border-tint-teal-border text-tint-teal-text", "bg-tint-teal-dot"],
cyan: ["bg-tint-cyan-bg text-tint-cyan-text", "border-tint-cyan-border text-tint-cyan-text", "bg-tint-cyan-dot"],
blue: ["bg-tint-blue-bg text-tint-blue-text", "border-tint-blue-border text-tint-blue-text", "bg-tint-blue-dot"],
indigo: ["bg-tint-indigo-bg text-tint-indigo-text", "border-tint-indigo-border text-tint-indigo-text", "bg-tint-indigo-dot"],
violet: ["bg-tint-violet-bg text-tint-violet-text", "border-tint-violet-border text-tint-violet-text", "bg-tint-violet-dot"],
pink: ["bg-tint-pink-bg text-tint-pink-text", "border-tint-pink-border text-tint-pink-text", "bg-tint-pink-dot"],
};
const sizes: Record<BadgeSize, string> = {
s: "h-5 gap-1 px-1.5 text-[12px] leading-4 [&_svg]:size-3",
m: "h-[22px] gap-1 px-2 text-[12px] leading-4 [&_svg]:size-3",
l: "h-[26px] gap-1.5 px-2.5 text-[13px] leading-[18px] [&_svg]:size-3.5",
};
export function Badge({
tone = "neutral",
variant = "soft",
size = "m",
shape = "pill",
icon,
live = false,
className,
children,
...rest
}: BadgeProps) {
const [soft, outline, dot] = tones[tone];
// Pops on the bouncy spring when its text or tone changes (a count going up, a status moving on),
// never on first render.
const el = React.useRef<HTMLSpanElement>(null);
const signature = `${tone}|${typeof children === "string" || typeof children === "number" ? children : ""}`;
const previous = React.useRef(signature);
React.useEffect(() => {
if (previous.current !== signature && el.current) animate(el.current, [{ scale: 0.85 }, { scale: 1 }], "bouncy");
previous.current = signature;
}, [signature]);
return (
<span
ref={el}
{...rest}
className={cx(
"inline-flex shrink-0 items-center whitespace-nowrap border font-medium transition-colors duration-[var(--motion-base)]",
shape === "pill" ? "rounded-full" : "rounded-6",
sizes[size],
variant === "soft" && cx("border-transparent", soft),
variant === "outline" && cx("bg-surface-card", outline),
variant === "dot" && "border-border-default bg-surface-card text-text-default",
className,
)}
>
{variant === "dot" ? (
<span aria-hidden="true" className={cx("size-1.5 shrink-0 rounded-full transition-colors duration-[var(--motion-base)]", dot, live && "animate-pulse-soft")} />
) : (
icon
)}
{children}
</span>
);
}
export type LiveStatus = "live" | "syncing" | "offline";
export type LiveBadgeProps = Omit<React.HTMLAttributes<HTMLSpanElement>, "children"> & {
status?: LiveStatus;
// Replaces the status word: "On air", "Updating".
children?: React.ReactNode;
};
// [halo, dot, label] for each status. The dot sits in a soft halo of its own colour.
const live: Record<LiveStatus, [string, string, string, string]> = {
live: ["bg-status-danger-bg", "bg-status-danger-solid animate-pulse-soft", "text-text-strong", "Live"],
syncing: ["bg-status-accent-bg animate-pulse-soft", "bg-action-primary", "text-text-strong", "Syncing"],
offline: ["bg-surface-muted", "bg-text-subtle", "text-text-subtle", "Offline"],
};
// Whether a feed or connection is Live, Syncing or Offline, in mono capitals beside a dot.
// It's a status region, so a change is read out without moving focus.
export function LiveBadge({ status = "live", children, className, ...rest }: LiveBadgeProps) {
const [halo, dot, text, word] = live[status];
return (
<span
role="status"
{...rest}
className={cx(
"inline-flex h-[22px] shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full border border-border-default bg-surface-card px-2",
"font-mono text-[11px] font-medium uppercase leading-4 tracking-[0.06em] transition-colors duration-[var(--motion-base)]",
text,
className,
)}
>
<span aria-hidden="true" className={cx("grid size-3 shrink-0 place-items-center rounded-full transition-colors duration-[var(--motion-base)]", halo)}>
<span className={cx("size-1.5 rounded-full transition-colors duration-[var(--motion-base)]", dot)} />
</span>
{children ?? word}
</span>
);
}
Installation
With the @ochre registry set up, one command adds the component and what it imports (utils, motion). Or copy the code above into components/ochre/badge.tsx.
npx shadcn@latest add @ochre/badgeExamples
Sizes and shapes
S, M and L, as pills and with rounded corners, with an icon.
import { Check } from "lucide-react";
import { Badge } from "@/components/ochre/badge";
export default function BadgeSizes() {
return (
<div className="grid gap-3">
{(["pill", "rounded"] as const).map((shape) => (
<div key={shape} className="flex flex-wrap items-center gap-2">
<Badge size="s" shape={shape} tone="green" icon={<Check />}>Paid</Badge>
<Badge size="m" shape={shape} tone="green" icon={<Check />}>Paid</Badge>
<Badge size="l" shape={shape} tone="green" icon={<Check />}>Paid</Badge>
<Badge size="s" shape={shape} className="font-mono">v2.4.0</Badge>
<Badge size="m" shape={shape} className="font-mono">v2.4.0</Badge>
<Badge size="l" shape={shape} className="font-mono">v2.4.0</Badge>
</div>
))}
</div>
);
}
Tones
Every tint in soft style. Keep most badges neutral and save colour for meaning.
import { Badge, type BadgeTone } from "@/components/ochre/badge";
const tones: BadgeTone[] = [
"neutral", "accent", "red", "orange", "amber", "yellow", "lime",
"green", "teal", "cyan", "blue", "indigo", "violet", "pink",
];
export default function BadgeTones() {
return (
<div className="flex max-w-xl flex-wrap justify-center gap-2">
{tones.map((tone) => (
<Badge key={tone} tone={tone} className="capitalize">
{tone}
</Badge>
))}
</div>
);
}
In a list
Badges carrying status and version beside a project name.
- Northwind analyticsv2.4.0Live
- Billing migrationv0.9.2Degraded
- Mobile onboardingv1.0.0New
import { Sparkles } from "lucide-react";
import { Badge } from "@/components/ochre/badge";
const projects = [
{ name: "Northwind analytics", version: "v2.4.0", status: <Badge variant="dot" tone="green">Live</Badge> },
{ name: "Billing migration", version: "v0.9.2", status: <Badge variant="dot" tone="amber">Degraded</Badge> },
{ name: "Mobile onboarding", version: "v1.0.0", status: <Badge tone="accent" icon={<Sparkles />}>New</Badge> },
];
export default function BadgeInContext() {
return (
<ul className="w-full max-w-md divide-y divide-border-subtle rounded-16 border border-border-default bg-surface-card">
{projects.map((p) => (
<li key={p.name} className="flex items-center gap-3 px-4 py-3">
<span className="flex-1 truncate text-[14px] font-medium leading-5 text-text-strong">{p.name}</span>
<Badge shape="rounded" size="s" className="font-mono">{p.version}</Badge>
{p.status}
</li>
))}
</ul>
);
}
Changing values
A count pops each time it changes; a live dot breathes.
"use client";
import { useState } from "react";
import { Badge } from "@/components/ochre/badge";
import { Button } from "@/components/ochre/button";
const stages = [
{ label: "Queued", tone: "neutral" },
{ label: "Building", tone: "amber" },
{ label: "Deployed", tone: "green" },
] as const;
export default function BadgeChanging() {
const [unread, setUnread] = useState(3);
const [stage, setStage] = useState(0);
return (
<div className="flex flex-wrap items-center gap-3">
<span className="flex items-center gap-2 text-[14px] font-medium text-text-strong">
Inbox <Badge tone="accent">{unread}</Badge>
</span>
<Button variant="secondary" size="s" onClick={() => setUnread((n) => n + 1)}>
New message
</Button>
<span className="mx-2 h-5 w-px bg-border-default" />
<Badge variant="dot" tone={stages[stage].tone} live={stage === 1}>
{stages[stage].label}
</Badge>
<Button variant="secondary" size="s" onClick={() => setStage((s) => (s + 1) % stages.length)}>
Next stage
</Button>
</div>
);
}
Live badge
Live, Syncing and Offline for a feed or a connection. Press Next to move it along.
"use client";
import { useState } from "react";
import { Button } from "@/components/ochre/button";
import { LiveBadge, type LiveStatus } from "@/components/ochre/badge";
const order: LiveStatus[] = ["live", "syncing", "offline"];
export default function BadgeLive() {
const [i, setI] = useState(0);
return (
<div className="grid justify-items-center gap-5">
<div className="flex flex-wrap items-center gap-2">
<LiveBadge status="live" />
<LiveBadge status="syncing" />
<LiveBadge status="offline" />
</div>
<div className="flex items-center gap-3 rounded-12 border border-border-default bg-surface-card py-2 pl-3 pr-2">
<span className="text-[14px] font-medium leading-5 text-text-strong">Stripe payouts</span>
<LiveBadge status={order[i]} />
<Button variant="secondary" size="s" onClick={() => setI((n) => (n + 1) % order.length)}>
Next
</Button>
</div>
</div>
);
}
Motion
Built on Ochre's ease-out curves. With reduced motion switched on, everything still works, it just doesn't move.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| tone | "neutral" | "accent" | "red" | "orange" | "amber" | "yellow" | "lime" | "green" | "teal" | "cyan" | "blue" | "indigo" | "violet" | "pink" | "neutral" | Colour. Accent follows the colour scheme; the rest are fixed tints. |
| variant | "soft" | "outline" | "dot" | "soft" | Tinted fill, tinted border, or a neutral pill with a coloured dot. |
| size | "s" | "m" | "l" | "m" | 20, 22 or 26 pixels high. |
| shape | "pill" | "rounded" | "pill" | Rounded suits versions, ids and tags in dense tables. |
| icon | ReactNode | – | Small icon before the label (not shown on the dot variant). |
| live | boolean | false | Dot variant: the dot breathes slowly, for things happening now. |
| status (LiveBadge) | "live" | "syncing" | "offline" | "live" | Live badge: a feed or connection's state, in mono capitals. children replaces the word. |
Usage
Use it for
- Status on rows and cards: Paid, In review, Blocked.
- Categories and versions, one or two words long.
- Accent tone for the one badge that needs attention, like New.
- Live badge for a feed or connection: Live, Syncing or Offline.
Avoid
- Actions: badges aren't clickable. Use a Button or a filter chip.
- A rainbow of tones in one table. Map tones to meaning and keep most neutral.
- Red for anything that isn't a problem.