feat(343): Style fixes on map
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { useRouter } from "next/navigation"
|
|
||||||
import { type ElementRef, useEffect, useRef } from "react"
|
|
||||||
|
|
||||||
export function Modal({ children }: { children: React.ReactNode }) {
|
|
||||||
const router = useRouter()
|
|
||||||
const dialogRef = useRef<ElementRef<"dialog">>(null)
|
|
||||||
|
|
||||||
console.log("modal is open")
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!dialogRef.current?.open) {
|
|
||||||
dialogRef.current?.showModal()
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
function onDismiss() {
|
|
||||||
router.back()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="modal-backdrop">
|
|
||||||
<dialog ref={dialogRef} className="modal" onClose={onDismiss}>
|
|
||||||
{children}
|
|
||||||
<button onClick={onDismiss} className="close-button" />
|
|
||||||
</dialog>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ import { env } from "@/env/server"
|
|||||||
import { getLocations } from "@/lib/trpc/memoizedRequests"
|
import { getLocations } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import SelectHotelMap from "@/components/HotelReservation/SelectHotel/SelectHotelMap"
|
import SelectHotelMap from "@/components/HotelReservation/SelectHotel/SelectHotelMap"
|
||||||
import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { MapModal } from "@/components/MapModal"
|
import { MapModal } from "@/components/MapModal"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
.layout {
|
.layout {
|
||||||
min-height: 100dvh;
|
min-height: 100dvh;
|
||||||
background-color: var(--Base-Background-Primary-Normal);
|
background-color: var(--Base-Background-Primary-Normal);
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
getPointOfInterests,
|
getPointOfInterests,
|
||||||
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
||||||
import SelectHotelMap from "@/components/HotelReservation/SelectHotel/SelectHotelMap"
|
import SelectHotelMap from "@/components/HotelReservation/SelectHotel/SelectHotelMap"
|
||||||
import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import styles from "./page.module.css"
|
import styles from "./page.module.css"
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { APIProvider } from "@vis.gl/react-google-maps"
|
import { APIProvider } from "@vis.gl/react-google-maps"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { selectHotel } from "@/constants/routes/hotelReservation"
|
import { selectHotel } from "@/constants/routes/hotelReservation"
|
||||||
|
|
||||||
import { CloseIcon } from "@/components/Icons"
|
import { CloseIcon, CloseLargeIcon } from "@/components/Icons"
|
||||||
import InteractiveMap from "@/components/Maps/InteractiveMap"
|
import InteractiveMap from "@/components/Maps/InteractiveMap"
|
||||||
import Button from "@/components/TempDesignSystem/Button"
|
import Button from "@/components/TempDesignSystem/Button"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
@@ -23,38 +24,38 @@ export default function SelectHotelMap({
|
|||||||
pointsOfInterest,
|
pointsOfInterest,
|
||||||
mapId,
|
mapId,
|
||||||
}: SelectHotelMapProps) {
|
}: SelectHotelMapProps) {
|
||||||
|
const router = useRouter()
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const [activePoi, setActivePoi] = useState<string | null>(null)
|
const [activePoi, setActivePoi] = useState<string | null>(null)
|
||||||
|
|
||||||
|
function onDismiss() {
|
||||||
|
router.back()
|
||||||
|
}
|
||||||
|
|
||||||
const closeButton = (
|
const closeButton = (
|
||||||
<Button
|
<Button
|
||||||
asChild
|
|
||||||
intent="inverted"
|
intent="inverted"
|
||||||
size="small"
|
size="small"
|
||||||
theme="base"
|
theme="base"
|
||||||
className={styles.closeButton}
|
className={styles.closeButton}
|
||||||
|
onClick={onDismiss}
|
||||||
>
|
>
|
||||||
<Link href={selectHotel[lang]} keepSearchParams color="burgundy">
|
<CloseIcon color="burgundy" />
|
||||||
<CloseIcon color="burgundy" />
|
{intl.formatMessage({ id: "Close the map" })}
|
||||||
{intl.formatMessage({ id: "Close the map" })}
|
|
||||||
</Link>
|
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<APIProvider apiKey={apiKey}>
|
<APIProvider apiKey={apiKey}>
|
||||||
<div className={styles.filterContainer}>
|
<div className={styles.filterContainer}>
|
||||||
<Button
|
<Button
|
||||||
asChild
|
|
||||||
intent="text"
|
intent="text"
|
||||||
size="small"
|
size="small"
|
||||||
theme="base"
|
|
||||||
variant="icon"
|
variant="icon"
|
||||||
wrapping
|
wrapping
|
||||||
|
onClick={onDismiss}
|
||||||
>
|
>
|
||||||
<Link href={selectHotel[lang]} keepSearchParams color="burgundy">
|
<CloseLargeIcon />
|
||||||
<CloseIcon color="burgundy" width={32} height={32} />
|
|
||||||
</Link>
|
|
||||||
</Button>
|
</Button>
|
||||||
<span>Filter and sort</span>
|
<span>Filter and sort</span>
|
||||||
{/* TODO: Add filter and sort button */}
|
{/* TODO: Add filter and sort button */}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
position: absolute;
|
position: relative;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
@@ -18,6 +18,10 @@
|
|||||||
padding: 0 var(--Spacing-x2);
|
padding: 0 var(--Spacing-x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.filterContainer .closeButton {
|
||||||
|
color: var(--UI-Text-High-Contrast);
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
.closeButton {
|
.closeButton {
|
||||||
display: flex !important;
|
display: flex !important;
|
||||||
|
|||||||
@@ -1,43 +1,88 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useEffect, useRef, useState } from "react"
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
import { Dialog, Modal } from "react-aria-components"
|
import { Dialog, Modal } from "react-aria-components"
|
||||||
|
|
||||||
|
import { useHandleKeyUp } from "@/hooks/useHandleKeyUp"
|
||||||
|
import { debounce } from "@/utils/debounce"
|
||||||
|
|
||||||
import styles from "./mapModal.module.css"
|
import styles from "./mapModal.module.css"
|
||||||
|
|
||||||
export function MapModal({ children }: { children: React.ReactNode }) {
|
export function MapModal({ children }: { children: React.ReactNode }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const [mapHeight, setMapHeight] = useState("0px")
|
||||||
|
const [mapTop, setMapTop] = useState("0px")
|
||||||
|
|
||||||
const [scrollHeightWhenOpened, setScrollHeightWhenOpened] = useState(0)
|
const [scrollHeightWhenOpened, setScrollHeightWhenOpened] = useState(0)
|
||||||
const hasMounted = useRef(false)
|
|
||||||
|
const rootDiv = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
function onDismiss() {
|
function onDismiss() {
|
||||||
router.back()
|
router.back()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Making sure the map is always opened at the top of the page, just below the header.
|
useHandleKeyUp((event: KeyboardEvent) => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Calculate the height of the map based on the viewport height from the start-point (below the header and booking widget)
|
||||||
|
const handleMapHeight = useCallback(() => {
|
||||||
|
const topPosition = rootDiv.current?.getBoundingClientRect().top ?? 0
|
||||||
|
const scrollY = window.scrollY
|
||||||
|
setMapHeight(`calc(100dvh - ${topPosition + scrollY}px)`)
|
||||||
|
setMapTop(`${topPosition + scrollY}px`)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// Making sure the map is always opened at the top of the page,
|
||||||
|
// just below the header and booking widget as these should stay visible.
|
||||||
// When closing, the page should scroll back to the position it was before opening the map.
|
// When closing, the page should scroll back to the position it was before opening the map.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Skip the first render
|
// Skip the first render
|
||||||
if (!hasMounted.current) {
|
if (!rootDiv.current) {
|
||||||
hasMounted.current = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollHeightWhenOpened === 0) {
|
if (scrollHeightWhenOpened === 0) {
|
||||||
setScrollHeightWhenOpened(window.scrollY)
|
const scrollY = window.scrollY
|
||||||
|
setScrollHeightWhenOpened(scrollY)
|
||||||
window.scrollTo({ top: 0, behavior: "instant" })
|
window.scrollTo({ top: 0, behavior: "instant" })
|
||||||
}
|
}
|
||||||
}, [scrollHeightWhenOpened])
|
}, [scrollHeightWhenOpened, rootDiv])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const debouncedResizeHandler = debounce(function () {
|
||||||
|
handleMapHeight()
|
||||||
|
})
|
||||||
|
|
||||||
|
const observer = new ResizeObserver(debouncedResizeHandler)
|
||||||
|
|
||||||
|
observer.observe(document.documentElement)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (observer) {
|
||||||
|
observer.unobserve(document.documentElement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [rootDiv, handleMapHeight])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={true}>
|
<div className={styles.wrapper} ref={rootDiv}>
|
||||||
<Dialog className={styles.dynamicMap}>
|
<Modal isOpen={true}>
|
||||||
{children}
|
<Dialog
|
||||||
<button onClick={onDismiss} className="close-button">
|
style={
|
||||||
close
|
{
|
||||||
</button>
|
"--hotel-map-height": mapHeight,
|
||||||
</Dialog>
|
"--hotel-map-top": mapTop,
|
||||||
</Modal>
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
className={styles.dynamicMap}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Dialog>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
.dynamicMap {
|
.dynamicMap {
|
||||||
position: fixed;
|
--hotel-map-height: 100dvh;
|
||||||
top: calc(
|
--hotel-map-top: 0px;
|
||||||
var(--main-menu-mobile-height) + var(--booking-widget-mobile-height) - 4px
|
position: absolute;
|
||||||
);
|
top: var(--hotel-map-top);
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: var(--dialog-z-index);
|
height: var(--hotel-map-height);
|
||||||
|
width: 100dvw;
|
||||||
|
z-index: var(--hotel-dynamic-map-z-index);
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
background-color: var(--Base-Surface-Primary-light-Normal);
|
background-color: var(--Base-Surface-Primary-light-Normal);
|
||||||
}
|
}
|
||||||
|
.wrapper {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 768px) {
|
@media screen and (min-width: 768px) {
|
||||||
.dynamicMap {
|
.dynamicMap {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
.mapContainer {
|
.mapContainer {
|
||||||
--button-box-shadow: 0 0 8px 1px rgba(0, 0, 0, 0.1);
|
--button-box-shadow: 0 0 8px 1px rgba(0, 0, 0, 0.1);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user