2024-06-07 20:17:03 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
import { motion } from 'framer-motion';
|
|
|
|
|
|
|
|
import { animateDropdown } from '@/styling/animations';
|
|
|
|
|
|
|
|
import { CProps } from '../props';
|
|
|
|
|
|
|
|
interface DropdownProps extends CProps.Styling {
|
2024-09-12 16:41:48 +03:00
|
|
|
/** Indicates whether the dropdown should stretch to the left. */
|
2024-06-07 20:17:03 +03:00
|
|
|
stretchLeft?: boolean;
|
2024-09-12 16:41:48 +03:00
|
|
|
|
|
|
|
/** Indicates whether the dropdown should stretch to the top. */
|
2024-06-26 18:59:49 +03:00
|
|
|
stretchTop?: boolean;
|
2024-09-12 16:41:48 +03:00
|
|
|
|
|
|
|
/** Indicates whether the dropdown is open. */
|
2024-06-07 20:17:03 +03:00
|
|
|
isOpen: boolean;
|
|
|
|
}
|
|
|
|
|
2024-09-12 16:41:48 +03:00
|
|
|
/**
|
|
|
|
* Dropdown animated component that displays a list of children with optional positioning and visibility control.
|
|
|
|
*/
|
2024-09-19 17:48:48 +03:00
|
|
|
function Dropdown({
|
|
|
|
isOpen,
|
|
|
|
stretchLeft,
|
|
|
|
stretchTop,
|
|
|
|
className,
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
}: React.PropsWithChildren<DropdownProps>) {
|
2024-06-07 20:17:03 +03:00
|
|
|
return (
|
|
|
|
<div className='relative'>
|
|
|
|
<motion.div
|
|
|
|
tabIndex={-1}
|
|
|
|
className={clsx(
|
2024-08-25 13:45:32 +03:00
|
|
|
'z-topmost',
|
2024-06-07 20:17:03 +03:00
|
|
|
'absolute mt-3',
|
|
|
|
'flex flex-col',
|
|
|
|
'border rounded-md shadow-lg',
|
|
|
|
'text-sm',
|
|
|
|
'clr-input',
|
|
|
|
{
|
|
|
|
'right-0': stretchLeft,
|
2024-06-26 18:59:49 +03:00
|
|
|
'left-0': !stretchLeft,
|
|
|
|
'bottom-[2rem]': stretchTop
|
2024-06-07 20:17:03 +03:00
|
|
|
},
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
initial={false}
|
|
|
|
animate={isOpen ? 'open' : 'closed'}
|
|
|
|
variants={animateDropdown}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</motion.div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Dropdown;
|