2023-12-13 14:32:57 +03:00
|
|
|
import { IColorsProps, IControlProps } from './commonInterfaces';
|
2023-11-05 16:31:49 +03:00
|
|
|
|
2023-07-25 22:29:33 +03:00
|
|
|
interface ButtonProps
|
2023-11-05 16:31:49 +03:00
|
|
|
extends IControlProps, IColorsProps, Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'className' | 'children' | 'title'| 'type'> {
|
2023-07-15 17:46:19 +03:00
|
|
|
text?: string
|
|
|
|
icon?: React.ReactNode
|
2023-11-05 16:31:49 +03:00
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
dense?: boolean
|
|
|
|
loading?: boolean
|
|
|
|
}
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
function Button({
|
2023-10-06 14:39:32 +03:00
|
|
|
text, icon, tooltip,
|
2023-11-05 16:31:49 +03:00
|
|
|
dense, disabled, noBorder, noOutline,
|
|
|
|
colors = 'clr-btn-default',
|
2023-09-15 23:29:52 +03:00
|
|
|
dimensions = 'w-fit h-fit',
|
2023-10-06 14:39:32 +03:00
|
|
|
loading,
|
2023-11-27 13:50:56 +03:00
|
|
|
...restProps
|
2023-07-20 17:11:03 +03:00
|
|
|
}: ButtonProps) {
|
2023-11-05 16:31:49 +03:00
|
|
|
const borderClass = noBorder ? '' : 'border rounded';
|
2023-07-25 20:27:29 +03:00
|
|
|
const padding = dense ? 'px-1' : 'px-3 py-2';
|
2023-11-05 16:31:49 +03:00
|
|
|
const outlineClass = noOutline ? 'outline-none': 'clr-outline';
|
2023-07-25 20:27:29 +03:00
|
|
|
const cursor = 'disabled:cursor-not-allowed ' + (loading ? 'cursor-progress ' : 'cursor-pointer ');
|
2023-07-15 17:46:19 +03:00
|
|
|
return (
|
2023-10-06 14:39:32 +03:00
|
|
|
<button type='button'
|
2023-07-25 22:29:33 +03:00
|
|
|
disabled={disabled ?? loading}
|
2023-07-15 17:46:19 +03:00
|
|
|
title={tooltip}
|
2023-11-05 16:31:49 +03:00
|
|
|
className={`inline-flex items-center gap-2 align-middle justify-center select-none ${padding} ${colors} ${outlineClass} ${borderClass} ${dimensions} ${cursor}`}
|
2023-11-27 13:50:56 +03:00
|
|
|
{...restProps}
|
2023-07-15 17:46:19 +03:00
|
|
|
>
|
2023-11-27 11:33:34 +03:00
|
|
|
{icon ? icon : null}
|
|
|
|
{text ? <span className='font-semibold'>{text}</span> : null}
|
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;
|