Status Badge
Small pill that labels the state of a record in neutral, info, success, warning and destructive tones. Use it in tables and headers, always with a word and optionally an icon.
How it differs. The baseline pill: a text label with an optional leading icon in soft, solid and outline appearances, with no dot, count or action.
Install
pnpm dlx shadcn@latest add @hazine/status-badgeAdds 1 file, 1 package (class-variance-authority), and the success, warning, and info tokens.
First time? Add the registry to components.json
{
"registries": {
"@hazine": "https://api.hazine.dev/r/{name}.json"
}
}Needed once per project. Items resolve each other through the @hazine namespace.
components/hazine/status-badge.tsx, 78 lines
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
export const statusBadgeVariants = cva(
"inline-flex min-h-6 items-center gap-1.5 rounded-full border px-2 text-xs font-medium whitespace-nowrap",
{
variants: {
tone: {
neutral: "",
info: "",
success: "",
warning: "",
destructive: "",
},
appearance: {
soft: "",
solid: "",
outline: "bg-background",
},
},
compoundVariants: [
{ tone: "neutral", appearance: "soft", className: "border-border bg-muted/50 text-foreground" },
{ tone: "neutral", appearance: "solid", className: "border-primary bg-primary text-primary-foreground" },
{ tone: "neutral", appearance: "outline", className: "border-foreground/50 text-foreground" },
{ tone: "info", appearance: "soft", className: "border-info/30 bg-info/10 text-info" },
{ tone: "info", appearance: "solid", className: "border-info bg-info text-info-foreground" },
{ tone: "info", appearance: "outline", className: "border-info/50 text-info" },
{ tone: "success", appearance: "soft", className: "border-success/30 bg-success/10 text-success" },
{ tone: "success", appearance: "solid", className: "border-success bg-success text-success-foreground" },
{ tone: "success", appearance: "outline", className: "border-success/50 text-success" },
{ tone: "warning", appearance: "soft", className: "border-warning/30 bg-warning/10 text-warning" },
{ tone: "warning", appearance: "solid", className: "border-warning bg-warning text-warning-foreground" },
{ tone: "warning", appearance: "outline", className: "border-warning/50 text-warning" },
// No tint: host destructive on its own /10 tint measures 4.0:1 in the stock light theme.
{ tone: "destructive", appearance: "soft", className: "border-destructive/30 bg-background text-destructive" },
{ tone: "destructive", appearance: "solid", className: "border-destructive bg-destructive text-background" },
{ tone: "destructive", appearance: "outline", className: "border-destructive/50 text-destructive" },
],
defaultVariants: {
tone: "neutral",
appearance: "soft",
},
}
)
export interface StatusBadgeProps
extends React.ComponentProps<"span">,
VariantProps<typeof statusBadgeVariants> {
/** Decorative icon before the label, sized by the caller (size-3.5 fits). */
icon?: React.ReactNode
}
export function StatusBadge({
tone = "neutral",
appearance = "soft",
icon,
className,
children,
...props
}: StatusBadgeProps) {
return (
<span
data-slot="status-badge"
data-tone={tone}
className={cn(statusBadgeVariants({ tone, appearance }), className)}
{...props}
>
{icon && (
<span aria-hidden="true" className="flex shrink-0">
{icon}
</span>
)}
{children}
</span>
)
}
The demo in the preview, 52 lines
import {
CircleAlert,
CircleCheck,
CircleDashed,
Clock,
Info,
} from "lucide-react"
import { StatusBadge, type StatusBadgeProps } from "@/components/hazine/status-badge"
const INVOICE_STATES = [
{ label: "Paid", tone: "success", icon: CircleCheck },
{ label: "Due in 3 days", tone: "warning", icon: Clock },
{ label: "In review", tone: "info", icon: Info },
{ label: "Payment failed", tone: "destructive", icon: CircleAlert },
{ label: "Draft", tone: "neutral", icon: CircleDashed },
] as const
function InvoiceStates({ appearance }: Pick<StatusBadgeProps, "appearance">) {
return (
<ul className="flex flex-wrap gap-2">
{INVOICE_STATES.map((state) => (
<li key={state.label}>
<StatusBadge
tone={state.tone}
appearance={appearance}
icon={<state.icon className="size-3.5" />}
>
{state.label}
</StatusBadge>
</li>
))}
</ul>
)
}
export default function StatusBadgeDemo() {
return <InvoiceStates appearance="soft" />
}
function StatusBadgeSolid() {
return <InvoiceStates appearance="solid" />
}
function StatusBadgeOutline() {
return <InvoiceStates appearance="outline" />
}
export const scenarios = {
solid: StatusBadgeSolid,
outline: StatusBadgeOutline,
}
Props1
- icon
- React.ReactNode
- Decorative icon before the label, sized by the caller (size-3.5 fits).
Also accepts every prop of React.ComponentProps<"span"> and VariantProps<typeof statusBadgeVariants>.
Accessibility
- Pattern
- Landmarks and headings
- Keyboard
- Nothing to operate. The item has no focusable parts.
- Screen reader
A span with a text label. The status is carried by the word, the icon is decorative and hidden from assistive technology.
- Reduced motion
- No motion.
- Checked
- Not checked yet. Automated results appear here once CI has run.
Dependencies1
- class-variance-authority
Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.
Tokens shipped6
- --success
- --success-foreground
- --warning
- --warning-foreground
- --info
- --info-foreground
Added to your stylesheet in light and dark, unless you already define them.