Badge

Small labels: brand tint, neutral and outline.

NewRecommendedBetav2.1

Install

$ npx shadcn@latest add @nudgekit/badge

Or with no config: npx shadcn@latest add https://ui.nudgekit.app/r/badge.json

Brings in class-variance-authority, and the theme.

Usage

usage.tsx
import { Badge } from "@/components/ui/badge"

<Badge>New</Badge>
<Badge variant="neutral">Beta</Badge>
<Badge variant="outline">v2.1</Badge>

Do

  • Keep it to one or two words.
  • Use brand for New and Recommended only.

Don't

  • Use a badge for status; use Status.
  • Put more than one badge on a card.

Code

What the CLI writes into your project. It is yours to change.

components/ui/badge.tsx
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";

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

const badgeVariants = cva(
  "inline-flex items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 py-0.5 text-xs font-medium",
  {
    variants: {
      variant: {
        brand: "bg-brand-tint text-brand-ink",
        neutral: "bg-surface text-muted-foreground ring-1 ring-inset ring-border",
        outline: "text-foreground ring-1 ring-inset ring-line-strong",
      },
    },
    defaultVariants: { variant: "brand" },
  },
);

function Badge({
  className,
  variant,
  ...props
}: React.HTMLAttributes<HTMLSpanElement> & VariantProps<typeof badgeVariants>) {
  return <span data-slot="badge" className={cn(badgeVariants({ variant }), className)} {...props} />;
}

export { Badge, badgeVariants };