import classNames from 'classnames' import { Dialog as ReakitDialog, DialogDisclosure, DialogBackdrop, DialogInitialState, DialogStateReturn, useDialogState as default_useDialogState, } from 'reakit' import CancelIcon from '~/icons/compiled/Cancel' import RenderMarkdown, { ALLOWED_INLINE_ELEMENTS } from '../RenderMarkdown' export type IVDialogProps = { dialog: DialogStateReturn children: React.ReactNode canClose?: boolean widthClassName?: string backdropClassName?: string renderChildrenWhileHidden?: boolean } & ( | { // One of these props is required for an accessibility title. // Use `title` to show as the modal header. Use `aria-label` to hide the title. title: string 'aria-label'?: string } | { title?: string 'aria-label': string } ) export function useDialogState(state?: DialogInitialState) { return default_useDialogState({ ...state, animated: 200, }) } // Wraps buttons that open a dialog. Reakit will complain if you don't use these, because // it can't identify the element to return focus to when you close the dialog. export function IVDialogDisclosure({ children, ...props }: DialogStateReturn & { children: React.ReactNode }) { return ( {children} ) } export function IVDialogActions(props: { children: React.ReactNode className?: string }) { const { className = 'mt-6' } = props return (
{props.children}
) } export default function IVDialog(props: IVDialogProps) { const { title, children, dialog, widthClassName = 'w-[400px]', canClose = true, 'aria-label': ariaLabel, renderChildrenWhileHidden = false, backdropClassName = 'fixed z-30 inset-0 overflow-y-auto transition-all transform duration-200 outline-none dialog-backdrop--shade', } = props return ( <>
{canClose && (
)}
{props.title && (

{props.title}

)}
{(renderChildrenWhileHidden || dialog.animating || dialog.visible) && ( <> {typeof children === 'string' ? ( ) : ( children )} )}
) }