Open History to see the last commit
1import { Slot } from "@radix-ui/react-slot";
2import { cva, type VariantProps } from "class-variance-authority";
3import type * as React from "react";
4
5import { cn } from "@/lib/utils";
6
7const badgeVariants = cva(
8 "inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
9 {
10 variants: {
11 variant: {
12 default:
13 "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
14 secondary:
15 "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
16 destructive:
17 "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
18 outline:
19 "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
20 neutral:
21 "border-transparent bg-muted text-muted-foreground [a&]:hover:bg-muted/90",
22 },
23 },
24 defaultVariants: {
25 variant: "default",
26 },
27 },
28);
29
30function Badge({
31 className,
32 variant,
33 asChild = false,
34 ...props
35}: React.ComponentProps<"span"> &
36 VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
37 const Comp = asChild ? Slot : "span";
38
39 return (
40 <Comp
41 data-slot="badge"
42 className={cn(badgeVariants({ variant }), className)}
43 {...props}
44 />
45 );
46}
47
48export { Badge, badgeVariants };