"use client" import { useCallback, useContext, useRef } from "react" import { Dialog, Modal, ModalOverlay } from "react-aria-components" import { IconButton } from "../IconButton" import { Typography } from "../Typography" import { SidePeekContext } from "./SidePeekContext" import SidePeekSEO from "./SidePeekSEO" import { debounce } from "@scandic-hotels/common/utils/debounce" import { KeepBodyVisible } from "./KeepBodyVisible" import styles from "./sidePeek.module.css" interface SidePeekProps { contentKey?: string title: string isOpen?: boolean openInRoot?: boolean handleClose?: (isOpen: boolean) => void closeLabel: string shouldInert?: boolean } export default function SidePeek({ children, title, contentKey, handleClose, isOpen, openInRoot = false, closeLabel, shouldInert, }: React.PropsWithChildren) { const rootDiv = useRef(null) const headerRef = useRef(null) const dialogRef = useRef(null) const context = useContext(SidePeekContext) const updateHeightRefCallback = useCallback((node: HTMLElement | null) => { if (node) { const debouncedUpdate = debounce(([entry]: ResizeObserverEntry[]) => { const height = entry.contentRect.height dialogRef.current?.style.setProperty( "--sidepeek-header-height", `${height}px` ) }, 100) const observer = new ResizeObserver(debouncedUpdate) observer.observe(node) return () => { observer.unobserve(node) observer.disconnect() dialogRef.current?.style.removeProperty("--sidepeek-header-height") } } }, []) function onClose() { const closeHandler = handleClose || context?.handleClose closeHandler?.(false) } return ( <>
{children} ) }