2023-12-15 17:34:50 +03:00
|
|
|
import clsx from 'clsx';
|
2023-12-25 16:53:27 +03:00
|
|
|
import { motion } from 'framer-motion';
|
2023-12-15 17:34:50 +03:00
|
|
|
|
2024-01-06 03:15:02 +03:00
|
|
|
import { animateDropdownItem } from '@/styling/animations';
|
2024-03-27 15:32:59 +03:00
|
|
|
import { globals } from '@/utils/constants';
|
2023-12-21 00:12:24 +03:00
|
|
|
|
2023-12-18 19:42:27 +03:00
|
|
|
import { CProps } from '../props';
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
interface DropdownButtonProps extends CProps.AnimatedButton {
|
|
|
|
text?: string;
|
|
|
|
icon?: React.ReactNode;
|
2023-12-16 19:20:26 +03:00
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
children?: React.ReactNode;
|
2023-07-21 00:09:05 +03:00
|
|
|
}
|
|
|
|
|
2024-03-08 18:39:08 +03:00
|
|
|
function DropdownButton({
|
|
|
|
text,
|
|
|
|
icon,
|
|
|
|
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 (
|
2023-12-28 14:04:44 +03:00
|
|
|
<motion.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',
|
|
|
|
{
|
|
|
|
'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
|
|
|
|
)}
|
|
|
|
variants={animateDropdownItem}
|
2024-03-27 15:32:59 +03:00
|
|
|
data-tooltip-id={!!title || !!titleHtml ? globals.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}
|
|
|
|
>
|
|
|
|
{children ? children : null}
|
|
|
|
{!children && icon ? icon : null}
|
|
|
|
{!children && text ? <span>{text}</span> : null}
|
|
|
|
</motion.button>
|
|
|
|
);
|
2023-07-21 00:09:05 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default DropdownButton;
|