badge.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import * as React from "react"
  2. import { cva, type VariantProps } from "class-variance-authority"
  3. import { cn } from "@/lib/utils"
  4. const badgeVariants = cva(
  5. "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
  6. {
  7. variants: {
  8. variant: {
  9. default:
  10. "border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
  11. secondary:
  12. "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
  13. destructive:
  14. "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
  15. outline: "text-foreground",
  16. },
  17. },
  18. defaultVariants: {
  19. variant: "default",
  20. },
  21. }
  22. )
  23. export interface BadgeProps
  24. extends React.HTMLAttributes<HTMLDivElement>,
  25. VariantProps<typeof badgeVariants> {}
  26. function Badge({ className, variant, ...props }: BadgeProps) {
  27. return (
  28. <div className={cn(badgeVariants({ variant }), className)} {...props} />
  29. )
  30. }
  31. export { Badge, badgeVariants }