2023-12-15 17:34:50 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2023-12-21 00:12:24 +03:00
|
|
|
import { globalIDs } from '@/utils/constants';
|
|
|
|
|
2023-12-18 19:42:27 +03:00
|
|
|
import { CProps } from '../props';
|
2023-11-05 16:31:49 +03:00
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
interface ButtonProps extends CProps.Control, CProps.Colors, CProps.Button {
|
|
|
|
text?: string;
|
|
|
|
icon?: React.ReactNode;
|
2024-03-08 18:39:08 +03:00
|
|
|
titleHtml?: string;
|
2023-11-05 16:31:49 +03:00
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
dense?: boolean;
|
2024-02-03 15:33:28 +03:00
|
|
|
hideTitle?: boolean;
|
2023-12-28 14:04:44 +03:00
|
|
|
loading?: boolean;
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
function Button({
|
2023-12-28 14:04:44 +03:00
|
|
|
text,
|
|
|
|
icon,
|
|
|
|
title,
|
2024-03-08 18:39:08 +03:00
|
|
|
titleHtml,
|
2023-12-28 14:04:44 +03:00
|
|
|
loading,
|
|
|
|
dense,
|
|
|
|
disabled,
|
2024-02-03 15:33:28 +03:00
|
|
|
hideTitle,
|
2023-12-28 14:04:44 +03:00
|
|
|
noBorder,
|
|
|
|
noOutline,
|
2023-11-05 16:31:49 +03:00
|
|
|
colors = 'clr-btn-default',
|
2023-12-18 12:25:39 +03:00
|
|
|
className,
|
2023-11-27 13:50:56 +03:00
|
|
|
...restProps
|
2023-07-20 17:11:03 +03:00
|
|
|
}: ButtonProps) {
|
2023-07-15 17:46:19 +03:00
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<button
|
|
|
|
type='button'
|
|
|
|
disabled={disabled ?? loading}
|
|
|
|
className={clsx(
|
|
|
|
'inline-flex gap-2 items-center justify-center',
|
|
|
|
'select-none disabled:cursor-not-allowed',
|
|
|
|
{
|
|
|
|
'border rounded': !noBorder,
|
|
|
|
'px-1': dense,
|
2023-12-30 19:43:24 +03:00
|
|
|
'px-3 py-1': !dense,
|
2023-12-28 14:04:44 +03:00
|
|
|
'cursor-progress': loading,
|
|
|
|
'cursor-pointer': !loading,
|
|
|
|
'outline-none': noOutline,
|
|
|
|
'clr-outline': !noOutline
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
colors
|
|
|
|
)}
|
2024-03-08 18:39:08 +03:00
|
|
|
data-tooltip-id={!!title || !!titleHtml ? globalIDs.tooltip : undefined}
|
|
|
|
data-tooltip-html={titleHtml}
|
2023-12-28 14:04:44 +03:00
|
|
|
data-tooltip-content={title}
|
2024-02-03 15:33:28 +03:00
|
|
|
data-tooltip-hidden={hideTitle}
|
2023-12-28 14:04:44 +03:00
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{icon ? icon : null}
|
2023-12-30 19:43:24 +03:00
|
|
|
{text ? <span className='font-medium'>{text}</span> : null}
|
2023-12-28 14:04:44 +03:00
|
|
|
</button>
|
|
|
|
);
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default Button;
|