quadratic/ui

Badge

Displays a badge or a component that looks like a badge.

Badge

Installation

Copy and paste the following code into your project.

import type { VariantProps } from "tailwind-variants";

import { cn, tv } from "~/utils/tailwind";

const badgeVariants = tv({
  base: "inline-flex h-7 items-center rounded-full px-2.5 text-3.5 font-medium",
  variants: {
    variant: {
      default: "bg-primary text-primary-foreground",
      secondary: "bg-secondary text-secondary-foreground",
      outline: "border text-foreground",
      destructive: "bg-destructive text-destructive-foreground",
      "destructive-outline":
        "border border-destructive-border text-destructive-foreground",
      warning: "bg-warning text-warning-foreground",
      "warning-outline": "border border-warning-border text-warning-foreground",
      success: "bg-success text-success-foreground",
      "success-outline": "border border-success-border text-success-foreground",
    },
  },
  defaultVariants: {
    variant: "default",
  },
});

export interface BadgeProps
  extends React.ComponentProps<"div">,
    VariantProps<typeof badgeVariants> {}

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

export { Badge, badgeVariants };

Update the import paths to match your project setup.

Usage

import { Badge } from "~/components/ui/Badge";
<Badge>Badge</Badge>

Next.js Link

Use the badgeVariants helper to make <Link /> look like <Badge />.

import Link from "next/link";
import { badgeVariants } from "~/components/ui/Badge";
<Link href="/" className={badgeVariants({ variant: "outline" })}>
    Home
</Link>

Examples

Default

Badge

Secondary

Badge

Outline

Badge

Destructive

Badge

Destructive Outline

Badge

Warning

Badge

Warning Outline

Badge

Success

Badge

Success Outline

Badge