ConceptPortal-public/rsconcept/frontend/src/components/ui/SelectorButton.tsx

64 lines
1.4 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 SelectorButtonProps extends CProps.Button {
/** Text to display in the button. */
2023-12-28 14:04:44 +03:00
text?: string;
/** Icon to display in the button. */
2023-12-28 14:04:44 +03:00
icon?: React.ReactNode;
/** Classnames for the colors of the button. */
2023-12-28 14:04:44 +03:00
colors?: string;
/** 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
}
/**
* 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,
titleHtml,
2023-11-05 16:31:49 +03:00
colors = 'clr-btn-default',
className,
2023-10-06 14:39:32 +03:00
transparent,
hideTitle,
...restProps
2023-10-06 14:39:32 +03:00
}: SelectorButtonProps) {
return (
2023-12-28 14:04:44 +03:00
<button
type='button'
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
)}
data-tooltip-id={!!title || !!titleHtml ? globals.tooltip : undefined}
data-tooltip-html={titleHtml}
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;