implement
Badge

Badge

A small status marker.

DefaultSecondaryOutlineDestructiveVerified8
import { Div } from "@implementjs/core";
import { CircleCheckIcon } from "@implementjs/lucide";
import { Badge } from "@/lib/components/ui/badge";

export default function BadgeDemo() {
	return Div(
		{ class: "flex flex-wrap items-center justify-center gap-2" },
		Badge("Default"),
		Badge({ variant: "secondary" }, "Secondary"),
		Badge({ variant: "outline" }, "Outline"),
		Badge({ variant: "destructive" }, "Destructive"),
		Badge(CircleCheckIcon({ "aria-hidden": true }), "Verified"),
		Badge({ variant: "secondary", class: "rounded-full px-1.5 tabular-nums" }, "8"),
	);
}

Installation

npx jsrepo add @implementjs/ui/badge

It installs tailwind-variants at the same time.

Usage

import { Badge } from "@/lib/components/ui/badge";

Badge("Default");
Badge({ variant: "outline" }, "Draft");
Badge({ variant: "destructive" }, "Failed");

Badge renders a Span. For a badge that navigates, put badgeVariants() on an A instead:

import { badgeVariants } from "@/lib/components/ui/badge";

A({ href: "/releases", class: badgeVariants({ variant: "outline" }) }, "v2.1.0");

The hover rules are written against [a&], so they only switch on once the badge really is a link — a Span badge does not pretend to be clickable.

Counts

A round count is a class, not a variant:

Badge({ variant: "secondary", class: "rounded-full px-1.5 tabular-nums" }, "8");

tabular-nums keeps the badge from resizing as the number ticks.

API Reference

Badge

A status marker. `badgeVariants` is exported so a badge that navigates can be an `A` instead — the hover rules only apply once it really is a link. Renders a Span; extra props are forwarded onto it.

PropTypeDefaultDescription
variant"default" | "secondary" | "destructive" | "outline""default"Which badge style to render. Also set as data-variant.