badge.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as React from "react"
  2. import { Slot } from "@radix-ui/react-slot"
  3. import { cva } from "class-variance-authority";
  4. import { cn } from "@/lib/utils"
  5. const badgeVariants = cva(
  6. "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",
  7. {
  8. variants: {
  9. variant: {
  10. default:
  11. "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
  12. secondary:
  13. "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
  14. destructive:
  15. "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",
  16. outline:
  17. "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
  18. },
  19. },
  20. defaultVariants: {
  21. variant: "default",
  22. },
  23. }
  24. )
  25. function Badge({
  26. className,
  27. variant,
  28. asChild = false,
  29. ...props
  30. }) {
  31. const Comp = asChild ? Slot : "span"
  32. return (
  33. <Comp
  34. data-slot="badge"
  35. className={cn(badgeVariants({ variant }), className)}
  36. {...props} />
  37. );
  38. }
  39. export { Badge, badgeVariants }