2023-12-15 17:34:50 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2024-03-27 15:32:59 +03:00
|
|
|
import { globals } from '@/utils/constants';
|
2023-12-21 00:12:24 +03:00
|
|
|
|
2023-12-18 19:42:27 +03:00
|
|
|
import { CProps } from '../props';
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
interface SelectorButtonProps extends CProps.Button {
|
2024-11-21 15:09:51 +03:00
|
|
|
/** Text to display in the button. */
|
2023-12-28 14:04:44 +03:00
|
|
|
text?: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Icon to display in the button. */
|
2023-12-28 14:04:44 +03:00
|
|
|
icon?: React.ReactNode;
|
2023-12-18 19:42:27 +03:00
|
|
|
|
2024-11-21 15:09:51 +03:00
|
|
|
/** Classnames for the colors of the button. */
|
2023-12-28 14:04:44 +03:00
|
|
|
colors?: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Indicates if button background should be transparent. */
|
2023-12-28 14:04:44 +03:00
|
|
|
transparent?: boolean;
|
2023-10-06 14:39:32 +03:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:09:51 +03:00
|
|
|
/**
|
|
|
|
* Displays a button with an icon and text that opens a dropdown menu.
|
|
|
|
*/
|
2023-10-06 14:39:32 +03:00
|
|
|
function SelectorButton({
|
2023-12-28 14:04:44 +03:00
|
|
|
text,
|
|
|
|
icon,
|
|
|
|
title,
|
2024-03-08 18:39:08 +03:00
|
|
|
titleHtml,
|
2023-11-05 16:31:49 +03:00
|
|
|
colors = 'clr-btn-default',
|
2023-12-18 19:42:27 +03:00
|
|
|
className,
|
2023-10-06 14:39:32 +03:00
|
|
|
transparent,
|
2024-02-03 15:33:28 +03:00
|
|
|
hideTitle,
|
2023-11-27 13:50:56 +03:00
|
|
|
...restProps
|
2023-10-06 14:39:32 +03:00
|
|
|
}: SelectorButtonProps) {
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<button
|
|
|
|
type='button'
|
2024-06-03 17:38:30 +03:00
|
|
|
tabIndex={-1}
|
2023-12-28 14:04:44 +03:00
|
|
|
className={clsx(
|
|
|
|
'px-1 flex flex-start items-center gap-1',
|
2023-12-30 19:43:24 +03:00
|
|
|
'text-sm font-controls select-none',
|
2023-12-28 14:04:44 +03:00
|
|
|
'text-btn clr-text-controls',
|
2024-06-18 15:19:19 +03:00
|
|
|
'disabled:cursor-auto cursor-pointer',
|
2023-12-28 14:04:44 +03:00
|
|
|
{
|
|
|
|
'clr-hover': transparent,
|
|
|
|
'border': !transparent
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
!transparent && colors
|
|
|
|
)}
|
2024-03-27 15:32:59 +03:00
|
|
|
data-tooltip-id={!!title || !!titleHtml ? globals.tooltip : undefined}
|
2024-03-08 18:39:08 +03:00
|
|
|
data-tooltip-html={titleHtml}
|
2024-02-03 15:33:28 +03:00
|
|
|
data-tooltip-content={title}
|
|
|
|
data-tooltip-hidden={hideTitle}
|
2023-12-28 14:04:44 +03:00
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{icon ? icon : null}
|
2024-08-23 22:53:53 +03:00
|
|
|
{text ? <div className='whitespace-nowrap'>{text}</div> : null}
|
2023-12-28 14:04:44 +03:00
|
|
|
</button>
|
|
|
|
);
|
2023-10-06 14:39:32 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default SelectorButton;
|