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
|
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,
|
2023-07-21 18:44:14 +03:00
|
|
|
borderClass='border rounded',
|
|
|
|
loading, onClick,
|
|
|
|
...props
|
2023-07-20 17:11:03 +03:00
|
|
|
}: 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 ')
|
|
|
|
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 + ' ' +
|
2023-07-21 18:44:14 +03:00
|
|
|
'inline-flex items-center gap-2 align-middle justify-center w-fit h-fit clr-btn-default ' + cursor
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
2023-07-21 18:44:14 +03:00
|
|
|
{...props}
|
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;
|