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';
|
|
|
|
|
2024-01-06 03:15:02 +03:00
|
|
|
import { animateDropdown } from '@/styling/animations';
|
2023-12-15 17:34:50 +03:00
|
|
|
|
2023-12-18 19:42:27 +03:00
|
|
|
import { CProps } from '../props';
|
2023-12-15 17:34:50 +03:00
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
interface DropdownProps extends CProps.Styling {
|
2024-09-12 16:42:02 +03:00
|
|
|
/** Indicates whether the dropdown should stretch to the left. */
|
2023-12-28 14:04:44 +03:00
|
|
|
stretchLeft?: boolean;
|
2024-09-12 16:42:02 +03:00
|
|
|
|
|
|
|
/** Indicates whether the dropdown should stretch to the top. */
|
2024-06-26 19:00:29 +03:00
|
|
|
stretchTop?: boolean;
|
2024-09-12 16:42:02 +03:00
|
|
|
|
|
|
|
/** Indicates whether the dropdown is open. */
|
2023-12-28 14:04:44 +03:00
|
|
|
isOpen: boolean;
|
2023-07-20 17:11:03 +03:00
|
|
|
}
|
|
|
|
|
2024-09-12 16:42:02 +03:00
|
|
|
/**
|
2024-10-30 21:35:55 +03:00
|
|
|
* Animated list of children with optional positioning and visibility control.
|
2024-09-12 16:42:02 +03:00
|
|
|
*/
|
2024-09-19 17:49:25 +03:00
|
|
|
function Dropdown({
|
|
|
|
isOpen,
|
|
|
|
stretchLeft,
|
|
|
|
stretchTop,
|
|
|
|
className,
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
}: React.PropsWithChildren<DropdownProps>) {
|
2023-07-20 17:11:03 +03:00
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<div className='relative'>
|
|
|
|
<motion.div
|
2024-05-11 20:53:36 +03:00
|
|
|
tabIndex={-1}
|
2023-12-28 14:04:44 +03:00
|
|
|
className={clsx(
|
2024-08-25 13:49:28 +03:00
|
|
|
'z-topmost',
|
2023-12-28 14:04:44 +03:00
|
|
|
'absolute mt-3',
|
|
|
|
'flex flex-col',
|
|
|
|
'border rounded-md shadow-lg',
|
|
|
|
'text-sm',
|
|
|
|
'clr-input',
|
|
|
|
{
|
|
|
|
'right-0': stretchLeft,
|
2024-06-26 19:00:29 +03:00
|
|
|
'left-0': !stretchLeft,
|
|
|
|
'bottom-[2rem]': stretchTop
|
2023-12-28 14:04:44 +03:00
|
|
|
},
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
initial={false}
|
|
|
|
animate={isOpen ? 'open' : 'closed'}
|
|
|
|
variants={animateDropdown}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</motion.div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-07-20 17:11:03 +03:00
|
|
|
}
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
export default Dropdown;
|