Portal/rsconcept/frontend/src/components/Dropdown/Dropdown.tsx

63 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
2024-12-12 13:17:24 +03:00
import { PARAMETER } from '@/utils/constants';
2024-06-07 20:17:03 +03:00
import { CProps } from '../props';
2024-06-07 20:17:03 +03:00
interface DropdownProps extends CProps.Styling {
/** Indicates whether the dropdown should stretch to the left. */
2024-06-07 20:17:03 +03:00
stretchLeft?: boolean;
/** Indicates whether the dropdown should stretch to the top. */
2024-06-26 18:59:49 +03:00
stretchTop?: boolean;
/** Indicates whether the dropdown is open. */
2024-06-07 20:17:03 +03:00
isOpen: boolean;
}
/**
2024-10-30 21:35:43 +03:00
* Animated list of children with optional positioning and visibility control.
*/
2025-02-07 10:53:49 +03:00
export function Dropdown({
2024-09-19 17:48:48 +03:00
isOpen,
stretchLeft,
stretchTop,
className,
children,
2024-12-12 13:17:24 +03:00
style,
2024-09-19 17:48:48 +03:00
...restProps
}: React.PropsWithChildren<DropdownProps>) {
2024-06-07 20:17:03 +03:00
return (
<div className='relative'>
2024-12-12 13:17:24 +03:00
<div
2024-06-07 20:17:03 +03:00
tabIndex={-1}
className={clsx(
'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
)}
2024-12-12 13:17:24 +03:00
style={{
transitionProperty: 'clip-path, transform',
transitionDuration: `${PARAMETER.dropdownDuration}ms`,
transitionTimingFunction: 'ease-in-out',
transform: isOpen ? 'translateY(0)' : 'translateY(-10%)',
clipPath: isOpen ? 'inset(0% 0% 0% 0%)' : 'inset(10% 0% 90% 0%)',
...style
}}
2024-06-07 20:17:03 +03:00
{...restProps}
>
{children}
2024-12-12 13:17:24 +03:00
</div>
2024-06-07 20:17:03 +03:00
</div>
);
}