import { FC, ReactNode } from 'react' import { proxy, useSnapshot } from 'valtio' import Button from '../Button' import Flex from '../Flex' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogTitle } from './primitive' export interface AlertState { isOpen: boolean title?: string body?: ReactNode cancelText?: string confirmText?: string confirmPrefix?: ReactNode onConfirm?: () => any onCancel?: () => any } export const alertState = proxy({ isOpen: false }) const Alert: FC = () => { const { title = 'Are you sure?', isOpen, body, cancelText, confirmText = 'Ok', confirmPrefix, onCancel, onConfirm } = useSnapshot(alertState) return ( (alertState.isOpen = value)}> {title} {body} {(cancelText || onCancel) && ( )} ) } export default Alert