import classNames from "classnames"; import * as m from "motion/react-m"; import type { ReactNode } from "react"; import { useMemo } from "react"; import { Overlay } from "../Overlay"; import { Heading } from "./Heading"; import { IconButton } from "./IconButton"; import type { DialogSize } from "@yaakapp-internal/plugins"; export interface DialogProps { children: ReactNode; open: boolean; onClose?: () => void; disableBackdropClose?: boolean; title?: ReactNode; description?: ReactNode; className?: string; size?: DialogSize; hideX?: boolean; noPadding?: boolean; noScroll?: boolean; vAlign?: "top" | "center"; } export function Dialog({ children, className, size = "full", open, onClose, disableBackdropClose, 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], ); return (
{ // NOTE: We handle Escape on the element itself so that it doesn't close multiple // dialogs and can be intercepted by children if needed. if (e.key === "Escape") { onClose?.(); e.stopPropagation(); e.preventDefault(); } }} > {title ? ( {title} ) : ( )} {description ? (
{description}
) : ( )}
{children}
{/*Put close at the end so that it's the last thing to be tabbed to*/} {!hideX && (
)}
); }