File size: 1,595 Bytes
057576a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';

const Button = ({ 

  children, 

  variant = 'primary', 

  size = 'medium',

  disabled = false,

  loading = false,

  onClick,

  type = 'button',

  className = '',

  ...props 

}) => {
  const baseClasses = 'font-medium rounded-lg transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed';
  
  const variants = {
    primary: 'bg-primary-500 hover:bg-primary-600 text-white focus:ring-primary-500',
    secondary: 'bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-900 dark:text-white focus:ring-gray-500',
    danger: 'bg-red-500 hover:bg-red-600 text-white focus:ring-red-500',
    ghost: 'bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300 focus:ring-gray-500'
  };

  const sizes = {
    small: 'px-3 py-1.5 text-sm',
    medium: 'px-4 py-2 text-sm',
    large: 'px-6 py-3 text-base'
  };

  const classes = `

    ${baseClasses}

    ${variants[variant]}

    ${sizes[size]}

    ${className}

  `.trim();

  return (
    <button

      type={type}

      className={classes}

      disabled={disabled || loading}

      onClick={onClick}

      {...props}

    >

      {loading ? (

        <div className="flex items-center justify-center space-x-2">

          <div className="animate-spin rounded-full h-4 w-4 border-b-2 border-current"></div>

          <span>Loading...</span>

        </div>

      ) : (

        children

      )}

    </button>
  );
};

export default Button;