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

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-03-09 21:57:21 +03:00
import React from 'react';
2024-06-07 20:17:03 +03:00
import clsx from 'clsx';
2025-02-20 20:22:05 +03:00
import { type Styling } from '../props';
2025-02-20 20:22:05 +03:00
interface DropdownProps extends Styling {
2025-03-09 21:57:21 +03:00
/** Reference to the dropdown element. */
ref?: React.Ref<HTMLDivElement>;
/** Unique ID for the dropdown. */
id?: string;
/** Margin for the dropdown. */
margin?: string;
/** 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-03-07 16:21:18 +03:00
* Note: Dropdown should be inside a relative container.
*/
2025-02-07 10:53:49 +03:00
export function Dropdown({
2024-09-19 17:48:48 +03:00
isOpen,
stretchLeft,
stretchTop,
margin,
2024-09-19 17:48:48 +03:00
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
tabIndex={-1}
className={clsx(
2025-03-07 22:04:56 +03:00
'z-topmost absolute',
2025-03-13 01:14:47 +03:00
stretchLeft ? 'right-0' : 'left-0',
stretchTop ? 'bottom-0' : 'top-full',
2025-03-07 22:04:56 +03:00
'grid',
'border rounded-md shadow-lg',
'clr-input',
'text-sm',
2025-03-13 01:14:47 +03:00
'ease-in-out duration-(--duration-dropdown) will-change-[clip-path,transform] transition-[clip-path,transform]',
margin,
className
)}
style={{
transform: isOpen ? 'translateY(0)' : 'translateY(-10%)',
clipPath: isOpen ? 'inset(0% 0% 0% 0%)' : 'inset(10% 0% 90% 0%)',
...style
}}
aria-hidden={!isOpen}
{...restProps}
>
{children}
2024-06-07 20:17:03 +03:00
</div>
);
}