2023-07-20 17:11:03 +03:00
|
|
|
import { MouseEventHandler } from 'react'
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
interface ButtonProps {
|
2023-07-20 17:11:03 +03:00
|
|
|
id?: string
|
2023-07-15 17:46:19 +03:00
|
|
|
text?: string
|
|
|
|
icon?: React.ReactNode
|
|
|
|
tooltip?: string
|
|
|
|
disabled?: boolean
|
|
|
|
dense?: boolean
|
|
|
|
loading?: boolean
|
|
|
|
colorClass?: string
|
2023-07-20 17:11:03 +03:00
|
|
|
borderClass?: string
|
|
|
|
onClick?: MouseEventHandler<HTMLButtonElement> | undefined
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
2023-07-20 17:11:03 +03:00
|
|
|
function Button({id, text, icon, tooltip,
|
|
|
|
dense, disabled,
|
|
|
|
colorClass, borderClass='border rounded',
|
|
|
|
loading, onClick
|
|
|
|
}: ButtonProps) {
|
|
|
|
const padding = dense ? 'px-1' : 'px-3 py-2'
|
2023-07-15 17:46:19 +03:00
|
|
|
const cursor = 'disabled:cursor-not-allowed ' + (loading ? 'cursor-progress ': 'cursor-pointer ')
|
2023-07-20 17:11:03 +03:00
|
|
|
const baseColor = 'dark:disabled:text-zinc-400 disabled:text-gray-400 bg-gray-100 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-400'
|
|
|
|
const color = baseColor + ' ' + (colorClass || 'text-gray-500 dark:text-zinc-200')
|
2023-07-15 17:46:19 +03:00
|
|
|
return (
|
2023-07-20 17:11:03 +03:00
|
|
|
<button id={id}
|
2023-07-15 17:46:19 +03:00
|
|
|
type='button'
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={onClick}
|
|
|
|
title={tooltip}
|
2023-07-20 17:11:03 +03:00
|
|
|
className={padding + ' ' + borderClass + ' ' +
|
|
|
|
'inline-flex items-center gap-2 align-middle justify-center w-fit h-fit ' + cursor + color
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
>
|
2023-07-20 17:11:03 +03:00
|
|
|
{icon && <span>{icon}</span>}
|
|
|
|
{text && <span className={'font-semibold'}>{text}</span>}
|
2023-07-15 17:46:19 +03:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Button;
|