Button.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import type { ComponentPropsWithoutRef } from 'react';
  2. import { cn } from '../utils';
  3. export type ButtonProps = {
  4. theme?: 'light' | 'dark';
  5. variant?: 'primary' | 'secondary' | 'danger';
  6. disabled?: boolean;
  7. } & ComponentPropsWithoutRef<'button'>;
  8. export function Button({ theme, variant = 'primary', className, disabled, children, ...props }: ButtonProps) {
  9. return (
  10. <button
  11. className={cn(
  12. 'py-1 px-4 rounded shadow transition-all',
  13. {
  14. // Primary variant
  15. 'bg-blue-500 hover:bg-blue-600 text-white hover:scale-105':
  16. variant === 'primary' && !disabled && theme !== 'dark',
  17. 'bg-blue-600 hover:bg-blue-700 text-white hover:scale-105':
  18. variant === 'primary' && !disabled && theme === 'dark',
  19. 'bg-gray-400 text-gray-600 cursor-not-allowed': variant === 'primary' && disabled,
  20. // Secondary variant
  21. 'bg-gray-300 hover:bg-gray-400 text-gray-800 hover:scale-105': variant === 'secondary' && !disabled,
  22. 'bg-gray-100 text-gray-400 cursor-not-allowed': variant === 'secondary' && disabled,
  23. // Danger variant
  24. // Note: bg-red-400 causes the button to appear black (RGB 0,0,0) for unknown reasons
  25. // Using bg-red-500 with opacity to achieve a softer look
  26. 'bg-red-600 bg-opacity-80 hover:bg-red-700 hover:bg-opacity-90 text-white hover:scale-105':
  27. variant === 'danger' && !disabled && theme !== 'dark',
  28. 'bg-red-500 bg-opacity-70 hover:bg-red-700 hover:bg-opacity-90 text-white hover:scale-105':
  29. variant === 'danger' && !disabled && theme === 'dark',
  30. 'bg-red-300 bg-opacity-80 text-red-100 cursor-not-allowed': variant === 'danger' && disabled,
  31. },
  32. className,
  33. )}
  34. disabled={disabled}
  35. {...props}>
  36. {children}
  37. </button>
  38. );
  39. }