Badge
FreeA fixed fact about a run as a tag, a badge inline in a table, or a small count beside a name, in the locked status colors with solid icons cut from the free Hugeicons.
npx shadcn@latest add https://pixilui.com/r/badge.jsonPreview
Solid icons cut from the outlines, in the locked status colors.
Show
Size
import { Badge, BadgeCount, BadgeTag, BadgeIcon, type BadgeIconName, type BadgeTone } from "@/components/pixilui/badge";
// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
show: ["tags", "badges", "counts"],
size: ["md", "sm"],
} as const;
const tones: [BadgeTone, string, BadgeIconName][] = [
["ok", "Pass", "pass"],
["bad", "Fail", "fail"],
["wait", "Needs review", "clock"],
["think", "Thinking", "sparkle"],
["read", "Reads files", "globe"],
["tool", "Uses tools", "nodes"],
["edit", "Edits", "pencil"],
["neutral", "Draft", "file"],
];
const runs: { name: string; tone: BadgeTone; words: string; icon: BadgeIconName; cost: string }[] = [
{ name: "Refund ticket 4471", tone: "ok", words: "Pass", icon: "pass", cost: "$0.41" },
{ name: "Weekly churn digest", tone: "wait", words: "Needs review", icon: "clock", cost: "$1.12" },
{ name: "Migrate billing tables", tone: "bad", words: "Fail", icon: "fail", cost: "$0.07" },
{ name: "Draft release notes", tone: "neutral", words: "Skipped", icon: "skip", cost: "$0.00" },
];
/** Tags in every tone, the same facts inline in a run table, and counts beside names. */
export default function BadgeDemo({ show = "tags", size = "md" }: KnobValues<typeof knobs>) {
if (show === "badges")
return (
<table className="w-full max-w-lg type-label">
<tbody>
{runs.map((r) => (
<tr key={r.name} className="border-b border-divider last:border-0">
<td className="py-2.5 pe-4 text-foreground">{r.name}</td>
<td className="py-2.5 pe-4">
<Badge tone={r.tone} icon={<BadgeIcon name={r.icon} />}>
{r.words}
</Badge>
</td>
<td className="py-2.5 text-end text-muted tabular-nums">{r.cost}</td>
</tr>
))}
</tbody>
</table>
);
if (show === "counts")
return (
<ul className="flex w-full max-w-xs flex-col gap-1 type-label text-secondary">
{[
["Inbox", <BadgeCount key="c" size={size}>128</BadgeCount>],
["Needs you", <BadgeCount key="c" size={size} tone="accent">3</BadgeCount>],
["Approvals", <BadgeCount key="c" size={size}>0</BadgeCount>],
["Changelog", <BadgeCount key="c" dot aria-label="New" />],
].map(([name, count]) => (
<li key={name as string} className="flex items-center justify-between rounded-control px-3 py-2">
<span>{name}</span>
{count}
</li>
))}
</ul>
);
return (
<div className="flex w-full max-w-lg flex-wrap justify-center gap-2">
{tones.map(([tone, words, icon]) => (
<BadgeTag key={tone} tone={tone} size={size} icon={<BadgeIcon name={icon} />}>
{words}
</BadgeTag>
))}
</div>
);
}When to use
Use it when
- A fixed fact about a run or a row: Pass, Fail, Needs review, Uses tools (BadgeTag).
- The same fact inline in a table cell or a meta line, icon and word with no pill (Badge).
- A number beside a name in a nav or a heading, or a dot for something new (BadgeCount).
Use something else when
- A state that changes while you watch: use Agent status, the pill with the live mark.
- Something a person can remove or press: use Chip.
- Decoration: every tone means a status or a kind of work.
Installation
Terminal
npx shadcn@latest add https://pixilui.com/r/badge.jsonAdds badge.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.
components/pixilui/badge.tsx
"use client";
/*
Tags, badges and counts, locked 28 Nov 2026 with the chips (design/explorations/components/locked/chips).
The look is foundation.css section 8 (.pixilui-tag, .pixilui-count); this file writes the locked markup.
BadgeTag a fixed fact about a run: the status pill without its live mark, in a status color or a meaning hue.
Badge the tag's inline variant: icon and word, no pill; words grey, the hue only for wait and bad.
BadgeCount a small number beside a name, or an 8px dot for "new".
BadgeIcon the Solid icon set the tags lead with (chips.solid.js), drawn from the free Hugeicons outlines
(MIT, https://hugeicons.com): the shapes filled, their inner lines cut through with a mask.
*/
import { cloneElement, forwardRef, isValidElement, useId, type ComponentPropsWithoutRef, type CSSProperties, type ReactElement, type ReactNode } from "react";
import { cn } from "./lib/utils";
/* ------------------------------------------------------------------ the Solid icons */
export type BadgeIconName =
| "pass"
| "fail"
| "warning"
| "skip"
| "shield"
| "sparkle"
| "lock"
| "clock"
| "gavel"
| "globe"
| "rocket"
| "target"
| "play"
| "pause"
| "pencil"
| "inbox"
| "nodes"
| "coins"
| "file"
| "link";
type SolidParts = {
base?: string[];
acc?: string[];
lines?: string[];
bline?: string[];
cuts?: string[];
accCuts?: string[];
halos?: string[];
heavy?: string[];
solid?: string[];
bulk?: string[];
cutsSolidOnly?: boolean;
};
// The locked drawing data (chips.solid.js), unchanged: each icon's parts, as SVG element strings.
const C10 = '<path d="M22 12c0-5.523-4.477-10-10-10S2 6.477 2 12s4.477 10 10 10s10-4.477 10-10Z"/>';
const SHIELD = '<path d="M21 11.183V8.28c0-1.64 0-2.46-.404-2.995s-1.318-.794-3.145-1.314a25 25 0 0 1-3.229-1.173C13.023 2.266 12.424 2 12 2s-1.023.266-2.222.798c-.88.39-1.98.818-3.229 1.173c-1.827.52-2.74.78-3.145 1.314C3 5.82 3 6.64 3 8.28v2.903c0 5.625 5.063 9 7.594 10.336c.607.32.91.481 1.406.481s.799-.16 1.406-.48C15.937 20.182 21 16.807 21 11.182Z"/>';
const PLAY = 'M18.89 12.846c-.353 1.343-2.023 2.292-5.364 4.19c-3.23 1.835-4.845 2.752-6.146 2.384a3.25 3.25 0 0 1-1.424-.841C5 17.614 5 15.743 5 12s0-5.614.956-6.579a3.25 3.25 0 0 1 1.424-.84c1.301-.37 2.916.548 6.146 2.383c3.34 1.898 5.011 2.847 5.365 4.19a3.3 3.3 0 0 1 0 1.692Z';
const SQ = (x: number, y: number) => `<path d="M${x} ${y + 3}c0-1.414 0-2.121.44-2.56C${x + .878} ${y} ${x + 1.585} ${y} ${x + 3} ${y}s2.121 0 2.56.44C${x + 6} ${y + .878} ${x + 6} ${y + 1.585} ${x + 6} ${y + 3}s0 2.121-.44 2.56C${x + 5.122} ${y + 6} ${x + 4.415} ${y + 6} ${x + 3} ${y + 6}s-2.121 0-2.56-.44C${x} ${y + 5.122} ${x} ${y + 4.415} ${x} ${y + 3}Z"/>`;
const KEY_RING = '<path d="M15.5 19.735a2.23 2.23 0 0 1-2.245 2.23c-1.236 0-2.255-.986-2.255-2.23a2.25 2.25 0 0 1 2.255-2.244c1.236 0 2.245 1 2.245 2.244Z"/>';
const KEY_BIT = '<path d="m22 15.848l-1.627-1.54c-.773-.739-1.423-.093-1.747.183l-1.41 1.357l-1.991 1.943m1.99-1.943l1.61 1.546"/>';
const PENCIL_CAP = '<path d="M16.425 4.605l.99-.99a2.1 2.1 0 0 1 2.97 2.97l-.99.99Z"/>';
const COIN_FRONT = '<path d="M9 11c0-1.105 2.91-2 6.5-2s6.5.895 6.5 2v8.8c0 1.215-2.91 2.2-6.5 2.2S9 21.015 9 19.8Z"/>';
const INBOX = 'M2.5 12c0-4.478 0-6.718 1.391-8.109S7.521 2.5 12 2.5c4.478 0 6.718 0 8.109 1.391S21.5 7.521 21.5 12c0 4.478 0 6.718-1.391 8.109S16.479 21.5 12 21.5c-4.478 0-6.718 0-8.109-1.391S2.5 16.479 2.5 12Z';
const TRAY = 'M21.5 13.5h-4.926c-.842 0-1.503.704-1.875 1.447c-.403.808-1.21 1.553-2.699 1.553s-2.296-.745-2.7-1.553c-.37-.743-1.032-1.447-1.874-1.447H2.5';
const SOLID: Record<BadgeIconName, SolidParts> = {
pass: { base: [C10], cuts: ['<path d="m8 12.5l2.5 2.5L16 9"/>'] },
fail: { base: [C10], cuts: ['<path d="M15 9l-6 6M9 9l6 6"/>'] },
warning: { base: ['<path d="M13.925 21h-3.85c-4.63 0-6.945 0-7.799-1.506c-.853-1.506.331-3.503 2.7-7.495L6.9 8.753C9.176 4.918 10.313 3 12 3s2.824 1.918 5.1 5.753L19.023 12c2.369 3.992 3.553 5.989 2.7 7.495C20.87 21 18.555 21 13.925 21Z"/>'],
cuts: ['<path d="M12 9v4"/>', '<circle cx="12" cy="16.75" r="1.1"/>'] },
skip: { base: ['<path d="M15.935 12.626c-.254 1.211-1.608 2.082-4.315 3.822c-2.945 1.893-4.417 2.84-5.61 2.475a2.8 2.8 0 0 1-1.088-.635C4 17.418 4 15.612 4 12s0-5.418.922-6.288a2.8 2.8 0 0 1 1.089-.635c1.192-.365 2.664.582 5.609 2.475c2.707 1.74 4.06 2.61 4.315 3.822c.087.412.087.84 0 1.252Z"/>'],
acc: ['<rect x="18.85" y="4.25" width="2.3" height="15.5" rx="1.15"/>'] },
shield: { base: [SHIELD], cuts: ['<path d="M12 8v4"/>', '<circle cx="12" cy="15.75" r="1.1"/>'] },
sparkle: { base: ['<path d="M9.853 4.865L8.758 8.697a3 3 0 0 1-2.06 2.06l-3.833 1.096a1.193 1.193 0 0 0 0 2.294l3.832 1.095a3 3 0 0 1 2.06 2.06l1.096 3.833a1.193 1.193 0 0 0 2.294 0l1.095-3.833a3 3 0 0 1 2.06-2.06l3.833-1.095a1.193 1.193 0 0 0 0-2.294l-3.832-1.095a3 3 0 0 1-2.06-2.06l-1.096-3.833a1.193 1.193 0 0 0-2.294 0Z"/>'],
acc: ['<path d="M22 4.5l-1.084-.361a1.67 1.67 0 0 1-1.055-1.055L19.5 2l-.361 1.084a1.67 1.67 0 0 1-1.055 1.055L17 4.5l1.084.361c.498.166.889.557 1.055 1.055L19.5 7l.361-1.084a1.67 1.67 0 0 1 1.055-1.055Z"/>'] },
lock: { base: ['<path d="M2.6 13.2c.05-2.65.9-4.15 3.66-4.2c1.56-.03 2.48-.075 4.43-.075s3.68.075 3.68.075c2.6-.06 3.65 1.6 3.65 3.9v5.4c0 2.5-1.5 3.6-3.9 3.6H6.6c-2.85 0-4-1.15-4-3.55Z"/>'],
lines: ['<path d="M5.984 8.196c-.05-2.375-.15-4.25 2.603-5.801c.926-.375 2.303-.7 4.005.1c1.777 1.075 1.999 2.213 2.153 2.5c.425 1.126.2 2.726.25 3.376"/>', KEY_RING, KEY_BIT],
halos: [KEY_RING, KEY_BIT] },
clock: { base: ['<circle cx="12" cy="12" r="10"/>'], cuts: ['<path d="M12 8v4l2 2"/>'] },
gavel: { base: [SHIELD], cuts: ['<path f="1" d="M11.833 12.167c1.055 1.055 2.445 2.127 2.445 2.127l1.905-1.905s-1.072-1.39-2.127-2.445s-2.445-2.127-2.445-2.127L9.706 9.722s1.072 1.39 2.127 2.445Z"/>', '<path d="M11.833 12.167L8.5 15.5M16.5 12.071l-2.54 2.54M11.93 7.5l-2.54 2.54"/>'] },
globe: { base: ['<circle cx="12" cy="12" r="10"/>'], cuts: ['<path d="M8 12c0 6 4 10 4 10s4-4 4-10s-4-10-4-10s-4 4-4 10Z"/>', '<path d="M21 15H3m18-6H3"/>'] },
rocket: { base: ['<path d="M9.74 6.681c3.67-4.091 7.434-4.953 9.854-4.614a2.156 2.156 0 0 1 1.84 1.84c.338 2.419-.524 6.182-4.615 9.853c-1.323 1.167-3.173 2.465-4.937 3.52L6.219 11.618c1.055-1.764 2.353-3.614 3.52-4.937Z"/>'],
acc: ['<path d="M6.219 11.618l-2.907-.38c-.596-.077-.993-.654-.729-1.192C3.425 8.334 5.62 6.354 9.74 6.68c-1.167 1.323-2.465 3.173-3.52 4.937Z"/>', '<path d="M11.882 17.281l.38 2.907c.077.596.654.993 1.192.729c1.712-.842 3.692-3.036 3.365-7.157c-1.323 1.167-3.173 2.465-4.937 3.52Z"/>'],
cuts: ['<circle class="ring" cx="15.5" cy="8" r="2"/>'], lines: ['<path d="M4 22l4-4m-4-1l1.5-1.5"/>'] },
target: { bline: ['<path d="M14 2.2q-.97-.198-2-.2C6.477 2 2 6.477 2 12s4.477 10 10 10s10-4.477 10-10q-.002-1.03-.2-2"/>'],
lines: ['<path d="M17 12a5 5 0 1 1-5-5"/>', '<path d="M12.03 11.963l4.553-4.553"/>'],
acc: ['<path d="M19.74 4.345l-.553-1.988a.48.48 0 0 0-.761-.24c-1.436 1.173-3 2.754-1.723 5.247c2.574 1.2 4.044-.418 5.17-1.779a.486.486 0 0 0-.248-.775Z"/>'] },
play: { base: [`<path d="${PLAY}"/>`],
bulk: ['<path class="s a" d="M19.02 12c0 .287-.044.57-.13.846c-.353 1.343-2.023 2.292-5.364 4.19c-3.23 1.835-4.845 2.752-6.146 2.384a3.25 3.25 0 0 1-1.424-.841C5 17.614 5 15.743 5 12Z"/>'] },
pause: { base: ['<path d="M4 7c0-1.414 0-2.121.44-2.56C4.878 4 5.585 4 7 4s2.121 0 2.56.44C10 4.878 10 5.585 10 7v10c0 1.414 0 2.121-.44 2.56C9.122 20 8.415 20 7 20s-2.121 0-2.56-.44C4 19.122 4 18.415 4 17Z"/>'],
acc: ['<path d="M14 7c0-1.414 0-2.121.44-2.56C14.878 4 15.585 4 17 4s2.121 0 2.56.44C20 4.878 20 5.585 20 7v10c0 1.414 0 2.121-.44 2.56c-.439.44-1.146.44-2.56.44s-2.121 0-2.56-.44C14 19.122 14 18.415 14 17Z"/>'] },
pencil: { base: ['<path d="M16.425 4.605l-6.66 6.66a3.96 3.96 0 0 0-1.041 1.84L8 16l2.896-.724a3.96 3.96 0 0 0 1.84-1.042l6.659-6.659Z"/>'],
acc: [PENCIL_CAP], halos: ['<path d="M16.425 4.605l2.97 2.97"/>'],
lines: ['<path d="M19 13.5c0 3.288 0 4.931-.908 6.038a4 4 0 0 1-.554.554C16.43 21 14.788 21 11.5 21H11c-3.771 0-5.657 0-6.828-1.172S3 16.771 3 13v-.5c0-3.287 0-4.931.908-6.038q.25-.304.554-.554C5.57 5 7.212 5 10.5 5"/>'] },
inbox: { solid: [`<path class="s" mask="CUT" d="${INBOX}"/>`],
bulk: ['<path class="s" d="M2.5 13.5h5.426c.842 0 1.503.704 1.875 1.447c.403.808 1.21 1.553 2.699 1.553s2.296-.745 2.7-1.553c.37-.743 1.032-1.447 1.874-1.447H21.5c-.03 3.38-.17 5.32-1.391 6.609C18.718 21.5 16.478 21.5 12 21.5s-6.718 0-8.109-1.391C2.67 18.82 2.53 16.88 2.5 13.5Z"/>',
`<path class="sl" d="${INBOX}"/>`, `<path class="sl" d="${TRAY}"/>`],
cuts: [`<path d="${TRAY}"/>`], cutsSolidOnly: true },
nodes: { base: [SQ(9, 2), SQ(2, 16), SQ(16, 16)],
lines: ['<path d="M12 8v1c0 .932 0 1.398-.178 1.765c-.236.49-.69.88-1.262 1.083C10.13 12 9.587 12 8.5 12s-1.63 0-2.06.152c-.571.203-1.026.593-1.262 1.083C5 13.602 5 14.068 5 15v1M12 9c0 .932 0 1.398.178 1.765c.236.49.69.88 1.262 1.083c.43.152.973.152 2.06.152s1.63 0 2.06.152c.571.203 1.026.593 1.262 1.083c.178.367.178.833.178 1.765v1"/>'] },
coins: { base: ['<path d="M2 4c0-1.105 2.91-2 6.5-2S15 2.895 15 4v5.05c-2.8.2-5.1.95-5.8 1.95H9v10H6c-1.892-.23-3.63-.826-4-2Z"/>'],
cuts: ['<path d="M2 4c0 1.105 2.91 2 6.5 2S15 5.105 15 4M2 9c.37 1.175 2.108 1.77 4 2m-4 3c.37 1.175 2.108 1.77 4 2"/>'],
acc: [COIN_FRONT], halos: [COIN_FRONT],
accCuts: ['<path d="M9 11c0 1.105 2.91 2 6.5 2s6.5-.895 6.5-2M22 15.5c0 1.105-2.91 2-6.5 2s-6.5-.895-6.5-2"/>'] },
// citation sources (28 Nov): a file, the page filled with its text lines and corner fold cut out; a link, the same two loops, heavier
file: { base: ['<path d="M20 13.343V10c0-3.771 0-5.657-1.172-6.828S15.771 2 12 2S6.343 2 5.172 3.172S4 6.229 4 10v4.544c0 3.245 0 4.868.886 5.967a4 4 0 0 0 .603.603C6.59 22 8.211 22 11.456 22c.705 0 1.058 0 1.381-.114q.1-.036.197-.082c.31-.148.559-.397 1.058-.896l4.736-4.736c.579-.578.867-.867 1.02-1.235c.152-.368.152-.776.152-1.594Z"/>'],
cuts: ['<path d="M8 7h8M8 11h4"/>', '<path d="M13 21.5V21c0-2.828 0-4.243.879-5.121C14.757 15 16.172 15 19 15h.5"/>'] },
link: { heavy: ['<path d="m9.143 10.691l.207-.207a5.067 5.067 0 1 1 7.166 7.166l-2.866 2.866a5.067 5.067 0 1 1-7.166-7.166l.464-.464"/>',
'<path d="m17.052 11.114l.464-.464a5.067 5.067 0 1 0-7.166-7.166L7.484 6.35a5.067 5.067 0 1 0 7.166 7.166l.207-.207"/>'] },
};
/** The drawing's classes, as the port names them (foundation.css section 8). */
const PART: Record<string, string> = {
s: "pixilui-s",
bl: "pixilui-bl",
sl: "pixilui-sl",
hv: "pixilui-hv",
"m-on": "pixilui-m-on",
"m-cut": "pixilui-m-cut",
"m-acut": "pixilui-m-acut",
"m-halo": "pixilui-m-halo",
fillcut: "pixilui-fillcut",
kc: "pixilui-kc",
bk: "pixilui-bk",
};
const renameParts = (svg: string) => svg.replace(/class="([^"]*)"/g, (_, list: string) => `class="${list.split(" ").map((c) => PART[c] ?? c).join(" ")}"`);
/** The locked tagSolid drawing: the masks, the filled shapes, the lines (Bulk's parts are drawn and hidden, as locked). */
function drawSolid(ic: SolidParts, A: string, B: string): string {
// a cut inside a mask is black; a dot or a filled shape fills, anything else is a line
const cut = (el: string, cls: string) => {
const fills = (/^<circle/.test(el) && !/class="ring"/.test(el)) || /\sf="1"/.test(el);
return el.replace(' class="ring"', "").replace(/^<(\w+)/, `<$1 class="${cls}${fills ? " fillcut" : ""}"`);
};
const tag = (el: string, cls: string) => el.replace(/^<(\w+)/, `<$1 class="${cls}"`);
const only = (list: string[] | undefined, cls: string) =>
(list ?? []).map((e) => e.replace(/^<(\w+) class="([^"]*)"/, `<$1 class="$2 ${cls}"`).replace('mask="CUT"', `mask="url(#${A})"`)).join("");
const maskA = `<mask id="${A}" maskUnits="userSpaceOnUse" x="-2" y="-2" width="28" height="28"><rect class="m-on" x="-2" y="-2" width="28" height="28"/>${(ic.halos ?? []).map((e) => cut(e, "m-halo")).join("")}${(ic.cuts ?? []).map((e) => cut(e, "m-cut")).join("")}</mask>`;
const maskB = `<mask id="${B}" maskUnits="userSpaceOnUse" x="-2" y="-2" width="28" height="28"><rect class="m-on" x="-2" y="-2" width="28" height="28"/>${(ic.accCuts ?? []).map((e) => cut(e, "m-acut")).join("")}</mask>`;
const base = `<g mask="url(#${A})">${(ic.base ?? []).map((e) => tag(e, "s")).join("")}${(ic.bline ?? []).map((e) => tag(e, "bl")).join("")}</g>`;
const acc = `<g mask="url(#${B})">${(ic.acc ?? []).map((e) => tag(e, "s a")).join("")}</g>`;
const lines = (ic.lines ?? []).map((e) => tag(e, "sl")).join("") + (ic.heavy ?? []).map((e) => tag(e, "sl hv")).join("");
const kc = ic.cutsSolidOnly ? "" : (ic.cuts ?? []).map((e) => cut(e, "kc")).join("");
return renameParts(`<defs>${maskA}${maskB}</defs>${base}${acc}${lines}${kc}${only(ic.solid, "nb")}${only(ic.bulk, "bk")}`);
}
export type BadgeIconProps = Omit<ComponentPropsWithoutRef<"svg">, "children" | "dangerouslySetInnerHTML"> & {
/** Which Solid icon. */
name: BadgeIconName;
};
/** A Solid icon for a tag: filled in the tag's hue, its inner lines cut through. Decorative. */
export const BadgeIcon = forwardRef<SVGSVGElement, BadgeIconProps>(function BadgeIcon({ name, className, ...props }, ref) {
const id = useId().replace(/[^\w-]/g, "");
return (
<svg
ref={ref}
className={cn("pixilui-i pixilui-tag-solid", className)}
viewBox="0 0 24 24"
aria-hidden="true"
dangerouslySetInnerHTML={{ __html: drawSolid(SOLID[name], `pxt${id}a`, `pxt${id}b`) }}
{...props}
/>
);
});
/* ------------------------------------------------------------------ tag and badge */
export type BadgeTone = "neutral" | "ok" | "bad" | "wait" | "think" | "read" | "tool" | "edit";
export type BadgeTagProps = Omit<ComponentPropsWithoutRef<"span">, "children"> & {
/** The words. */
children?: ReactNode;
/** ok, bad, wait and think are the status colors; read, tool and edit the meaning hues; neutral is grey. */
tone?: BadgeTone;
/** md 30 (the default), sm 24. Not used inline. */
size?: "md" | "sm";
/** A leading icon, usually a BadgeIcon. */
icon?: ReactNode;
/** pill (a tag) or inline (a badge: icon and word, no pill). */
variant?: "pill" | "inline";
};
/** The icon with the part's class, so the tag sizes and colors it. */
const leading = (icon: ReactNode) => {
if (!isValidElement(icon)) return icon;
const el = icon as ReactElement<{ className?: string }>;
return el.type === BadgeIcon || /(^|\s)pixilui-i(\s|$)/.test(el.props.className ?? "") ? el : cloneElement(el, { className: cn("pixilui-i", el.props.className) });
};
/** A fixed fact about a run, as a pill in its status color or meaning hue. */
export const BadgeTag = forwardRef<HTMLSpanElement, BadgeTagProps>(function BadgeTag({ children, tone = "neutral", size = "md", icon, variant = "pill", className, ...props }, ref) {
return (
<span
ref={ref}
className={cn("pixilui-tag font-body", className)}
data-tone={tone === "neutral" ? undefined : tone}
data-size={size === "md" ? undefined : size}
data-variant={variant === "inline" ? "inline" : undefined}
{...props}
>
{leading(icon)}
{children}
</span>
);
});
export type BadgeProps = Omit<BadgeTagProps, "variant">;
/** A status as an icon and a word, inline in a table or a meta line: grey words, the hue only for wait and bad. */
export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(function Badge(props, ref) {
return <BadgeTag ref={ref} {...props} variant="inline" />;
});
/* ------------------------------------------------------------------ count */
export type BadgeCountProps = Omit<ComponentPropsWithoutRef<"span">, "children"> & {
/** The number. Leave it out with dot. */
children?: ReactNode;
/** md 18 (the default), sm 16. */
size?: "md" | "sm";
/** accent: the accent tint with deep accent numbers. */
tone?: "neutral" | "accent";
/** An 8px accent dot for "new" instead of a number; give it an aria-label. */
dot?: boolean;
/** The ring around the dot: the surface it sits on (defaults to the surface). */
ring?: string;
};
/** A small number beside a name, or a dot for "new". */
export const BadgeCount = forwardRef<HTMLSpanElement, BadgeCountProps>(function BadgeCount({ children, size = "md", tone = "neutral", dot, ring, className, style, ...props }, ref) {
return (
<span
ref={ref}
className={cn("pixilui-count font-body", className)}
data-size={size === "md" ? undefined : size}
data-tone={tone === "accent" ? "accent" : undefined}
data-dot={dot ? "" : undefined}
style={ring ? ({ "--pixilui-count-dot-ring": ring, ...style } as CSSProperties) : style}
{...props}
>
{dot ? null : children}
</span>
);
});
Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
example.tsx
import { Badge } from "@/components/pixilui/badge";
<Badge>Save changes</Badge>A tag keeps its words on one line; a badge wraps with the line it sits in.
API reference
PropTypeDefault
tone"neutral" | "ok" | "bad" | "wait" | "think" | "read" | "tool" | "edit"–ok, bad, wait and think are the status colors; read, tool and edit the meaning hues; neutral is grey.size"md" | "sm"–md 30 (the default), sm 24. Not used inline.iconReactNode–A leading icon, usually a BadgeIcon.childrenReactNode–The words.Keyboard
TabNever takes focus: tags, badges and counts are not interactive.
Accessibility
- Tags and badges are text: the word carries the meaning, and the icon is aria-hidden.
- Never color alone: each tone pairs its hue with a word and, where given, its own solid icon.
- A count is text; a dot count has no text, so give it an aria-label ("New").
- Every word passes 4.5:1 in both themes.
Motion
- None: a tag is a fixed fact. A state that changes belongs in Agent status.