fixes
This commit is contained in:
@@ -17,13 +17,10 @@
|
|||||||
|
|
||||||
@media screen and (min-width: 1367px) {
|
@media screen and (min-width: 1367px) {
|
||||||
.container {
|
.container {
|
||||||
width: var(--max-width-page);
|
|
||||||
|
|
||||||
grid-template-columns: 1fr 340px;
|
grid-template-columns: 1fr 340px;
|
||||||
grid-template-rows: auto 1fr;
|
grid-template-rows: auto 1fr;
|
||||||
width: var(--max-width-page);
|
width: var(--max-width-page);
|
||||||
margin: var(--Spacing-x5) auto 0;
|
margin: var(--Spacing-x5) auto 0;
|
||||||
/* simulates padding on viewport smaller than --max-width-navigation */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { useCallback, useEffect, useRef, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||||
@@ -7,61 +7,13 @@ import { useEnterDetailsStore } from "@/stores/enter-details"
|
|||||||
import { CheckIcon, ChevronDownIcon } from "@/components/Icons"
|
import { CheckIcon, ChevronDownIcon } from "@/components/Icons"
|
||||||
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
||||||
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
||||||
|
import useScrollToActiveSection from "@/hooks/booking/useScrollToActiveSection"
|
||||||
|
|
||||||
import styles from "./sectionAccordion.module.css"
|
import styles from "./sectionAccordion.module.css"
|
||||||
|
|
||||||
import type { SectionAccordionProps } from "@/types/components/hotelReservation/selectRate/sectionAccordion"
|
import type { SectionAccordionProps } from "@/types/components/hotelReservation/selectRate/sectionAccordion"
|
||||||
import { StepEnum } from "@/types/enums/step"
|
import { StepEnum } from "@/types/enums/step"
|
||||||
|
|
||||||
function useScrollToActiveSection(
|
|
||||||
step: StepEnum,
|
|
||||||
steps: StepEnum[],
|
|
||||||
isActive: boolean
|
|
||||||
) {
|
|
||||||
const handleScroll = useCallback(() => {
|
|
||||||
const isMobile = window.matchMedia("(max-width: 768px)").matches
|
|
||||||
if (!isMobile) return
|
|
||||||
|
|
||||||
const currentElement = document.querySelector<HTMLElement>(
|
|
||||||
`[data-step="${step}"]`
|
|
||||||
)
|
|
||||||
const prevOpenElement =
|
|
||||||
document.querySelector<HTMLElement>(`[data-open="true"]`)
|
|
||||||
|
|
||||||
const currentStepIndex = steps.indexOf(step)
|
|
||||||
const prevStep = prevOpenElement?.dataset.step as StepEnum
|
|
||||||
const prevStepIndex = steps.indexOf(prevStep)
|
|
||||||
|
|
||||||
if (currentElement) {
|
|
||||||
const BOOKING_WIDGET_OFFSET = 71
|
|
||||||
|
|
||||||
const prevElementContent = prevOpenElement?.querySelector("header + div")
|
|
||||||
|
|
||||||
let collapsedSpace = 0
|
|
||||||
if (prevElementContent && prevStepIndex < currentStepIndex) {
|
|
||||||
collapsedSpace = prevElementContent.clientHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentElementTop =
|
|
||||||
currentElement.getBoundingClientRect().top + window.scrollY
|
|
||||||
|
|
||||||
const scrollTarget = Math.round(
|
|
||||||
currentElementTop - BOOKING_WIDGET_OFFSET - collapsedSpace
|
|
||||||
)
|
|
||||||
|
|
||||||
window.scrollTo({
|
|
||||||
top: scrollTarget,
|
|
||||||
behavior: "smooth",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [step, steps])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isActive) return
|
|
||||||
handleScroll()
|
|
||||||
}, [isActive, handleScroll])
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function SectionAccordion({
|
export default function SectionAccordion({
|
||||||
children,
|
children,
|
||||||
header,
|
header,
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export default function Select({
|
|||||||
<ListBox className={styles.listBox}>
|
<ListBox className={styles.listBox}>
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<ListBoxItem
|
<ListBoxItem
|
||||||
aria-label={JSON.stringify(item)}
|
aria-label={item.label}
|
||||||
className={`${styles.listBoxItem} ${showRadioButton && styles.showRadioButton}`}
|
className={`${styles.listBoxItem} ${showRadioButton && styles.showRadioButton}`}
|
||||||
id={item.value}
|
id={item.value}
|
||||||
key={item.label}
|
key={item.label}
|
||||||
|
|||||||
56
hooks/booking/useScrollToActiveSection.ts
Normal file
56
hooks/booking/useScrollToActiveSection.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { useCallback, useEffect } from "react"
|
||||||
|
import { useMediaQuery } from "usehooks-ts"
|
||||||
|
|
||||||
|
import { StepEnum } from "@/types/enums/step"
|
||||||
|
|
||||||
|
export default function useScrollToActiveSection(
|
||||||
|
step: StepEnum,
|
||||||
|
steps: StepEnum[],
|
||||||
|
isActive: boolean
|
||||||
|
) {
|
||||||
|
const isMobile = useMediaQuery("(max-width: 768px)")
|
||||||
|
|
||||||
|
const handleScroll = useCallback(() => {
|
||||||
|
if (!isMobile) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentElement = document.querySelector<HTMLElement>(
|
||||||
|
`[data-step="${step}"]`
|
||||||
|
)
|
||||||
|
const prevOpenElement =
|
||||||
|
document.querySelector<HTMLElement>(`[data-open="true"]`)
|
||||||
|
|
||||||
|
const currentStepIndex = steps.indexOf(step)
|
||||||
|
const prevStep = prevOpenElement?.dataset.step as StepEnum
|
||||||
|
const prevStepIndex = steps.indexOf(prevStep)
|
||||||
|
|
||||||
|
if (currentElement) {
|
||||||
|
const BOOKING_WIDGET_OFFSET = 71
|
||||||
|
|
||||||
|
const prevElementContent = prevOpenElement?.querySelector("header + div")
|
||||||
|
|
||||||
|
let collapsedSpace = 0
|
||||||
|
if (prevElementContent && prevStepIndex < currentStepIndex) {
|
||||||
|
collapsedSpace = prevElementContent.clientHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentElementTop =
|
||||||
|
currentElement.getBoundingClientRect().top + window.scrollY
|
||||||
|
|
||||||
|
const scrollTarget = Math.round(
|
||||||
|
currentElementTop - BOOKING_WIDGET_OFFSET - collapsedSpace
|
||||||
|
)
|
||||||
|
|
||||||
|
window.scrollTo({
|
||||||
|
top: scrollTarget,
|
||||||
|
behavior: "smooth",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [step, steps, isMobile])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isActive) return
|
||||||
|
handleScroll()
|
||||||
|
}, [isActive, handleScroll])
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user