feat(SW-593): fix map toggle positioning
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import useHotelPageStore from "@/stores/hotel-page"
|
import useHotelPageStore from "@/stores/hotel-page"
|
||||||
@@ -13,15 +14,45 @@ export default function MobileMapToggle() {
|
|||||||
const { isDynamicMapOpen, openDynamicMap, closeDynamicMap } =
|
const { isDynamicMapOpen, openDynamicMap, closeDynamicMap } =
|
||||||
useHotelPageStore()
|
useHotelPageStore()
|
||||||
|
|
||||||
|
const mapToggleRef = useRef<HTMLDivElement>(null)
|
||||||
|
const [isVisible, setIsVisible] = useState<boolean>(true)
|
||||||
|
|
||||||
|
const handleScroll = useCallback(() => {
|
||||||
|
if (mapToggleRef.current) {
|
||||||
|
const rect = mapToggleRef.current.getBoundingClientRect()
|
||||||
|
if (rect.top >= 150) {
|
||||||
|
setIsVisible(true)
|
||||||
|
} else {
|
||||||
|
setIsVisible(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleScroll()
|
||||||
|
|
||||||
|
window.addEventListener("scroll", handleScroll)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("scroll", handleScroll)
|
||||||
|
}
|
||||||
|
}, [handleScroll])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.mobileToggle}>
|
<div
|
||||||
|
ref={mapToggleRef}
|
||||||
|
className={
|
||||||
|
isVisible
|
||||||
|
? styles.mobileToggle
|
||||||
|
: `${styles.mobileToggle} ${styles.hidden}`
|
||||||
|
}
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`${styles.button} ${!isDynamicMapOpen ? styles.active : ""}`}
|
className={`${styles.button} ${!isDynamicMapOpen ? styles.active : ""}`}
|
||||||
onClick={closeDynamicMap}
|
onClick={closeDynamicMap}
|
||||||
>
|
>
|
||||||
<HouseIcon
|
<HouseIcon
|
||||||
className={styles.icon}
|
|
||||||
color={!isDynamicMapOpen ? "white" : "red"}
|
color={!isDynamicMapOpen ? "white" : "red"}
|
||||||
height={24}
|
height={24}
|
||||||
width={24}
|
width={24}
|
||||||
@@ -34,7 +65,6 @@ export default function MobileMapToggle() {
|
|||||||
onClick={openDynamicMap}
|
onClick={openDynamicMap}
|
||||||
>
|
>
|
||||||
<MapIcon
|
<MapIcon
|
||||||
className={styles.icon}
|
|
||||||
color={isDynamicMapOpen ? "white" : "red"}
|
color={isDynamicMapOpen ? "white" : "red"}
|
||||||
height={24}
|
height={24}
|
||||||
width={24}
|
width={24}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
.mobileToggle {
|
.mobileToggle {
|
||||||
position: fixed;
|
position: sticky;
|
||||||
bottom: var(--Spacing-x5);
|
bottom: var(--Spacing-x5);
|
||||||
left: 50%;
|
margin: 0 auto;
|
||||||
transform: translateX(-50%);
|
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(2, 1fr);
|
||||||
@@ -41,6 +40,10 @@
|
|||||||
background-color: var(--Primary-Strong-Surface-Hover);
|
background-color: var(--Primary-Strong-Surface-Hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 1367px) {
|
@media screen and (min-width: 1367px) {
|
||||||
.mobileToggle {
|
.mobileToggle {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
Reference in New Issue
Block a user