2022-09-01 22:23:12 +00:00
|
|
|
import { MouseEventHandler, ReactNode } from 'react'
|
2022-07-13 21:57:34 +00:00
|
|
|
import clsx from 'clsx'
|
2022-10-03 20:33:00 +00:00
|
|
|
import { LoadingIndicator } from 'web/components/loading-indicator'
|
2022-07-13 21:57:34 +00:00
|
|
|
|
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'
|
2022-10-04 22:36:03 +00:00
|
|
|
| 'gray-outline'
|
2022-08-19 17:07:48 +00:00
|
|
|
| 'gradient'
|
|
|
|
| 'gray-white'
|
2022-09-16 00:41:25 +00:00
|
|
|
| 'highlight-blue'
|
2022-08-19 17:07:48 +00:00
|
|
|
|
2022-10-05 22:51:10 +00:00
|
|
|
const sizeClasses = {
|
|
|
|
'2xs': 'px-2 py-1 text-xs',
|
|
|
|
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',
|
|
|
|
xl: 'px-6 py-2.5 text-base font-semibold',
|
|
|
|
'2xl': 'px-6 py-3 text-xl font-semibold',
|
|
|
|
}
|
|
|
|
|
|
|
|
export function buttonClass(size: SizeType, color: ColorType | 'override') {
|
|
|
|
return clsx(
|
|
|
|
'font-md inline-flex items-center justify-center rounded-md border border-transparent shadow-sm transition-colors disabled:cursor-not-allowed',
|
|
|
|
sizeClasses[size],
|
|
|
|
color === 'green' &&
|
|
|
|
'disabled:bg-greyscale-2 bg-teal-500 text-white hover:bg-teal-600',
|
|
|
|
color === 'red' &&
|
|
|
|
'disabled:bg-greyscale-2 bg-red-400 text-white hover:bg-red-500',
|
|
|
|
color === 'yellow' &&
|
|
|
|
'disabled:bg-greyscale-2 bg-yellow-400 text-white hover:bg-yellow-500',
|
|
|
|
color === 'blue' &&
|
|
|
|
'disabled:bg-greyscale-2 bg-blue-400 text-white hover:bg-blue-500',
|
|
|
|
color === 'indigo' &&
|
|
|
|
'disabled:bg-greyscale-2 bg-indigo-500 text-white hover:bg-indigo-600',
|
|
|
|
color === 'gray' &&
|
|
|
|
'bg-greyscale-1 text-greyscale-6 hover:bg-greyscale-2 disabled:opacity-50',
|
|
|
|
color === 'gray-outline' &&
|
|
|
|
'border-greyscale-4 text-greyscale-4 hover:bg-greyscale-4 border-2 hover:text-white disabled:opacity-50',
|
|
|
|
color === 'gradient' &&
|
|
|
|
'disabled:bg-greyscale-2 border-none bg-gradient-to-r from-indigo-500 to-blue-500 text-white hover:from-indigo-700 hover:to-blue-700',
|
|
|
|
color === 'gray-white' &&
|
|
|
|
'text-greyscale-6 hover:bg-greyscale-2 border-none shadow-none disabled:opacity-50',
|
|
|
|
color === 'highlight-blue' &&
|
|
|
|
'text-highlight-blue disabled:bg-greyscale-2 border-none shadow-none'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-15 17:24:07 +00:00
|
|
|
export function Button(props: {
|
2022-07-13 21:57:34 +00:00
|
|
|
className?: string
|
2022-09-01 22:23:12 +00:00
|
|
|
onClick?: MouseEventHandler<any> | undefined
|
2022-07-16 01:42:37 +00:00
|
|
|
children?: ReactNode
|
2022-08-19 17:07:48 +00:00
|
|
|
size?: SizeType
|
2022-10-05 22:51:10 +00:00
|
|
|
color?: ColorType | 'override'
|
2022-07-13 21:57:34 +00:00
|
|
|
type?: 'button' | 'reset' | 'submit'
|
2022-07-16 01:42:37 +00:00
|
|
|
disabled?: boolean
|
2022-10-03 20:33:00 +00:00
|
|
|
loading?: 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-10-03 20:33:00 +00:00
|
|
|
loading,
|
2022-07-13 21:57:34 +00:00
|
|
|
} = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type={type}
|
2022-10-05 22:51:10 +00:00
|
|
|
className={clsx(buttonClass(size, color), className)}
|
2022-10-03 20:33:00 +00:00
|
|
|
disabled={disabled || loading}
|
2022-07-13 21:57:34 +00:00
|
|
|
onClick={onClick}
|
|
|
|
>
|
2022-10-03 20:33:00 +00:00
|
|
|
{loading && <LoadingIndicator className={'mr-2 border-gray-500'} />}
|
2022-07-13 21:57:34 +00:00
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|