"use client"; import { ReactNode, useState, useCallback, useEffect, useRef, useId, } from "react"; interface TooltipProps { label: string; description?: string; children: ReactNode; side?: "right" | "bottom"; } export function Tooltip({ label, description, children, side = "right", }: TooltipProps) { const [visible, setVisible] = useState(false); const timeoutRef = useRef | null>(null); const tooltipId = useId(); const showTooltip = useCallback(() => { if (timeoutRef.current) clearTimeout(timeoutRef.current); timeoutRef.current = setTimeout(() => setVisible(true), 300); }, []); const showNow = useCallback(() => { if (timeoutRef.current) clearTimeout(timeoutRef.current); setVisible(true); }, []); const hideTooltip = useCallback(() => { if (timeoutRef.current) clearTimeout(timeoutRef.current); setVisible(false); }, []); useEffect(() => { return () => { if (timeoutRef.current) clearTimeout(timeoutRef.current); }; }, []); return (
{children} {visible && ( )}
); }