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

64 lines
1.5 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'
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',
2025-03-13 01:14:47 +03:00
dense ? 'px-1' : 'px-3 py-1',
loading ? 'cursor-progress' : 'cursor-pointer',
noOutline ? 'outline-hidden' : 'clr-outline',
!noBorder && 'border rounded-sm',
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}
2025-03-20 11:33:19 +03:00
disabled={disabled ?? loading}
aria-label={!text ? title : undefined}
2024-06-07 20:17:03 +03:00
{...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>
);
}