import { useCallback, useLayoutEffect, useRef, useState } from "react"; import { createPortal } from "react-dom"; import { HelpCircle } from "lucide-react"; /** * Small ⓘ help icon with a portal-rendered tooltip. * * Reused wherever a UI element has a short label that some users * (especially non-quantum readers) might not recognise — block family * badges, status chips, terse stat labels in the pipeline pane. * * Why this looks the way it does (in detail because the previous * iterations had a few subtle gotchas): * * - **`createPortal` to `document.body`, not a CSS-only bubble.** The * old absolutely-positioned bubble was clipped by every * `overflow: hidden/auto` ancestor — inside the Evidence pane's * scroll body a tooltip near the pane edge was simply cut off. * Rendering on `document.body` with `position: fixed`, placed from * the trigger's `getBoundingClientRect()`, escapes all clipping * contexts. Placement flips above/below by available viewport * space (the `position` prop is the preferred side) and clamps * horizontally to the viewport. * * - **Scroll/resize close the tooltip.** A fixed-position bubble does * not travel with a scrolling anchor; recomputing per scroll frame * is wasted work for a hover hint, so any scroll (capture phase — * nested scrollers like the Evidence pane body included) or resize * just dismisses it. * * - **Accessibility unchanged.** The trigger keeps `tabIndex={0}` * (keyboard users tab onto the icon; focus/blur mirror * hover/unhover) and carries an `sr-only` copy of the hint as its * accessible content — screen readers read it without caring where * the visual bubble lives. The portal bubble is `aria-hidden` so * the text is never announced twice. No `aria-label`/`title`: when * a `cursor:help` element carries `aria-label`, browsers (notably * macOS Chrome) fall back to a delayed native tooltip that races * our own. * * - **`pointer-events-none` on the bubble.** Moving the cursor onto * the tooltip itself doesn't extend its visibility — once the * cursor leaves the icon, the tooltip closes immediately. Keeps it * a pure read-only affordance. * * - **Figure export**: the trigger is tagged `data-export-strip` (the * paper transform removes it), and the bubble lives on * `document.body` — outside any subtree a camera clones — so an * open tooltip can never leak into an exported figure. * * - The `onClick` blocks both default and propagation, so clicking * the icon inside a `