ConceptPortal-public/rsconcept/frontend/src/components/Dropdown/DropdownButton.tsx

61 lines
1.6 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
2025-01-28 23:23:42 +03:00
import { CProps } from '@/components/props';
import { globals } from '@/utils/constants';
2023-12-21 00:12:24 +03:00
interface DropdownButtonProps extends CProps.Button {
/** 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
/** 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
}
/**
* `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:54:47 +03:00
export function DropdownButton({
icon,
text,
className,
title,
titleHtml,
2024-03-09 16:40:10 +03:00
hideTitle,
onClick,
children,
...restProps
}: DropdownButtonProps) {
2023-07-21 00:09:05 +03:00
return (
<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',
'text-left text-sm overflow-ellipsis whitespace-nowrap',
'disabled:clr-text-controls',
2024-12-17 11:38:00 +03:00
'cc-animate-color',
2023-12-28 14:04:44 +03:00
{
'clr-hover': onClick,
2024-06-18 15:19:19 +03:00
'cursor-pointer disabled:cursor-auto': onClick,
2023-12-28 14:04:44 +03:00
'cursor-default': !onClick
},
className
)}
data-tooltip-id={!!title || !!titleHtml ? globals.tooltip : undefined}
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}
>
{children ? children : null}
{!children && icon ? icon : null}
{!children && text ? <span>{text}</span> : null}
</button>
2023-12-28 14:04:44 +03:00
);
2023-07-21 00:09:05 +03:00
}