A short label in neutral or toned soft, outline and solid styles.
softDraftIn reviewShippedOver budgetBlockedNew
outlineDraftIn reviewShippedOver budgetBlockedNew
solidDraftIn reviewShippedOver budgetBlockedNew
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Badge } from "./ui/uicontext/components/Badge.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ rows: { display: "grid", gap: 12 }, row: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 8 }, label: { inlineSize: "4.5rem", color: color.muted, fontSize: font.sm },})const tones = [ ["neutral", "Draft"], ["info", "In review"], ["success", "Shipped"], ["warning", "Over budget"], ["danger", "Blocked"], ["accent", "New"],] as const// soft for labels in a list, outline beside quiet text, solid for what must stand outexport const BadgeTones = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.rows)).children( (["soft", "outline", "solid"] as const).map((emphasis) => h.div.key(emphasis).attrs(sx(styles.row)).children( h.span.attrs(sx(styles.label)).children(emphasis), ...tones.map(([tone, label]) => Badge(h, { tone, emphasis }).key(tone).children(label)), )), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/badgeUsage
import { Badge } from "./ui/uicontext/components/Badge.ts"export const PlanBadge = <M>(h: Html.H<M>) => Badge(h, { tone: "accent" }).children("Team plan")Examples
Counts
pill and solid for counts. Give a bare number an aria-label that says what it counts.
- Inbox3
- Assigned to me12
- Failed runs99+
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Badge } from "./ui/uicontext/components/Badge.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ list: { display: "grid", gap: space.xs, inlineSize: "min(100%, 16rem)", margin: 0, padding: 0, listStyle: "none" }, item: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: space.md, fontSize: font.base, color: color.fg },})const inboxes = [ { name: "Inbox", count: 3, tone: "accent" as const }, { name: "Assigned to me", count: 12, tone: "neutral" as const }, { name: "Failed runs", count: 128, tone: "danger" as const },]export const Counts = <M>(h: Html.H<M>) => h.ul.attrs(sx(styles.list)).children( inboxes.map((inbox) => h.li.key(inbox.name).attrs(sx(styles.item)).children( inbox.name, // a count over 99 reads as 99+, so the column keeps its width Badge(h, { tone: inbox.tone, emphasis: inbox.tone === "neutral" ? "soft" : "solid", pill: true, size: "sm" }) .attr("aria-label", `${inbox.count} unread`) .children(inbox.count > 99 ? "99+" : String(inbox.count)), )), )With a dot
dot adds a small mark in the tone's color, for a state.
OnlineAway until 3 PMOffline
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Badge } from "./ui/uicontext/components/Badge.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ row: { display: "flex", flexWrap: "wrap", gap: 8 } })export const Presence = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.row)).children( Badge(h, { tone: "success", dot: true, emphasis: "outline" }).children("Online"), Badge(h, { tone: "warning", dot: true, emphasis: "outline" }).children("Away until 3 PM"), Badge(h, { tone: "neutral", dot: true, emphasis: "outline" }).children("Offline"), )API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
tone | "neutral" | "accent" | "danger" | "warning" | "success" | "info" | neutral | What it means; neutral by default |
emphasis | "soft" | "outline" | "solid" | — | Soft (a faint wash, the default), outline (a hairline) or solid (filled, for counts that must stand out) |
size | "sm" | "md" | md | The text size and padding; md by default. |
pill | boolean | — | Fully rounded, for counts |
dot | boolean | — | A small dot before the text in the tone's color |
style | Style | — | StyleX styles applied after the badge’s own. |
Accessibility
- Screen readers hear only its text, so the words must carry the meaning; color and the dot only add to it.