import React, { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { X } from '@phosphor-icons/react'; import { motion, AnimatePresence } from 'framer-motion'; import { MistOrb } from './mist'; const MistImageModal = ({ src, alt, onClose }) => { const [dimensions, setDimensions] = useState(null); useEffect(() => { if (src) document.body.style.overflow = 'hidden'; else document.body.style.overflow = ''; const handleKeyDown = (e) => { if (e.key === 'Escape') onClose(); }; if (src) window.addEventListener('keydown', handleKeyDown); return () => { document.body.style.overflow = ''; window.removeEventListener('keydown', handleKeyDown); }; }, [src, onClose]); const handleImageLoad = (e) => { setDimensions({ width: e.target.naturalWidth, height: e.target.naturalHeight, }); }; const showAlt = alt && ![ 'Project Detail', 'Enlarged Content', 'Intel Imagery', 'Full size image', ].includes(alt); return createPortal( {src && (
e.stopPropagation()} initial={{ opacity: 0, scale: 0.98, filter: 'blur(6px)' }} animate={{ opacity: 1, scale: 1, filter: 'blur(0px)' }} exit={{ opacity: 0, scale: 0.98, filter: 'blur(6px)' }} transition={{ duration: 0.4, ease: 'easeOut' }} >
image viewer · seen through fog
press esc to wake
{showAlt ? alt : 'an unnamed drift'} {dimensions ? `${dimensions.width} × ${dimensions.height} px` : 'measuring…'}
)} , document.body, ); }; export default MistImageModal;