|
| 1 | +"use client"; |
| 2 | +import { useState } from "react"; |
| 3 | +import { Swiper, SwiperSlide } from "swiper/react"; |
| 4 | +import { Navigation, Pagination, Autoplay } from "swiper/modules"; |
| 5 | +import Image from "next/image"; |
| 6 | + |
| 7 | +import H1 from "../components/H1"; |
| 8 | +import H2 from "../components/H2"; |
| 9 | +import Article from "../components/Article"; |
| 10 | +import ClickFocus from "./components/ClickFocus"; |
| 11 | +import { images, type ImageItem } from "./data/Images"; |
| 12 | + |
| 13 | +import "swiper/css"; |
| 14 | +import "swiper/css/navigation"; |
| 15 | +import "swiper/css/pagination"; |
| 16 | +import { ChevronLeft, ChevronRight } from "lucide-react"; |
| 17 | + |
| 18 | +export default function HomeEventHighlights() { |
| 19 | + const [selectedImage, setSelectedImage] = useState<ImageItem | null>(null); |
| 20 | + const [selectedIndex, setSelectedIndex] = useState<number>(0); |
| 21 | + |
| 22 | + const openModal = (image: ImageItem) => { |
| 23 | + const index = images.findIndex((img) => img.id === image.id); |
| 24 | + setSelectedIndex(index); |
| 25 | + setSelectedImage(image); |
| 26 | + }; |
| 27 | + |
| 28 | + const closeModal = () => { |
| 29 | + setSelectedImage(null); |
| 30 | + }; |
| 31 | + |
| 32 | + return ( |
| 33 | + <Article id="home-achievements"> |
| 34 | + <H1>成果展現</H1> |
| 35 | + <H2>活動花絮</H2> |
| 36 | + <div className="relative max-w-6xl mx-auto mt-8 overflow-hidden group md:h-64"> |
| 37 | + <Swiper |
| 38 | + modules={[Navigation, Pagination, Autoplay]} |
| 39 | + spaceBetween={10} |
| 40 | + slidesPerView={2} |
| 41 | + centeredSlides={true} |
| 42 | + loop={true} |
| 43 | + autoplay={{ |
| 44 | + delay: 3000, |
| 45 | + }} |
| 46 | + breakpoints={{ |
| 47 | + // Mobile |
| 48 | + 320: { |
| 49 | + slidesPerView: 1.5, |
| 50 | + spaceBetween: 0, |
| 51 | + }, |
| 52 | + // Mobile L |
| 53 | + 480: { |
| 54 | + slidesPerView: 1.5, |
| 55 | + spaceBetween: 0, |
| 56 | + }, |
| 57 | + // Tablet |
| 58 | + 768: { |
| 59 | + slidesPerView: 2, |
| 60 | + spaceBetween: 11, |
| 61 | + }, |
| 62 | + // Desktop |
| 63 | + 1024: { |
| 64 | + slidesPerView: 2.2, |
| 65 | + spaceBetween: 10, |
| 66 | + }, |
| 67 | + // Desktop L |
| 68 | + 1280: { |
| 69 | + slidesPerView: 2.2, |
| 70 | + spaceBetween: 10, |
| 71 | + }, |
| 72 | + }} |
| 73 | + pagination={{ |
| 74 | + clickable: true, |
| 75 | + }} |
| 76 | + navigation={{ |
| 77 | + nextEl: ".swiper-button-next-highlights", |
| 78 | + prevEl: ".swiper-button-prev-highlights", |
| 79 | + }} |
| 80 | + className="w-full h-full" |
| 81 | + > |
| 82 | + {images.map((image) => ( |
| 83 | + <SwiperSlide key={image.id}> |
| 84 | + {({ isActive }) => ( |
| 85 | + <button |
| 86 | + type="button" |
| 87 | + className={`h-full transition-transform duration-300 ease-in-out ${isActive ? "scale-100" : "scale-75 opacity-60"} w-full`} |
| 88 | + onClick={() => openModal(image)} |
| 89 | + aria-label={`View ${image.alt}`} |
| 90 | + > |
| 91 | + <div className="relative w-full aspect-video md:h-full"> |
| 92 | + <Image |
| 93 | + src={image.src} |
| 94 | + alt={image.alt} |
| 95 | + fill |
| 96 | + sizes="(max-width: 768px) 10vw, (max-width: 1200px) 10vw, 33vw" |
| 97 | + className="object-cover rounded-md" |
| 98 | + priority={image.id === 1} |
| 99 | + /> |
| 100 | + </div> |
| 101 | + </button> |
| 102 | + )} |
| 103 | + </SwiperSlide> |
| 104 | + ))} |
| 105 | + </Swiper> |
| 106 | + |
| 107 | + <div className="swiper-button-prev-highlights absolute left-4 top-1/2 -translate-y-1/2 z-10 cursor-pointer p-2 rounded-full leading-none bg-white bg-opacity-40 hover:bg-opacity-60 transition-all duration-300 opacity-0 group-hover:opacity-100"> |
| 108 | + <ChevronLeft size={16} /> |
| 109 | + </div> |
| 110 | + <div className="swiper-button-next-highlights absolute right-4 top-1/2 -translate-y-1/2 z-10 cursor-pointer p-2 rounded-full leading-none bg-white bg-opacity-40 hover:bg-opacity-60 transition-all duration-300 opacity-0 group-hover:opacity-100"> |
| 111 | + <ChevronRight size={16} /> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + {selectedImage && ( |
| 115 | + <ClickFocus |
| 116 | + closeModal={closeModal} |
| 117 | + selectedImage={selectedImage} |
| 118 | + setSelectedImage={setSelectedImage} |
| 119 | + selectedIndex={selectedIndex} |
| 120 | + setSelectedIndex={setSelectedIndex} |
| 121 | + /> |
| 122 | + )} |
| 123 | + <a |
| 124 | + href="https://photos.app.goo.gl/MwV2tBbE1YxWxuL18" |
| 125 | + target="_blank" |
| 126 | + rel="noopener noreferrer" |
| 127 | + className="text-gray-500 underline hover:text-blue-600 cursor-pointer" |
| 128 | + > |
| 129 | + 前往共用相簿 |
| 130 | + </a> |
| 131 | + </Article> |
| 132 | + ); |
| 133 | +} |
0 commit comments