Portal/rsconcept/frontend/src/components/ui/Button.tsx

71 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
2025-01-28 23:23:03 +03:00
import { CProps } from '@/components/props';
2024-06-07 20:17:03 +03:00
import { globals } from '@/utils/constants';
interface ButtonProps extends CProps.Control, CProps.Colors, CProps.Button {
/** Icon to display first. */
2024-06-07 20:17:03 +03:00
icon?: React.ReactNode;
/** Text to display second. */
text?: string;
/** Indicates whether to render the button in a dense style. */
2024-06-07 20:17:03 +03:00
dense?: boolean;
/** Indicates loading state to prevent interactions and change visual style. */
2024-06-07 20:17:03 +03:00
loading?: boolean;
}
/**
2024-10-30 21:35:43 +03:00
* Customizable `button` with text, icon, tooltips and various styles.
*/
2024-06-07 20:17:03 +03:00
function Button({
icon,
text,
2024-06-07 20:17:03 +03:00
title,
titleHtml,
hideTitle,
loading,
dense,
disabled,
noBorder,
noOutline,
colors = 'clr-btn-default',
className,
...restProps
}: ButtonProps) {
return (
<button
type='button'
disabled={disabled ?? loading}
className={clsx(
'inline-flex gap-2 items-center justify-center',
2024-06-18 15:19:04 +03:00
'select-none disabled:cursor-auto',
2024-12-17 11:37:42 +03:00
'cc-animate-color',
2024-06-07 20:17:03 +03:00
{
'border rounded': !noBorder,
'px-1': dense,
'px-3 py-1': !dense,
'cursor-progress': loading,
'cursor-pointer': !loading,
'outline-none': noOutline,
'clr-outline': !noOutline
},
className,
colors
)}
data-tooltip-id={!!title || !!titleHtml ? globals.tooltip : undefined}
data-tooltip-html={titleHtml}
data-tooltip-content={title}
data-tooltip-hidden={hideTitle}
{...restProps}
>
{icon ? icon : null}
{text ? <span className='font-medium'>{text}</span> : null}
</button>
);
}
export default Button;