badge.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import * as React from "react"
  2. import { cn } from "@/lib/utils"
  3. export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement> {
  4. variant?: 'default' | 'secondary' | 'destructive' | 'outline'
  5. }
  6. function Badge({ className, variant = 'default', ...props }: BadgeProps) {
  7. const getVariantClasses = () => {
  8. switch (variant) {
  9. case 'default':
  10. return "border-transparent bg-primary text-primary-foreground hover:bg-primary/80"
  11. case 'secondary':
  12. return "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80"
  13. case 'destructive':
  14. return "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80"
  15. case 'outline':
  16. return "text-foreground"
  17. default:
  18. return "border-transparent bg-primary text-primary-foreground hover:bg-primary/80"
  19. }
  20. }
  21. return (
  22. <div
  23. className={cn(
  24. "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",
  25. getVariantClasses(),
  26. className
  27. )}
  28. {...props}
  29. />
  30. )
  31. }
  32. export { Badge }