import React, { useEffect, useRef, useState } from "react"; import { createPortal } from "react-dom"; import { useDismissOnOutsideAndEscape } from "../hooks/useDismissOnOutsideAndEscape"; /** * Floating popover anchored to a code-file link with multiple repo matches. * Selecting an entry calls `onPick(path)`. Esc / outside-click dismisses. */ export const CodeFilePicker: React.FC<{ anchorEl: HTMLElement | null; matches: string[]; onPick: (path: string) => void; onDismiss: () => void; }> = ({ anchorEl, matches, onPick, onDismiss }) => { const popoverRef = useRef(null); const [pos, setPos] = useState<{ top: number; left: number } | null>(null); useEffect(() => { if (!anchorEl) return; const rect = anchorEl.getBoundingClientRect(); setPos({ top: rect.bottom + 4, left: rect.left, }); }, [anchorEl]); useDismissOnOutsideAndEscape({ enabled: true, ref: popoverRef as React.RefObject, onDismiss, }); if (!pos) return null; return createPortal(
{matches.length} matches
    {matches.map((m) => (
  • ))}
, document.body, ); };