From efcc47ca76c0fb1bbfb29bbff769738b1a3ce4e8 Mon Sep 17 00:00:00 2001 From: DmitriyB Date: Mon, 20 Mar 2023 17:00:36 +0500 Subject: [PATCH] swipertsx --- src/components/swiper/swiper.tsx | 141 +++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/src/components/swiper/swiper.tsx b/src/components/swiper/swiper.tsx index e69de29..adefdf1 100644 --- a/src/components/swiper/swiper.tsx +++ b/src/components/swiper/swiper.tsx @@ -0,0 +1,141 @@ +import React, { useEffect, useState } from "react"; +// Import Swiper React components +import { Swiper, SwiperSlide } from "swiper/react"; + +// import required modules +import { Pagination, Navigation } from "swiper"; +import useScreenSize from "use-screen-size"; + +import img from "./images/Architecture1.png"; +import img1 from "./images/Floor1.png"; +import img2 from "./images/Infrastructure1.png"; +import img3 from "./images/Outside.png"; +import "./swiper.css"; +import "swiper/css"; +import "swiper/css/pagination"; +import "swiper/css/navigation"; +import "../calendar/calendar"; +import { useTranslation } from "react-i18next"; + +type propsTypes = { + slidesPerView: string; + centeredSlides: boolean; + spaceBetween: number; + modules: Array; + className: string; + children: React.ReactNode; + rewind: boolean; + slideToClickedSlide: boolean, +}; + +export default function SwiperCentred(props: propsTypes) { + const { t } = useTranslation() + + const size = useScreenSize(); + const [caption, setCaption] = useState(); + + useEffect(() => { + setCaption(t('slider-subtitle1')); + }, [t]); + + function updateCaption() { + const slide = document + .querySelector(".image__slider_active") + ?.getAttribute("data-caption"); + setCaption(slide); + } + + function swiperWidth() { + if (size.width > 1600) { + return { + width: "644px", + height: "514px", + }; + } else if (size.width > 640) { + return { width: "536px", height: "428px" }; + } else { + return { width: "290px", height: "232px" }; + + } + } + + + return ( +
+ 1024 ? true : false} + spaceBetween={size.width > 640 ? 20 : 10} + initialSlide={1} + slideToClickedSlide={true} + slidesPerView={'auto'} + loop={true} + loopedSlides={3} + onSlideChangeTransitionEnd={updateCaption} + modules={[Navigation, Pagination]} + navigation={{ + nextEl: ".button_next", + prevEl: ".button_prev", + }} + pagination={{ + el: ".container1", + type: "fraction", + }} + > + + {({ isActive }) => ( + slide + )} + + + {({ isActive }) => ( + slide + )} + + + {({ isActive }) => ( + slide + )} + + + {({ isActive }) => ( + slide + )} + +
+
+
+
+
+
+
+

{caption}

+
+

+
+
+
+
+
+
+ ); +}