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
|
|
|
|
2023-12-25 16:53:27 +03:00
|
|
|
import { animateDropdownItem } from '@/utils/animations';
|
2023-12-21 00:12:24 +03:00
|
|
|
import { globalIDs } from '@/utils/constants';
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
function DropdownButton({ text, icon, className, title, onClick, children, ...restProps }: DropdownButtonProps) {
|
2023-07-21 00:09:05 +03:00
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<motion.button
|
|
|
|
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,
|
|
|
|
'cursor-pointer disabled:cursor-not-allowed': onClick,
|
|
|
|
'cursor-default': !onClick
|
|
|
|
},
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
variants={animateDropdownItem}
|
|
|
|
data-tooltip-id={title ? globalIDs.tooltip : undefined}
|
|
|
|
data-tooltip-content={title}
|
|
|
|
{...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;
|