import { useState } from "react"; import Button from "./ui/Button"; import ChevronLeftIcon from "./icons/ChevronLeftIcon"; import ChevronRightIcon from "./icons/ChevronRightIcon"; import { projects } from "../data/projects"; import { motion } from "motion/react"; import { useSwipeable } from "react-swipeable"; export interface InteriorSliderProps { unitTypeSlug: string; projectSlug: string; } function InteriorSlider({ unitTypeSlug, projectSlug }: InteriorSliderProps) { const images = projects ?.find((project) => project.slug === projectSlug) ?.types.find((type) => type.slug === unitTypeSlug)?.interiors; const [currentIndex, setCurrentIndex] = useState(0); const handlers = useSwipeable({ onSwipedLeft: () => images && setCurrentIndex(Math.min(currentIndex + 1, images.length - 1)), onSwipedRight: () => setCurrentIndex(Math.max(currentIndex - 1, 0)), preventScrollOnSwipe: true, touchEventOptions: { passive: false, }, trackMouse: true, }); if (!images) return null; return (
{images?.map((src, index) => ( ))}
); } export default InteriorSlider;