Portal/rsconcept/frontend/src/components/dropdown/dropdown-button.tsx

57 lines
1.6 KiB
TypeScript
Raw Normal View History

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-04-12 21:47:46 +03:00
import { cn } from '../utils';
2025-02-20 20:22:05 +03:00
interface DropdownButtonProps extends Button {
/** Icon to display first (not used if children are provided). */
2024-06-07 20:17:03 +03:00
icon?: React.ReactNode;
/** 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-12-12 13:17:24 +03:00
* `button` with optional text, icon, and click functionality styled for use in a {@link Dropdown}.
* 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,
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
type='button'
onClick={onClick}
2025-04-12 21:47:46 +03:00
className={cn(
2024-06-07 20:17:03 +03:00
'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',
2025-06-19 17:49:51 +03:00
'disabled:text-muted-foreground disabled:opacity-75',
2025-04-13 22:28:28 +03:00
'focus-outline cc-animate-background',
2025-06-17 22:28:37 +03:00
!!onClick ? 'cc-hover-bg cursor-pointer disabled:cursor-auto' : 'bg-secondary text-secondary-foreground',
2024-06-07 20:17:03 +03:00
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}
2025-03-20 11:33:19 +03:00
aria-label={title}
2024-06-07 20:17:03 +03:00
{...restProps}
>
2025-03-09 21:57:21 +03:00
{icon ? icon : null}
{text ? <span>{text}</span> : null}
2024-06-07 20:17:03 +03:00
{children ? children : null}
2024-12-12 13:17:24 +03:00
</button>
2024-06-07 20:17:03 +03:00
);
}