'use client' import { MouseEventHandler, forwardRef, useEffect, useState } from 'react' import { Alert_Shadcn_, Button, Dialog, DialogContent, DialogSection, DialogSectionSeparator, DialogTitle, cn, } from 'ui' import { Admonition } from './../admonition' import { DialogDescription, DialogHeader } from 'ui/src/components/shadcn/ui/dialog' export interface ConfirmationModalProps { loading?: boolean visible: boolean title: string | React.ReactNode description?: string | React.ReactNode size?: React.ComponentProps['size'] confirmLabel?: string confirmLabelLoading?: string cancelLabel?: string onConfirm: () => void onCancel: () => void disabled?: boolean variant?: React.ComponentProps['variant'] alert?: { base?: React.ComponentProps title?: string description?: string | React.ReactNode } } const ConfirmationModal = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & ConfirmationModalProps >( ( { title, description, size = 'small', visible, onCancel, onConfirm, loading: loading_ = false, cancelLabel = 'Cancel', confirmLabel = 'Submit', confirmLabelLoading, alert = undefined, children, variant = 'default', disabled, ...props }, ref ) => { useEffect(() => { if (visible) { setLoading(false) } }, [visible]) const [loading, setLoading] = useState(false) const onSubmit: MouseEventHandler = (e) => { e.preventDefault() e.stopPropagation() setLoading(true) onConfirm() } return ( { if (visible) { onCancel() } }} > {title} {description && {description}} {alert && ( )} {children && ( <> {children} )}
) } ) ConfirmationModal.displayName = 'ConfirmationModal' export default ConfirmationModal