import { ArrowDownTrayIcon, ArrowTopRightOnSquareIcon, ArrowUturnLeftIcon, ChevronLeftIcon, ChevronRightIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import { AnimatePresence, motion, MotionConfig } from "framer-motion"; import Image from "next/image"; import { useState } from "react"; import { useSwipeable } from "react-swipeable"; import { variants } from "../utils/animationVariants"; import downloadPhoto from "../utils/downloadPhoto"; import { range } from "../utils/range"; import type { ImageProps, SharedModalProps } from "../utils/types"; import Twitter from "./Icons/Twitter"; export default function SharedModal({ index, images, changePhotoId, closeModal, navigation, currentPhoto, direction, }: SharedModalProps) { const [loaded, setLoaded] = useState(false); let filteredImages = images?.filter((img: ImageProps) => range(index - 15, index + 15).includes(img.id), ); const handlers = useSwipeable({ onSwipedLeft: () => { if (index < images?.length - 1) { changePhotoId(index + 1); } }, onSwipedRight: () => { if (index > 0) { changePhotoId(index - 1); } }, trackMouse: true, }); let currentImage = images ? images[index] : currentPhoto; return (
{/* Main image */}
Next.js Conf image setLoaded(true)} />
{/* Buttons + bottom nav bar */}
{/* Buttons */} {loaded && (
{navigation && ( <> {index > 0 && ( )} {index + 1 < images.length && ( )} )}
{navigation ? ( ) : ( )}
)} {/* Bottom Nav bar */} {navigation && (
{filteredImages.map(({ public_id, format, id }) => ( changePhotoId(id)} key={id} className={`${ id === index ? "z-20 rounded-md shadow shadow-black/50" : "z-10" } ${id === 0 ? "rounded-l-md" : ""} ${ id === images.length - 1 ? "rounded-r-md" : "" } relative inline-block w-full shrink-0 transform-gpu overflow-hidden focus:outline-none`} > small photos on the bottom ))}
)}
); }