import { X } from 'lucide-react'; import { useEffect, useState, type ReactElement } from 'react'; import { createPortal } from 'react-dom'; import { useTranslation } from '../../i18n'; import { lockBodyScroll } from '../../utils/bodyScrollLock'; function sheetRoot(): HTMLElement { return document.getElementById('m-sheet-root') ?? document.body; } /** * One image full screen, for a picture shown small in a list (a chat * attachment). A tap on the image zooms in, and the zoomed image pans with the * finger as any scrolled page does; a tap beside it or the X closes the view, * as Escape does with a keyboard. The page's own pinch zoom is off in the app, * so the zoom is the viewer's. */ export default function MImageViewer({ src, alt, onClose, }: { src: string; alt: string; onClose: () => void; }): ReactElement { const { t } = useTranslation(); const [zoomed, setZoomed] = useState(false); useEffect(() => lockBodyScroll(), []); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [onClose]); return createPortal(