import * as React from "react"; import * as ReactDOM from "react-dom"; import { classList, ContainerProps } from "../util"; import { Button } from "./Button"; import { FocusTrap } from "./FocusTrap"; import { Link } from "./Link"; export interface ModalAction { label: string; className?: string; disabled?: boolean; icon?: string; xicon?: boolean; leftIcon?: string; onClick: () => void; url?: string; // TODO: It would be nice to make fullscreen modals their own thing and deprecate this prop. right // now it's required to render the back arrow fullscreen?: boolean; } export interface ModalProps extends ContainerProps { title: string; leftIcon?: string; helpUrl?: string ariaDescribedBy?: string; actions?: ModalAction[]; onClose?: () => void; fullscreen?: boolean; parentElement?: Element; hideDismissButton?: boolean; } export const Modal = (props: ModalProps) => { const { children, id, className, ariaLabel, ariaHidden, ariaDescribedBy, role, title, leftIcon, helpUrl, actions, onClose, parentElement, fullscreen, hideDismissButton, } = props; const closeClickHandler = (e?: React.MouseEvent) => { if (onClose) onClose(); } const classes = classList( "common-modal-container", fullscreen && "fullscreen", className ); return ReactDOM.createPortal(
{fullscreen && !hideDismissButton &&
} {fullscreen && helpUrl &&
} {!fullscreen && !hideDismissButton &&
}
{children}
{actions?.length &&
{ actions.map((action, index) =>
}
, parentElement || document.getElementById("root") || document.body) }