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