| 1 | import { type VariantProps, cva } from "class-variance-authority"; |
| 2 | import type { ComponentProps } from "react"; |
| 3 | |
| 4 | import { cn } from "../../lib/cn"; |
| 5 | |
| 6 | // shadcn/ui's badge, styled with g1t's tokens: a small outlined label whose |
| 7 | // tone says how much it matters. `sm` (the default) is the 11px label beside |
| 8 | // a title or in a table; `md` the 12px pill in a list of properties. |
| 9 | |
| 10 | export const badgeVariants = cva("inline-flex shrink-0 items-center gap-1 rounded-full border whitespace-nowrap", { |
| 11 | variants: { |
| 12 | tone: { |
| 13 | neutral: "border-line text-muted", |
| 14 | accent: "border-accent/40 bg-accent/10 text-accent", |
| 15 | success: "border-success/40 bg-success/10 text-success", |
| 16 | info: "border-info/40 bg-info/10 text-info", |
| 17 | merged: "border-merged/40 bg-merged/10 text-merged", |
| 18 | warn: "border-warn/40 bg-warn/10 text-warn", |
| 19 | danger: "border-danger/40 bg-danger/10 text-danger", |
| 20 | }, |
| 21 | size: { |
| 22 | sm: "px-2 py-px text-[0.6875rem] font-medium", |
| 23 | md: "px-2 py-0.5 text-xs", |
| 24 | }, |
| 25 | }, |
| 26 | defaultVariants: { tone: "neutral", size: "sm" }, |
| 27 | }); |
| 28 | |
| 29 | export type BadgeTone = NonNullable<VariantProps<typeof badgeVariants>["tone"]>; |
| 30 | |
| 31 | export function Badge({ tone, size, className, ...props }: ComponentProps<"span"> & VariantProps<typeof badgeVariants>) { |
| 32 | return <span data-slot="badge" className={cn(badgeVariants({ tone, size }), className)} {...props} />; |
| 33 | } |