ConceptPortal-public/rsconcept/frontend/src/components/Control/Button.tsx

70 lines
1.6 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
import { globals } from '@/utils/constants';
2023-12-21 00:12:24 +03:00
import { CProps } from '../props';
2023-12-28 14:04:44 +03:00
interface ButtonProps extends CProps.Control, CProps.Colors, CProps.Button {
/** Icon to display first. */
2023-12-28 14:04:44 +03:00
icon?: React.ReactNode;
2023-11-05 16:31:49 +03:00
/** Text to display second. */
text?: string;
/** Indicates whether to render the button in a dense style. */
2023-12-28 14:04:44 +03:00
dense?: boolean;
/** Indicates loading state to prevent interactions and change visual style. */
2023-12-28 14:04:44 +03:00
loading?: boolean;
2023-07-15 17:46:19 +03:00
}
/**
2024-10-30 21:35:55 +03:00
* Customizable `button` with text, icon, tooltips and various styles.
*/
2025-02-07 10:54:47 +03:00
export function Button({
2023-12-28 14:04:44 +03:00
icon,
text,
2023-12-28 14:04:44 +03:00
title,
titleHtml,
2024-03-09 16:40:10 +03:00
hideTitle,
2023-12-28 14:04:44 +03:00
loading,
dense,
disabled,
noBorder,
noOutline,
2023-11-05 16:31:49 +03:00
colors = 'clr-btn-default',
className,
...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',
2024-06-18 15:19:19 +03:00
'select-none disabled:cursor-auto',
2024-12-17 11:38:00 +03:00
'cc-animate-color',
2023-12-28 14:04:44 +03:00
{
'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
)}
data-tooltip-id={!!title || !!titleHtml ? globals.tooltip : undefined}
data-tooltip-html={titleHtml}
2023-12-28 14:04:44 +03:00
data-tooltip-content={title}
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
}