import React, { ReactElement, useLayoutEffect, useState } from 'react' import { createPortal } from 'react-dom' import { Button } from '../Button/Button' import '../../styles/global.scss' import './ConfirmModal.scss' interface ConfirmModalProps { title?: React.ReactNode message?: React.ReactNode confirmLabel?: string cancelLabel?: string onConfirm?: () => void | Promise onCancel?: () => void showFooter?: boolean isProgress?: boolean spinnerMessage?: React.ReactNode showMinimize?: boolean onMinimize?: () => void background?: boolean } export function ConfirmModal({ title = 'Are you sure?', message, confirmLabel = 'Confirm', cancelLabel = 'Cancel', onConfirm, onCancel, showFooter = true, isProgress = false, spinnerMessage, showMinimize = true, onMinimize, background = true, }: ConfirmModalProps): ReactElement { const [modalRoot, setModalRoot] = useState(() => document.querySelector('.fm-main') || document.body) useLayoutEffect(() => { setModalRoot(document.querySelector('.fm-main') || document.body) }, []) return createPortal(
{title}
{isProgress ? (
{spinnerMessage || 'Working…'}
{showMinimize &&
) : (
{message}
)}
{showFooter && (onCancel || onConfirm) && (
{onCancel &&
)}
, modalRoot, ) }