|
| 1 | +import booths from "@public/assets/carnival/json/booth.json"; |
| 2 | + |
| 3 | +import React from "react"; |
| 4 | +import Carousel from "react-multi-carousel"; |
| 5 | +import "react-multi-carousel/lib/styles.css"; |
| 6 | + |
| 7 | +import useIsMobile from "@/hooks/useIsMobile"; |
| 8 | + |
| 9 | +const BoothCarousel = () => { |
| 10 | + const isMobile = useIsMobile(); |
| 11 | + |
| 12 | + if (Object.keys(booths).length === 0) { |
| 13 | + return <></>; |
| 14 | + } |
| 15 | + |
| 16 | + const responsive = { |
| 17 | + superLargeDesktop: { |
| 18 | + breakpoint: { max: 4000, min: 3000 }, |
| 19 | + items: 5, |
| 20 | + }, |
| 21 | + desktop: { |
| 22 | + breakpoint: { max: 3000, min: 1024 }, |
| 23 | + items: 3, |
| 24 | + }, |
| 25 | + tablet: { |
| 26 | + breakpoint: { max: 1024, min: 464 }, |
| 27 | + items: 2, |
| 28 | + }, |
| 29 | + mobile: { |
| 30 | + breakpoint: { max: 464, min: 0 }, |
| 31 | + items: 1, |
| 32 | + partialVisibilityGutter: 30, |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 37 | + const CustomDot = ({ onClick, active }: any): React.ReactElement => { |
| 38 | + return ( |
| 39 | + <button |
| 40 | + className={ |
| 41 | + "h-2 w-2 rounded-full " + |
| 42 | + `${active ? "bg-[#8e8e8e]" : "bg-[#f1f1f1]"}` |
| 43 | + } |
| 44 | + onClick={() => onClick()} |
| 45 | + /> |
| 46 | + ); |
| 47 | + }; |
| 48 | + |
| 49 | + const renderBooths = () => |
| 50 | + Object.entries(booths).map(([boothName, booth]) => ( |
| 51 | + <div |
| 52 | + key={boothName} |
| 53 | + className="rounded-lg border border-gray-200 bg-white p-2 shadow" |
| 54 | + > |
| 55 | + <h3>{boothName}</h3> |
| 56 | + <p className="text-sm text-gray-500"> |
| 57 | + {booth.type} - {booth.theme} |
| 58 | + </p> |
| 59 | + </div> |
| 60 | + )); |
| 61 | + |
| 62 | + return ( |
| 63 | + <div className="mt-4 px-4"> |
| 64 | + <h3 className="mb-2 font-bold">All Booths</h3> |
| 65 | + {isMobile ? ( |
| 66 | + <Carousel |
| 67 | + responsive={responsive} |
| 68 | + showDots={true} |
| 69 | + customDot={<CustomDot />} |
| 70 | + partialVisible={true} |
| 71 | + itemClass="px-2" |
| 72 | + infinite={true} |
| 73 | + > |
| 74 | + {renderBooths()} |
| 75 | + </Carousel> |
| 76 | + ) : ( |
| 77 | + <div className="grid grid-cols-2 gap-3 md:grid-cols-3"> |
| 78 | + {renderBooths()} |
| 79 | + </div> |
| 80 | + )} |
| 81 | + </div> |
| 82 | + ); |
| 83 | +}; |
| 84 | + |
| 85 | +export default BoothCarousel; |
0 commit comments