p441z/Components/Badge
UI · components/ui/badge.tsx

Badge

Small labels for tags, counts, and status.

51 linesclass-variance-authorityGitHub ↗
Install with the shadcn CLI

First time with the kit? Read the install guide

New
Draft
v1.0

About

Badge — small labels: tags, counts, categories.

For STATUS pills (Upcoming / Pending / Completed …) don't use these variants — use the tinted-status recipe instead, which reads better as a state than a solid fill:

Usage

bg-emerald-500/10 text-emerald-500 border-emerald-500/20

Source

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

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

/**
 * Badge — small labels: tags, counts, categories.
 *
 * For STATUS pills (Upcoming / Pending / Completed …) don't use these
 * variants — use the tinted-status recipe instead, which reads better as a
 * state than a solid fill:
 *
 *   bg-emerald-500/10 text-emerald-500 border-emerald-500/20
 *
 * The full status palette is in the README §"Status colors".
 *
 * v4 note: `outline-hidden` replaces v3's `outline-none`.
 */

const badgeVariants = cva(
  "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2",
  {
    variants: {
      variant: {
        default:
          "border-transparent bg-primary text-primary-foreground shadow-sm hover:bg-primary/80",
        secondary:
          "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
        destructive:
          "border-transparent bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/80",
        outline: "text-foreground",
      },
    },
    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 };