button.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { cva, type VariantProps } from "class-variance-authority";
  2. import type { ButtonHTMLAttributes } from "react";
  3. import { cn } from "@/lib/utils";
  4. const buttonVariants = cva(
  5. "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 touch-manipulation",
  6. {
  7. variants: {
  8. variant: {
  9. primary: "bg-accent text-accent-foreground hover:bg-accent-hover",
  10. secondary: "bg-muted text-foreground hover:bg-border",
  11. outline:
  12. "border border-border bg-transparent text-foreground hover:bg-muted",
  13. ghost: "text-muted-foreground hover:bg-muted hover:text-foreground",
  14. },
  15. size: {
  16. sm: "min-h-9 h-9 px-3 text-xs sm:min-h-8 sm:h-8",
  17. md: "min-h-11 h-11 px-4 sm:min-h-9 sm:h-9",
  18. lg: "min-h-12 h-12 px-5 sm:min-h-10 sm:h-10",
  19. icon: "min-h-11 min-w-11 h-11 w-11 sm:min-h-9 sm:min-w-9 sm:h-9 sm:w-9",
  20. },
  21. },
  22. defaultVariants: {
  23. variant: "primary",
  24. size: "md",
  25. },
  26. },
  27. );
  28. export interface ButtonProps
  29. extends ButtonHTMLAttributes<HTMLButtonElement>,
  30. VariantProps<typeof buttonVariants> {}
  31. export function Button({ className, variant, size, ...props }: ButtonProps) {
  32. return (
  33. <button
  34. className={cn(buttonVariants({ variant, size }), className)}
  35. {...props}
  36. />
  37. );
  38. }
  39. export { buttonVariants };