From 0ddbd3c549e476754814a3d2e2ecbbe90aaacf61 Mon Sep 17 00:00:00 2001 From: Chuma McPhoy Date: Fri, 6 Sep 2024 09:52:21 +0200 Subject: [PATCH] refactor(SW-337): css only approach for sticky tab navigation --- .../HotelPage/TabNavigation/index.tsx | 60 +++++++------------ .../TabNavigation/tabNavigation.module.css | 26 ++++---- .../HotelPage/hotelPage.module.css | 17 ++++-- components/ContentType/HotelPage/index.tsx | 4 +- 4 files changed, 44 insertions(+), 63 deletions(-) diff --git a/components/ContentType/HotelPage/TabNavigation/index.tsx b/components/ContentType/HotelPage/TabNavigation/index.tsx index e88879244..ea688679c 100644 --- a/components/ContentType/HotelPage/TabNavigation/index.tsx +++ b/components/ContentType/HotelPage/TabNavigation/index.tsx @@ -1,5 +1,4 @@ "use client" -import { useEffect, useRef } from "react" import { useIntl } from "react-intl" import Link from "@/components/TempDesignSystem/Link" @@ -12,25 +11,6 @@ import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation" export default function TabNavigation() { const hash = useHash() const intl = useIntl() - const navRef = useRef(null) - - useEffect(() => { - const nav = navRef.current - if (!nav) return - - const sticky = nav.offsetTop - - const handleScroll = () => { - if (window.scrollY > sticky) { - nav.classList.add(styles.sticky) - } else { - nav.classList.remove(styles.sticky) - } - } - - window.addEventListener("scroll", handleScroll) - return () => window.removeEventListener("scroll", handleScroll) - }, []) const hotelTabLinks: { href: HotelHashValues; text: string }[] = [ { href: HotelHashValues.overview, text: "Overview" }, @@ -43,24 +23,26 @@ export default function TabNavigation() { ] return ( - +
+ +
) } diff --git a/components/ContentType/HotelPage/TabNavigation/tabNavigation.module.css b/components/ContentType/HotelPage/TabNavigation/tabNavigation.module.css index 2d3748b51..9e5ee8f5a 100644 --- a/components/ContentType/HotelPage/TabNavigation/tabNavigation.module.css +++ b/components/ContentType/HotelPage/TabNavigation/tabNavigation.module.css @@ -1,30 +1,24 @@ -.tabsContainer { - display: flex; +.stickyWrapper { + position: sticky; + top: 0; + z-index: 10; + background-color: var(--Base-Surface-Subtle-Normal); + border-bottom: 1px solid var(--Base-Border-Subtle); overflow-x: auto; white-space: nowrap; +} + +.tabsContainer { + display: flex; gap: var(--Spacing-x4); justify-content: flex-start; padding: 0 var(--Spacing-x2); - max-width: 100vw; - width: 100%; - background-color: var(--Base-Surface-Subtle-Normal); - z-index: 1000; -} - -.sticky { - position: fixed; - top: 0; - left: 0; - right: 0; - border-bottom: 1px solid var(--Base-Border-Subtle); width: 100%; } @media screen and (min-width: 1367px) { .tabsContainer { padding: 0 var(--Spacing-x5); - } - .sticky { max-width: calc(100% - var(--hotel-page-map-desktop-width)); } } diff --git a/components/ContentType/HotelPage/hotelPage.module.css b/components/ContentType/HotelPage/hotelPage.module.css index 2f8e99626..78f0cd686 100644 --- a/components/ContentType/HotelPage/hotelPage.module.css +++ b/components/ContentType/HotelPage/hotelPage.module.css @@ -2,20 +2,27 @@ display: grid; max-width: var(--max-width); margin: 0 auto; + grid-template-areas: + "hotelImages" + "tabNavigation" + "mainSection" + "mapContainer"; } -.topSection { +.hotelImages { + grid-area: hotelImages; background-color: var(--Base-Surface-Subtle-Normal); - border-bottom: 1px solid var(--Base-Border-Subtle); } .mainSection { + grid-area: mainSection; display: grid; gap: var(--Spacing-x9); padding: var(--Spacing-x4) var(--Spacing-x2); } .mapContainer { + grid-area: mapContainer; display: none; } @@ -27,13 +34,11 @@ @media screen and (min-width: 1367px) { .pageContainer { grid-template-areas: - "topSection mapContainer" + "hotelImages mapContainer" + "tabNavigation mapContainer" "mainSection mapContainer"; grid-template-columns: 1fr var(--hotel-page-map-desktop-width); } - .topSection { - grid-area: topSection; - } .mainSection { grid-area: mainSection; padding: var(--Spacing-x6) 0; diff --git a/components/ContentType/HotelPage/index.tsx b/components/ContentType/HotelPage/index.tsx index 6b5abc9dd..cec60d055 100644 --- a/components/ContentType/HotelPage/index.tsx +++ b/components/ContentType/HotelPage/index.tsx @@ -32,10 +32,10 @@ export default async function HotelPage() { return (
-
+
-
+