2023-07-25 22:29:33 +03:00
|
|
|
interface ButtonProps
|
2023-07-27 22:04:25 +03:00
|
|
|
extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'className' | 'children' | 'title'> {
|
2023-07-15 17:46:19 +03:00
|
|
|
text?: string
|
|
|
|
icon?: React.ReactNode
|
|
|
|
tooltip?: string
|
|
|
|
dense?: boolean
|
|
|
|
loading?: boolean
|
2023-07-22 12:24:14 +03:00
|
|
|
widthClass?: string
|
2023-07-20 17:11:03 +03:00
|
|
|
borderClass?: string
|
2023-07-22 12:24:14 +03:00
|
|
|
colorClass?: string
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
function Button({
|
|
|
|
id, text, icon, tooltip,
|
2023-07-20 17:11:03 +03:00
|
|
|
dense, disabled,
|
2023-08-09 10:33:42 +03:00
|
|
|
borderClass = 'border rounded',
|
|
|
|
colorClass = 'clr-btn-default',
|
|
|
|
widthClass = 'w-fit h-fit',
|
2023-07-21 18:44:14 +03:00
|
|
|
loading, onClick,
|
|
|
|
...props
|
2023-07-20 17:11:03 +03:00
|
|
|
}: ButtonProps) {
|
2023-07-25 20:27:29 +03:00
|
|
|
const padding = dense ? 'px-1' : 'px-3 py-2';
|
|
|
|
const cursor = 'disabled:cursor-not-allowed ' + (loading ? 'cursor-progress ' : 'cursor-pointer ');
|
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'
|
2023-07-25 22:29:33 +03:00
|
|
|
disabled={disabled ?? loading}
|
2023-07-15 17:46:19 +03:00
|
|
|
onClick={onClick}
|
|
|
|
title={tooltip}
|
2023-08-16 10:46:22 +03:00
|
|
|
className={`inline-flex items-center gap-2 align-middle justify-center select-none ${padding} ${borderClass} ${colorClass} ${widthClass} ${cursor}`}
|
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>
|
2023-07-25 20:27:29 +03:00
|
|
|
);
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
export default Button;
|