diff --git a/src/components/GallerySlider.tsx b/src/components/GallerySlider.tsx new file mode 100644 index 0000000..865a718 --- /dev/null +++ b/src/components/GallerySlider.tsx @@ -0,0 +1,146 @@ +"use client"; + +import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; +import { AnimatePresence, motion, MotionConfig } from "framer-motion"; +import Image, { StaticImageData } from "next/image"; +import { useState } from "react"; +import { useSwipeable } from "react-swipeable"; +import { variants } from "@/utils/animationVariants"; +import Link from "next/link"; +import { Route } from "@/routers/types"; + +export interface GallerySliderProps { + className?: string; + galleryImgs: (StaticImageData | string)[]; + ratioClass?: string; + uniqueID: string; + href?: Route; + imageClass?: string; + galleryClass?: string; + navigation?: boolean; +} + +export default function GallerySlider({ + className = "", + galleryImgs, + ratioClass = "aspect-w-4 aspect-h-3", + imageClass = "", + uniqueID = "uniqueID", + galleryClass = "rounded-xl", + href = "/listing-stay-detail", + navigation = true, +}: GallerySliderProps) { + const [loaded, setLoaded] = useState(false); + const [index, setIndex] = useState(0); + const [direction, setDirection] = useState(0); + const images = galleryImgs; + + function changePhotoId(newVal: number) { + if (newVal > index) { + setDirection(1); + } else { + setDirection(-1); + } + setIndex(newVal); + } + + const handlers = useSwipeable({ + onSwipedLeft: () => { + if (index < images?.length - 1) { + changePhotoId(index + 1); + } + }, + onSwipedRight: () => { + if (index > 0) { + changePhotoId(index - 1); + } + }, + trackMouse: true, + }); + + let currentImage = images[index]; + + return ( + +
+ {/* Main image */} +
+ + + + listing card gallery setLoaded(true)} + sizes="(max-width: 1025px) 100vw, 300px" + /> + + + +
+ + {/* Buttons + bottom nav bar */} + <> + {/* Buttons */} + {loaded && navigation && ( +
+ {index > 0 && ( + + )} + {index + 1 < images.length && ( + + )} +
+ )} + + {/* Bottom Nav bar */} +
+
+ {images.map((_, i) => ( +
+ +
+
+ ); +}