import React, { ReactNode, useState, useRef } from 'react'; import { useClickOutside } from '@/app/hooks/useClickOutside'; interface DropDownListProps { children: ReactNode; value: string | number; callBack: (value: string) => void; } interface ChildProps { value?: string; onClick?: () => void; className?: string; children?: React.ReactNode; } export default function DropDownList({ children, value, callBack }: DropDownListProps) { const [isOpen, setIsOpen] = useState(false) const dropdownRef = useRef(null) useClickOutside(dropdownRef, () => { setIsOpen(false); }); const enhancedChildren = React.Children.map(children, (child, index) => { if (React.isValidElement(child)) { const childValue = child.props.value || undefined; return React.cloneElement(child, { onClick: () => { callBack(childValue || ""); setIsOpen(false); }, className: `flex items-center w-full px-4 py-2 text-sm text-left hover:bg-blue-100 cursor-pointer select-none`, key: index }); } return child; }); return (
{isOpen && (
    {enhancedChildren}
)}
) }