'use client'; import React from 'react'; import * as Dialog from '@radix-ui/react-dialog'; import { styled, keyframes } from '@stitches/react'; import { blackA, } from '@radix-ui/colors'; import { AlertTriangle, Info } from 'lucide-react'; type ModalParams = { confirmationMessage: string; confirmationButtonText: string; dialogTitle: string; functionToExecute: any; dialogTrigger?: React.ReactNode; status?: "warning" | "info"; }; const ConfirmationModal = (params: ModalParams) => { const [isDialogOpen, setIsDialogOpen] = React.useState(false); const warningColors = 'bg-red-100 text-red-600' const infoColors = 'bg-blue-100 text-blue-600' const warningButtonColors = 'text-white bg-red-500 hover:bg-red-600' const infoButtonColors = 'text-white bg-blue-500 hover:bg-blue-600' const onOpenChange = React.useCallback( (open: any) => { setIsDialogOpen(open); }, [setIsDialogOpen] ); return ( {params.dialogTrigger ? ( {params.dialogTrigger} ) : null}
{params.status === 'warning' ? : }
{params.dialogTitle}
{params.confirmationMessage}
{ params.functionToExecute(); setIsDialogOpen(false) }}> {params.confirmationButtonText}
) }; const overlayShow = keyframes({ '0%': { opacity: 0 }, '100%': { opacity: 1 }, }); const overlayClose = keyframes({ '0%': { opacity: 1 }, '100%': { opacity: 0 }, }); const contentShow = keyframes({ '0%': { opacity: 0, transform: 'translate(-50%, -50%) scale(.96)' }, '100%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' }, }); const contentClose = keyframes({ '0%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' }, '100%': { opacity: 0, transform: 'translate(-50%, -52%) scale(.96)' }, }); const DialogOverlay = styled(Dialog.Overlay, { backgroundColor: blackA.blackA9, position: 'fixed', zIndex: 500, inset: 0, animation: `${overlayShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`, '&[data-state="closed"]': { animation: `${overlayClose} 150ms cubic-bezier(0.16, 1, 0.3, 1)`, }, }); const DialogContent = styled(Dialog.Content, { backgroundColor: 'white', borderRadius: 18, zIndex: 501, boxShadow: 'hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px', position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 'auto', minWidth: '500px', overflow: 'hidden', height: 'auto', maxHeight: '85vh', maxWidth: '600px', padding: 11, animation: `${contentShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`, '&:focus': { outline: 'none' }, '&[data-state="closed"]': { animation: `${contentClose} 150ms cubic-bezier(0.16, 1, 0.3, 1)`, }, transition: "max-height 0.3s ease-out", }); export default ConfirmationModal;