From a9cde500166e0ee776aa25dff9cfa9e8d29e8095 Mon Sep 17 00:00:00 2001 From: zojgame Date: Wed, 22 May 2024 18:52:02 +0500 Subject: [PATCH] similar slider --- .../complexWingPage/SequenceWing.tsx | 4 +- .../searchApartment/SimilarAppartmentCard.tsx | 63 +++++++++++ .../searchApartment/SimilarSlider.tsx | 105 ++++++++++++++++++ src/pages/SearchApartment.tsx | 6 +- 4 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 src/components/searchApartment/SimilarAppartmentCard.tsx create mode 100644 src/components/searchApartment/SimilarSlider.tsx diff --git a/src/components/complexWingPage/SequenceWing.tsx b/src/components/complexWingPage/SequenceWing.tsx index a382fd0..9ba6b39 100644 --- a/src/components/complexWingPage/SequenceWing.tsx +++ b/src/components/complexWingPage/SequenceWing.tsx @@ -148,7 +148,7 @@ const SequenceWing = () => { }, [isSidebar]); return ( -
+
{ width={`${width}px`} height={`${width}px`} src="/images/sequenceWing.jpg" - className={`absolute z-10 duration-300 transition-opacity ease-in-out opacity-100`} + className={`absolute z-10 duration-300 transition-opacity ease-in-out opacity-100 select-none`} alt="" /> ; +} + +const SimilarAppartmentCard = ({ layoutCard, elementRef }: LayoutCardProps) => { + const { + floorEnd, + floorStart, + apartmentType, + roveHome, + wing, + units, + square, + cost, + id, + } = layoutCard; + const navigate = useNavigate(); + + const handleOnClick = () => { + navigate(`${id}`); + }; + + return ( +
+
+
+

+ Rove Home {roveHome} +

+
+

{wing}

+
+

+ Floor {floorStart}-{floorEnd} +

+
+
+
+ {units} units +
+
+
+ +
+
+

+ {apartmentType}, {square} Sqft +

+

AED {cost}

+
+
+ ); +}; + +export default SimilarAppartmentCard; diff --git a/src/components/searchApartment/SimilarSlider.tsx b/src/components/searchApartment/SimilarSlider.tsx new file mode 100644 index 0000000..34af41c --- /dev/null +++ b/src/components/searchApartment/SimilarSlider.tsx @@ -0,0 +1,105 @@ +import { useEffect, useLayoutEffect, useRef, useState } from "react"; +import { layoutsCards } from "../../consts/initialSearchPage"; +import LayoutCard from "../searchPage/LayoutCard"; +import SimilarAppartmentCard from "./SimilarAppartmentCard"; +import Button from "../Button"; +import RightArrowIcon from "../icons/RightArrowIcon"; + +const SimilarSlider = () => { + const [cards, setCards] = useState(layoutsCards.slice(0, 4)); + const [offset, setOffset] = useState(0); + const sliderRef = useRef(null); + const cardRef = useRef(null); + const [sliderHeight, setSliderHeight] = useState(0); + const [cardWidth, setCardWidth] = useState(0); + + useLayoutEffect(() => { + const sliderElement = sliderRef.current; + if (sliderElement) { + const height = sliderElement.clientHeight; + setSliderHeight(height); + } + const cardElement = cardRef.current; + if (cardElement) { + const gap = 16; + const width = cardElement.clientWidth + gap; + setCardWidth(width); + } + }, []); + + useEffect(() => { + console.log("offset", offset); + + return () => {}; + }, [offset]); + + const handleOnLeftBtnClick = () => { + if (0 < offset) { + setOffset((prev) => prev + 1); + } + }; + + const handleOnRightBtnClick = () => { + // if (0 > offset) { + setOffset((prev) => prev - 1); + // } + }; + + return ( + <> +
+

+ Similar +

+
+
+
+
+
+
+
+
+ {cards.map((layoutsCard) => ( + + ))} +
+
+ {cards.map((layoutsCard) => ( + + ))} +
+
+
+
+
+ + ); +}; + +export default SimilarSlider; diff --git a/src/pages/SearchApartment.tsx b/src/pages/SearchApartment.tsx index a40d12f..2db4402 100644 --- a/src/pages/SearchApartment.tsx +++ b/src/pages/SearchApartment.tsx @@ -2,11 +2,12 @@ import Footer from "../components/Footer"; import ButtonPanel from "../components/searchApartment/ButtonPanel"; import ApartmentLayout from "../components/searchApartment/ApartmentLayout"; import ApartmentSidebar from "../components/searchApartment/ApartmentSidebar"; +import SimilarSlider from "../components/searchApartment/SimilarSlider"; const SearchApartment = () => { return (
-
+
@@ -14,6 +15,9 @@ const SearchApartment = () => {
+
+ +