import { useState, useEffect } from "react"; type Props = { images: string[]; title: string; expansionHandler: (height: number) => void; }; export default function SimpleGallery({ images, title, expansionHandler }: Props) { const [active, setActive] = useState(0); const [enlarged, setEnlarged] = useState(false); let timerRef: any | null = null; if (images.length === 0) return null; function galleryImage(src: string, alt: string) { return (
{`${title}
) } useEffect(() => { return () => { if (timerRef) { clearTimeout(timerRef); } }; }, []); return ( <>
{galleryImage(images[active], `${title} screenshot ${active + 1}`)}
{images.length > 1 && (
{images.map((src, i) => ( {`${title}{ setActive(i) clearTimeout(timerRef); timerRef = setTimeout(() => { const imgElement = document.getElementById("gallery-image") as HTMLImageElement | null; imgElement?.height && expansionHandler(imgElement.height + 70); }, 200); // delay to allow for CSS transition }} style={{ width: 48, height: 36, objectFit: "cover", borderRadius: 3, cursor: "pointer", border: `2px solid ${i === active ? "var(--accent)" : "var(--border)"}`, opacity: i === active ? 1 : 0.6, transition: "all 0.15s ease", pointerEvents: "auto", }} /> ))}
)}
); }