|
| 1 | +import { Loader } from 'react-feather'; |
| 2 | + |
| 3 | +// button variant based on color |
| 4 | +const COLOR_VARIANT_MAP = { |
| 5 | + solid: { |
| 6 | + primary: 'bg-blue-500 hover:bg-blue-700 text-white', |
| 7 | + secondary: 'bg-gray-500 hover:bg-gray-700 text-white', |
| 8 | + success: 'bg-green-500 hover:bg-green-700 text-white', |
| 9 | + danger: 'bg-red-500 hover:bg-red-700 text-white', |
| 10 | + warning: 'bg-orange-500 hover:bg-orange-700 text-white', |
| 11 | + info: 'bg-teal-500 hover:bg-teal-700 text-white', |
| 12 | + light: 'bg-gray-100 hover:bg-gray-200 text-gray-800', |
| 13 | + dark: 'bg-gray-800 hover:bg-gray-900 text-white', |
| 14 | + }, |
| 15 | + outlined: { |
| 16 | + primary: 'border-2 border-blue-800 text-blue-800', |
| 17 | + secondary: 'border-2 border-gray-800 text-gray-800', |
| 18 | + success: 'border-2 border-green-800 text-green-800', |
| 19 | + danger: 'border-2 border-red-800 text-red-800', |
| 20 | + warning: 'border-2 border-orange-800 text-orange-800', |
| 21 | + info: 'border-2 border-teal-800 text-teal-800', |
| 22 | + light: 'border-2 border-gray-100 text-gray-800', |
| 23 | + dark: 'border-2 border-gray-900 text-black', |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +const COMMON_CLASS = |
| 28 | + 'px-6 py-2 flex justify-center uppercase tracking-wider font-bold transition-all hover:ring-2 ring-offset-2 ring-black focus:outline-none focus:shadow-outline'; |
| 29 | + |
| 30 | +export default function Button({ |
| 31 | + loading, |
| 32 | + children, |
| 33 | + block = false, |
| 34 | + color = 'dark', |
| 35 | + variant = 'solid', |
| 36 | + className = '', |
| 37 | + ...rest |
| 38 | +}) { |
| 39 | + return ( |
| 40 | + <button |
| 41 | + className={`${ |
| 42 | + COLOR_VARIANT_MAP[variant][color] |
| 43 | + } ${COMMON_CLASS} space-x-5 ${block ? 'w-full' : ''} ${ |
| 44 | + loading ? 'bg-gray-500 cursor-not-allowed' : '' |
| 45 | + } ${className}`} |
| 46 | + {...rest} |
| 47 | + > |
| 48 | + <span>{children}</span> |
| 49 | + {loading && ( |
| 50 | + <span className='animate-spin'> |
| 51 | + <Loader /> |
| 52 | + </span> |
| 53 | + )} |
| 54 | + </button> |
| 55 | + ); |
| 56 | +} |
0 commit comments