88 lines
3.2 KiB
TypeScript
88 lines
3.2 KiB
TypeScript
// src/components/ConfirmationModal.tsx
|
|
import React from 'react';
|
|
import { XMarkIcon } from './icons/XMarkIcon';
|
|
import { ExclamationTriangleIcon } from './icons/ExclamationTriangleIcon';
|
|
|
|
interface ConfirmationModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
onConfirm: () => void;
|
|
title: string;
|
|
message: React.ReactNode;
|
|
confirmButtonText?: string;
|
|
cancelButtonText?: string;
|
|
confirmButtonClass?: string;
|
|
}
|
|
|
|
export const ConfirmationModal: React.FC<ConfirmationModalProps> = ({
|
|
isOpen,
|
|
onClose,
|
|
onConfirm,
|
|
title,
|
|
message,
|
|
confirmButtonText = 'Confirm',
|
|
cancelButtonText = 'Cancel',
|
|
confirmButtonClass = 'bg-red-600 hover:bg-red-700 focus:ring-red-500',
|
|
}) => {
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<div
|
|
className="fixed inset-0 bg-black bg-opacity-60 z-50 flex justify-center items-center p-4"
|
|
onClick={onClose}
|
|
aria-modal="true"
|
|
role="dialog"
|
|
>
|
|
<div
|
|
className="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md relative"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<button
|
|
onClick={onClose}
|
|
className="absolute top-3 right-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors"
|
|
aria-label="Close confirmation modal"
|
|
>
|
|
<XMarkIcon className="w-6 h-6" />
|
|
</button>
|
|
<div className="p-6">
|
|
<div className="sm:flex sm:items-start">
|
|
<div className="mx-auto shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 dark:bg-red-900/30 sm:mx-0 sm:h-10 sm:w-10">
|
|
<ExclamationTriangleIcon
|
|
className="h-6 w-6 text-red-600 dark:text-red-400"
|
|
aria-hidden="true"
|
|
/>
|
|
</div>
|
|
<div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
|
|
<h3
|
|
className="text-lg leading-6 font-medium text-gray-900 dark:text-white"
|
|
id="modal-title"
|
|
>
|
|
{title}
|
|
</h3>
|
|
<div className="mt-2">
|
|
<div className="text-sm text-gray-500 dark:text-gray-400">{message}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="bg-gray-50 dark:bg-gray-800/50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse rounded-b-lg">
|
|
<button
|
|
type="button"
|
|
className={`w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm ${confirmButtonClass}`}
|
|
onClick={onConfirm}
|
|
>
|
|
{confirmButtonText}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 dark:border-gray-500 shadow-sm px-4 py-2 bg-white dark:bg-gray-700 text-base font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:w-auto sm:text-sm"
|
|
onClick={onClose}
|
|
>
|
|
{cancelButtonText}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|