import { HelpCircle, X } from 'lucide-react'; import React, { ReactNode, useEffect, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; import { Box } from '@/ui/Box'; import { Heading } from '@/ui/Heading'; import { Icon } from '@/ui/Icon'; import { IconButton } from '@/ui/IconButton'; import { Surface } from '@/ui/Surface'; export interface InfoFlyoutProps { isOpen: boolean; onClose: () => void; title: string; children: ReactNode; anchorRef: React.RefObject; } export const InfoFlyout = ({ isOpen, onClose, title, children, anchorRef }: InfoFlyoutProps) => { const [position, setPosition] = useState({ top: 0, left: 0 }); const flyoutRef = useRef(null); useEffect(() => { if (isOpen && anchorRef.current) { const rect = anchorRef.current.getBoundingClientRect(); const flyoutWidth = 380; const padding = 16; let left = rect.right + 12; let top = rect.top; if (left + flyoutWidth > window.innerWidth - padding) { left = rect.left - flyoutWidth - 12; } setPosition({ top, left }); } }, [isOpen, anchorRef]); if (!isOpen) return null; return createPortal( {title} {children} , document.body ); };