2022-07-13 21:57:34 +00:00
|
|
|
import { ReactNode } from 'react'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
2022-08-19 17:07:48 +00:00
|
|
|
export type SizeType = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
|
|
|
export type ColorType =
|
|
|
|
| 'green'
|
|
|
|
| 'red'
|
|
|
|
| 'blue'
|
|
|
|
| 'indigo'
|
|
|
|
| 'yellow'
|
|
|
|
| 'gray'
|
|
|
|
| 'gradient'
|
|
|
|
| 'gray-white'
|
|
|
|
|
2022-07-15 17:24:07 +00:00
|
|
|
export function Button(props: {
|
2022-07-13 21:57:34 +00:00
|
|
|
className?: string
|
|
|
|
onClick?: () => void
|
2022-07-16 01:42:37 +00:00
|
|
|
children?: ReactNode
|
2022-08-19 17:07:48 +00:00
|
|
|
size?: SizeType
|
|
|
|
color?: ColorType
|
2022-07-13 21:57:34 +00:00
|
|
|
type?: 'button' | 'reset' | 'submit'
|
2022-07-16 01:42:37 +00:00
|
|
|
disabled?: boolean
|
2022-07-13 21:57:34 +00:00
|
|
|
}) {
|
|
|
|
const {
|
2022-07-15 17:24:07 +00:00
|
|
|
children,
|
2022-07-13 21:57:34 +00:00
|
|
|
className,
|
|
|
|
onClick,
|
2022-07-15 17:24:07 +00:00
|
|
|
size = 'md',
|
2022-07-13 21:57:34 +00:00
|
|
|
color = 'indigo',
|
|
|
|
type = 'button',
|
2022-07-16 01:42:37 +00:00
|
|
|
disabled = false,
|
2022-07-13 21:57:34 +00:00
|
|
|
} = props
|
|
|
|
|
2022-07-15 17:24:07 +00:00
|
|
|
const sizeClasses = {
|
2022-08-05 06:42:35 +00:00
|
|
|
'2xs': 'px-2 py-1 text-xs',
|
2022-07-15 17:24:07 +00:00
|
|
|
xs: 'px-2.5 py-1.5 text-sm',
|
|
|
|
sm: 'px-3 py-2 text-sm',
|
|
|
|
md: 'px-4 py-2 text-sm',
|
|
|
|
lg: 'px-4 py-2 text-base',
|
2022-08-28 21:09:42 +00:00
|
|
|
xl: 'px-6 py-2.5 text-base font-semibold',
|
|
|
|
'2xl': 'px-6 py-3 text-xl font-semibold',
|
2022-07-15 17:24:07 +00:00
|
|
|
}[size]
|
|
|
|
|
2022-07-13 21:57:34 +00:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type={type}
|
|
|
|
className={clsx(
|
2022-07-16 01:42:37 +00:00
|
|
|
'font-md items-center justify-center rounded-md border border-transparent shadow-sm hover:transition-colors disabled:cursor-not-allowed disabled:opacity-50',
|
2022-07-15 17:24:07 +00:00
|
|
|
sizeClasses,
|
2022-07-13 21:57:34 +00:00
|
|
|
color === 'green' && 'btn-primary text-white',
|
|
|
|
color === 'red' && 'bg-red-400 text-white hover:bg-red-500',
|
|
|
|
color === 'yellow' && 'bg-yellow-400 text-white hover:bg-yellow-500',
|
|
|
|
color === 'blue' && 'bg-blue-400 text-white hover:bg-blue-500',
|
|
|
|
color === 'indigo' && 'bg-indigo-500 text-white hover:bg-indigo-600',
|
2022-08-28 20:56:35 +00:00
|
|
|
color === 'gray' && 'bg-gray-50 text-gray-600 hover:bg-gray-200',
|
2022-08-04 21:27:02 +00:00
|
|
|
color === 'gradient' &&
|
2022-08-28 21:09:42 +00:00
|
|
|
'border-none bg-gradient-to-r from-indigo-500 to-blue-500 text-white hover:from-indigo-700 hover:to-blue-700',
|
2022-07-30 07:50:03 +00:00
|
|
|
color === 'gray-white' &&
|
2022-08-05 05:22:45 +00:00
|
|
|
'border-none bg-white text-gray-500 shadow-none hover:bg-gray-200',
|
2022-07-13 21:57:34 +00:00
|
|
|
className
|
|
|
|
)}
|
2022-07-16 01:42:37 +00:00
|
|
|
disabled={disabled}
|
2022-07-13 21:57:34 +00:00
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|