"use client"; import { useRef, useState, useEffect } from "react"; import { imageUrl } from "@/lib/assetUrls"; /** * Wraps any element. On hover of the wrapped child, a floating popover * shows the full-resolution image at /api/image/[imageId]. */ export function HoverImagePreview({ imageId, children, }: { imageId: number; children: React.ReactNode; }) { const [show, setShow] = useState(false); const [pos, setPos] = useState<{ maxW: number; maxH: number }>({ maxW: 0, maxH: 0 }); const ref = useRef(null); const timerRef = useRef(null); const open = () => { const margin = 24; setPos({ maxW: window.innerWidth - margin * 2, maxH: window.innerHeight - margin * 2, }); timerRef.current = window.setTimeout(() => setShow(true), 120); }; const close = () => { if (timerRef.current != null) { clearTimeout(timerRef.current); timerRef.current = null; } setShow(false); }; useEffect(() => () => { if (timerRef.current != null) clearTimeout(timerRef.current); }, []); return ( <> {children} {show && (
{/* eslint-disable-next-line @next/next/no-img-element */}
)} ); }