Files
web/packages/design-system/lib/components/SidePeek/index.tsx
Erik Tiekstra 333636c81a Merged in feat/BOOK-61-refactor-hotel-page-css-variables (pull request #3014)
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
2025-10-29 09:15:03 +00:00

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>
</>
)
}