Portal/rsconcept/frontend/src/components/control/button.tsx

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
2025-02-20 18:10:34 +03:00
import { globalIDs } from '@/utils/constants';
2024-06-07 20:17:03 +03:00
2025-02-22 14:03:13 +03:00
import { type Button as ButtonStyle, type Control } from '../props';
2025-02-22 14:03:13 +03:00
interface ButtonProps extends Control, ButtonStyle {
/** 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.
*/
2025-02-07 10:53:49 +03:00
export function Button({
2024-06-07 20:17:03 +03:00
icon,
text,
2024-06-07 20:17:03 +03:00
title,
titleHtml,
hideTitle,
loading,
dense,
disabled,
noBorder,
noOutline,
className,
...restProps
}: ButtonProps) {
return (
<button
type='button'
disabled={disabled ?? loading}
className={clsx(
'inline-flex gap-2 items-center justify-center',
2025-03-09 21:57:21 +03:00
'font-medium select-none disabled:cursor-auto',
2025-02-22 14:03:13 +03:00
'clr-btn-default cc-animate-color',
2024-06-07 20:17:03 +03:00
{
2025-02-20 20:22:05 +03:00
'border rounded-sm': !noBorder,
2024-06-07 20:17:03 +03:00
'px-1': dense,
'px-3 py-1': !dense,
'cursor-progress': loading,
'cursor-pointer': !loading,
2025-02-20 20:22:05 +03:00
'outline-hidden': noOutline,
2024-06-07 20:17:03 +03:00
'clr-outline': !noOutline
},
2025-02-22 14:03:13 +03:00
className
2024-06-07 20:17:03 +03:00
)}
2025-02-20 18:10:34 +03:00
data-tooltip-id={!!title || !!titleHtml ? globalIDs.tooltip : undefined}
2024-06-07 20:17:03 +03:00
data-tooltip-html={titleHtml}
data-tooltip-content={title}
data-tooltip-hidden={hideTitle}
{...restProps}
>
{icon ? icon : null}
2025-03-09 21:57:21 +03:00
{text ? <span>{text}</span> : null}
2024-06-07 20:17:03 +03:00
</button>
);
}