Feat/BOOK-61 refactor hotel page css variables * feat(BOOK-61): Breadcrumbs * feat(BOOK-61): intro section * feat(BOOK-61): show more button * feat(BOOK-61): rooms section * feat(BOOK-61): sidepeeks * feat(BOOK-61): deprecated old Link component * feat(BOOK-61): added new TextLink component to the design-system * feat(BOOK-61): replaced deprecated links with new TextLink component * feat(BOOK-61): miscellaneous changes Approved-by: Bianca Widstam Approved-by: Christel Westerberg
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
'use client'
|
|
|
|
import { useContext, useRef } from 'react'
|
|
import { Dialog, Modal, ModalOverlay } from 'react-aria-components'
|
|
|
|
import { MaterialIcon } from '../Icons/MaterialIcon'
|
|
import { Typography } from '../Typography'
|
|
|
|
import { SidePeekContext } from './SidePeekContext'
|
|
|
|
import SidePeekSEO from './SidePeekSEO'
|
|
|
|
import { IconButton } from '../IconButton'
|
|
import styles from './sidePeek.module.css'
|
|
|
|
interface SidePeekProps {
|
|
contentKey?: string
|
|
title: string
|
|
isOpen?: boolean
|
|
openInRoot?: boolean
|
|
handleClose?: (isOpen: boolean) => void
|
|
closeLabel: string
|
|
}
|
|
|
|
export default function SidePeek({
|
|
children,
|
|
title,
|
|
contentKey,
|
|
handleClose,
|
|
isOpen,
|
|
openInRoot = false,
|
|
closeLabel,
|
|
}: React.PropsWithChildren<SidePeekProps>) {
|
|
const rootDiv = useRef<HTMLDivElement>(null)
|
|
|
|
const context = useContext(SidePeekContext)
|
|
function onClose() {
|
|
const closeHandler = handleClose || context?.handleClose
|
|
closeHandler?.(false)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div ref={openInRoot ? null : rootDiv}>
|
|
<ModalOverlay
|
|
UNSTABLE_portalContainer={rootDiv.current || undefined}
|
|
className={styles.overlay}
|
|
isOpen={
|
|
isOpen || (!!contentKey && contentKey === context?.activeSidePeek)
|
|
}
|
|
onOpenChange={onClose}
|
|
isDismissable
|
|
>
|
|
<Modal className={styles.modal}>
|
|
<Dialog className={styles.dialog} aria-label={title}>
|
|
<aside className={styles.aside}>
|
|
<header className={styles.header}>
|
|
{title ? (
|
|
<Typography variant="Title/md">
|
|
<h2 className={styles.heading}>{title}</h2>
|
|
</Typography>
|
|
) : null}
|
|
<IconButton
|
|
theme="Black"
|
|
style="Muted"
|
|
onPress={onClose}
|
|
aria-label={closeLabel}
|
|
>
|
|
<MaterialIcon
|
|
icon="close"
|
|
color="Icon/Interactive/Default"
|
|
/>
|
|
</IconButton>
|
|
</header>
|
|
<div className={styles.sidePeekContent}>{children}</div>
|
|
</aside>
|
|
</Dialog>
|
|
</Modal>
|
|
</ModalOverlay>
|
|
</div>
|
|
|
|
<SidePeekSEO title={title}>{children}</SidePeekSEO>
|
|
</>
|
|
)
|
|
}
|