import classNames from 'classnames'; import { motion } from 'framer-motion'; import type { ReactNode } from 'react'; import { useMemo } from 'react'; import { useKey } from 'react-use'; import { Overlay } from '../Overlay'; import { Heading } from './Heading'; import { IconButton } from './IconButton'; export interface DialogProps { children: ReactNode; open: boolean; onClose: () => void; title?: ReactNode; description?: ReactNode; className?: string; size?: 'sm' | 'md' | 'lg' | 'full' | 'dynamic'; hideX?: boolean; noPadding?: boolean; noScroll?: boolean; vAlign?: 'top' | 'center'; } export function Dialog({ children, className, size = 'full', open, onClose, title, description, hideX, noPadding, noScroll, vAlign = 'center', }: DialogProps) { const titleId = useMemo(() => Math.random().toString(36).slice(2), []); const descriptionId = useMemo( () => (description ? Math.random().toString(36).slice(2) : undefined), [description], ); useKey( 'Escape', () => { if (!open) return; onClose(); }, {}, [open], ); return (
{title ? ( {title} ) : ( )} {description ? (

{description}

) : ( )}
{children}
{/*Put close at the end so that it's the last thing to be tabbed to*/} {!hideX && (
)}
); }