button.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import * as React from 'react';
  2. import { cn } from '@/lib/utils';
  3. export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  4. variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost';
  5. size?: 'default' | 'sm' | 'lg' | 'icon';
  6. }
  7. const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
  8. ({ className, variant = 'default', size = 'default', ...props }, ref) => {
  9. return (
  10. <button
  11. className={cn(
  12. 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors',
  13. 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
  14. 'disabled:pointer-events-none disabled:opacity-50',
  15. {
  16. 'bg-primary text-primary-foreground hover:bg-primary/90': variant === 'default',
  17. 'bg-destructive text-destructive-foreground hover:bg-destructive/90': variant === 'destructive',
  18. 'border border-input bg-background hover:bg-accent hover:text-accent-foreground': variant === 'outline',
  19. 'bg-secondary text-secondary-foreground hover:bg-secondary/80': variant === 'secondary',
  20. 'hover:bg-accent hover:text-accent-foreground': variant === 'ghost',
  21. },
  22. {
  23. 'h-10 px-4 py-2': size === 'default',
  24. 'h-9 rounded-md px-3': size === 'sm',
  25. 'h-11 rounded-md px-8': size === 'lg',
  26. 'h-10 w-10': size === 'icon',
  27. },
  28. className
  29. )}
  30. ref={ref}
  31. {...props}
  32. />
  33. );
  34. }
  35. );
  36. Button.displayName = 'Button';
  37. export { Button };