1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 23:58:06 +01:00
metamask-extension/ui/components/component-library/modal/modal.tsx

53 lines
1.1 KiB
TypeScript

import React, { forwardRef, Ref } from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import { ModalProps } from './modal.types';
import { ModalContext } from './modal.context';
export const Modal = forwardRef(
(
{
className = '',
isOpen,
onClose,
children,
isClosedOnOutsideClick = true,
isClosedOnEscapeKey = true,
autoFocus = true,
initialFocusRef,
finalFocusRef,
restoreFocus,
...props
}: ModalProps,
ref: Ref<HTMLDivElement>,
) => {
const context = {
isOpen,
onClose,
isClosedOnOutsideClick,
isClosedOnEscapeKey,
autoFocus,
initialFocusRef,
finalFocusRef,
restoreFocus,
};
return isOpen
? ReactDOM.createPortal(
<ModalContext.Provider value={context}>
<div
className={classnames('mm-modal', className)}
ref={ref}
{...props}
>
{children}
</div>
</ModalContext.Provider>,
document.body,
)
: null;
},
);
export default Modal;