import { useEffect } from 'react'; import * as DialogPrimitives from '@radix-ui/react-dialog'; import classNames from 'classnames'; import { getIntentBorder } from '../../utils/intent'; import { VegaIcon, VegaIconNames } from '../icon'; import type { ReactNode } from 'react'; import type { Intent } from '../../utils/intent'; interface DialogProps { children: ReactNode; open: boolean; onChange?: (isOpen: boolean) => void; onCloseAutoFocus?: (e: Event) => void; onInteractOutside?: (e: Event) => void; title?: string | ReactNode; icon?: ReactNode; intent?: Intent; size?: 'small' | 'medium'; dataTestId?: string; } export function Dialog({ children, open, onChange, onCloseAutoFocus, onInteractOutside, title, icon, intent, size = 'small', dataTestId = 'dialog-content', }: DialogProps) { const contentClasses = classNames( 'fixed top-0 left-0 z-20 flex justify-center items-start overflow-auto', 'w-full h-full' ); const wrapperClasses = classNames( // Positions the modal in the center of screen 'z-20 relative rounded top-[10vh]', // Dimensions 'max-w-[90vw] p-4 md:p-8', // Need to apply background and text colors again as content is rendered in a portal 'dark:bg-black bg-white dark:text-white', getIntentBorder(intent), { 'w-[620px]': size === 'small', 'w-[720px] lg:w-[940px]': size === 'medium', } ); useEffect(() => { if (open) { document.body.classList.add('overflow-hidden'); } else { document.body.classList.remove('overflow-hidden'); } }, [open]); return ( onChange?.(x)}>
{onChange && ( )}
{icon &&
{icon}
}
{title && (

{title}

)}
{children}
); }