2024-06-07 20:17:03 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type Button } from '@/components/props';
|
2025-02-20 18:10:34 +03:00
|
|
|
import { globalIDs } from '@/utils/constants';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface DropdownButtonProps extends Button {
|
2024-09-12 16:41:48 +03:00
|
|
|
/** Icon to display first (not used if children are provided). */
|
2024-06-07 20:17:03 +03:00
|
|
|
icon?: React.ReactNode;
|
|
|
|
|
2024-09-12 16:41:48 +03:00
|
|
|
/** Text to display second (not used if children are provided). */
|
|
|
|
text?: string;
|
|
|
|
|
|
|
|
/** Custom children to display. */
|
2024-06-07 20:17:03 +03:00
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2024-09-12 16:41:48 +03:00
|
|
|
/**
|
2024-12-12 13:17:24 +03:00
|
|
|
* `button` with optional text, icon, and click functionality styled for use in a {@link Dropdown}.
|
2024-09-12 16:41:48 +03:00
|
|
|
* It supports optional children for custom content or the default text/icon display.
|
|
|
|
*/
|
2025-02-07 10:53:49 +03:00
|
|
|
export function DropdownButton({
|
2024-06-07 20:17:03 +03:00
|
|
|
icon,
|
2024-09-12 16:41:48 +03:00
|
|
|
text,
|
2024-06-07 20:17:03 +03:00
|
|
|
className,
|
|
|
|
title,
|
|
|
|
titleHtml,
|
|
|
|
hideTitle,
|
|
|
|
onClick,
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
}: DropdownButtonProps) {
|
|
|
|
return (
|
2024-12-12 13:17:24 +03:00
|
|
|
<button
|
2024-06-07 20:17:03 +03:00
|
|
|
tabIndex={-1}
|
|
|
|
type='button'
|
|
|
|
onClick={onClick}
|
|
|
|
className={clsx(
|
|
|
|
'px-3 py-1 inline-flex items-center gap-2',
|
2025-02-20 20:22:05 +03:00
|
|
|
'text-left text-sm text-ellipsis whitespace-nowrap',
|
2024-06-07 20:17:03 +03:00
|
|
|
'disabled:clr-text-controls',
|
2024-12-17 11:37:42 +03:00
|
|
|
'cc-animate-color',
|
2024-06-07 20:17:03 +03:00
|
|
|
{
|
|
|
|
'clr-hover': onClick,
|
2024-06-18 15:19:04 +03:00
|
|
|
'cursor-pointer disabled:cursor-auto': onClick,
|
2024-06-07 20:17:03 +03:00
|
|
|
'cursor-default': !onClick
|
|
|
|
},
|
|
|
|
className
|
|
|
|
)}
|
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}
|
|
|
|
>
|
|
|
|
{children ? children : null}
|
|
|
|
{!children && icon ? icon : null}
|
|
|
|
{!children && text ? <span>{text}</span> : null}
|
2024-12-12 13:17:24 +03:00
|
|
|
</button>
|
2024-06-07 20:17:03 +03:00
|
|
|
);
|
|
|
|
}
|