import { mergeProps } from "@base-ui/react/merge-props"; import { useRender } from "@base-ui/react/use-render"; import { cva, type VariantProps } from "class-variance-authority"; import type * as React from "react"; import { cn } from "../../lib/utils"; /** * Badge — small labelled token (status, category, count). Token-driven variants. * Pass `render` (e.g. `render={}`) to render as a link/button. * Override padding/size via className for tighter inline badges * (e.g. `px-1.5 py-px text-[10px]`). */ const badgeVariants = cva( "inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-auto whitespace-nowrap rounded-md border px-3 py-1 text-xs font-medium transition-[color,box-shadow] [&>svg]:size-3 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40", { variants: { variant: { default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90", secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90", destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40", outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground", }, }, defaultVariants: { variant: "default", }, }, ); function Badge({ className, variant, render, ...props }: useRender.ComponentProps<"span"> & VariantProps) { return useRender({ defaultTagName: "span", render, props: mergeProps<"span">( { "data-slot": "badge", className: cn(badgeVariants({ variant }), className) } as React.ComponentProps<"span">, props, ), }); } export { Badge, badgeVariants };