Data display

Badge

Mono small-caps status pill. Colour is severity.

Preview
Neutral
In use
Stale
Fresh
Manual
Install
npx shadcn@latest add https://ui.thjsecurity.tech/r/badge.json

Pulls the component into components/ui/badge.tsx and its token dependencies. The app owns the copy from then on.

Dependencies
class-variance-authority
Source
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

/** Mono small-caps pill on a soft tint (`.pill` in globals.css). Colour
 *  carries severity, never category: crimson, orange, amber, sage, stone. */
const badgeVariants = cva("pill", {
  variants: {
    variant: {
      default: "",
      secondary: "",
      destructive: "pill-signal",
      outline: "border border-glass-border bg-transparent text-paper-dim",
      critical: "pill-signal",
      high: "bg-sev-high/15 text-sev-high",
      medium: "pill-amber",
      low: "pill-sage",
      info: "",
    },
  },
  defaultVariants: {
    variant: "default",
  },
})

export interface BadgeProps
  extends React.HTMLAttributes<HTMLDivElement>,
    VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
  return (
    <div className={cn(badgeVariants({ variant }), className)} {...props} />
  )
}

export { Badge, badgeVariants }