|
| 1 | +import { |
| 2 | + component$, |
| 3 | + useSignal, |
| 4 | + useStyles$, |
| 5 | + useVisibleTask$, |
| 6 | +} from "@builder.io/qwik"; |
| 7 | +import Review, { type ReviewData } from "./review"; |
| 8 | +import Swiper from "swiper"; |
| 9 | +import { Pagination, Navigation } from "swiper/modules"; |
| 10 | + |
| 11 | +const reviews: ReviewData[] = []; |
| 12 | +import swiperStyles from "swiper/swiper-bundle.css?inline"; |
| 13 | + |
| 14 | +export default component$(() => { |
| 15 | + if (reviews.length === 0) { |
| 16 | + return <></>; |
| 17 | + } |
| 18 | + useStyles$(swiperStyles); |
| 19 | + useStyles$(` |
| 20 | + .swiper-slide { |
| 21 | + filter: blur(2px) !important; |
| 22 | + transform: scale(0.8) !important; |
| 23 | + transition: all 0.2s; |
| 24 | + } |
| 25 | + .swiper-slide-active { |
| 26 | + filter: blur(0) !important; |
| 27 | + transform: scale(1) !important; |
| 28 | + } |
| 29 | + .swiper-pagination { |
| 30 | + position: static; |
| 31 | + } |
| 32 | + .swiper-pagination-bullet { |
| 33 | + width: 2.5rem; |
| 34 | + height: 0.25rem; |
| 35 | + border-radius: 50px; |
| 36 | + background: #fff; |
| 37 | + } |
| 38 | + .swiper-pagination-bullet-active { |
| 39 | + width: 4rem; |
| 40 | + } |
| 41 | + `); |
| 42 | + |
| 43 | + const swiperRef = useSignal<HTMLElement>(); |
| 44 | + const nextRef = useSignal<HTMLElement>(); |
| 45 | + const prevRef = useSignal<HTMLElement>(); |
| 46 | + const paginationRef = useSignal<HTMLElement>(); |
| 47 | + |
| 48 | + // eslint-disable-next-line qwik/no-use-visible-task |
| 49 | + useVisibleTask$(() => { |
| 50 | + new Swiper(swiperRef.value!, { |
| 51 | + spaceBetween: 30, |
| 52 | + pagination: { |
| 53 | + el: paginationRef.value, |
| 54 | + type: "bullets", |
| 55 | + clickable: true, |
| 56 | + }, |
| 57 | + navigation: { |
| 58 | + prevEl: prevRef.value, |
| 59 | + nextEl: nextRef.value, |
| 60 | + }, |
| 61 | + slidesPerView: 1, |
| 62 | + breakpoints: { |
| 63 | + 768: { slidesPerView: 2 }, |
| 64 | + 1280: { slidesPerView: 3 }, |
| 65 | + }, |
| 66 | + modules: [Pagination, Navigation], |
| 67 | + centeredSlides: true, |
| 68 | + slideToClickedSlide: true, |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + return ( |
| 73 | + <section |
| 74 | + class="review-slide swiper container m-auto my-4 min-h-[400px] select-none" |
| 75 | + ref={swiperRef} |
| 76 | + > |
| 77 | + <div class="swiper-wrapper"> |
| 78 | + {reviews.map((review) => ( |
| 79 | + <div key={review.name} class="swiper-slide"> |
| 80 | + <Review review={review} /> |
| 81 | + </div> |
| 82 | + ))} |
| 83 | + </div> |
| 84 | + <div class="mt-8 flex justify-center"> |
| 85 | + <div class="flex gap-2"> |
| 86 | + <button |
| 87 | + class="group rounded-lg border-[1px] px-4 py-2 disabled:opacity-50" |
| 88 | + ref={prevRef} |
| 89 | + > |
| 90 | + <div class="h-3 w-3 translate-x-1/4 rotate-45 border-b-2 border-s-2 border-light" /> |
| 91 | + </button> |
| 92 | + <button |
| 93 | + class="group rounded-lg border-[1px] px-4 py-2 disabled:opacity-50" |
| 94 | + ref={nextRef} |
| 95 | + > |
| 96 | + <div class=" h-3 w-3 -translate-x-1/4 rotate-45 border-e-2 border-t-2 border-light" /> |
| 97 | + </button> |
| 98 | + </div> |
| 99 | + <div |
| 100 | + class="swiper-pagination hidden md:block" |
| 101 | + ref={paginationRef} |
| 102 | + ></div> |
| 103 | + </div> |
| 104 | + </section> |
| 105 | + ); |
| 106 | +}); |
0 commit comments