| import React from 'react'; |
| import { CloseIcon } from './icons'; |
|
|
| interface ConfirmModalProps { |
| isOpen: boolean; |
| title: string; |
| message: string | React.ReactNode; |
| confirmText?: string; |
| cancelText?: string; |
| onConfirm: () => void; |
| onCancel: () => void; |
| isConfirmDestructive?: boolean; |
| } |
|
|
| const ConfirmModal: React.FC<ConfirmModalProps> = ({ |
| isOpen, |
| title, |
| message, |
| confirmText = 'Confirm', |
| cancelText = 'Cancel', |
| onConfirm, |
| onCancel, |
| isConfirmDestructive = false, |
| }) => { |
| if (!isOpen) return null; |
|
|
| return ( |
| <div |
| className="fixed inset-0 bg-black bg-opacity-70 backdrop-blur-sm flex justify-center items-center z-[1100] p-4" |
| aria-modal="true" |
| role="dialog" |
| aria-labelledby="confirm-modal-title" |
| > |
| <div className="bg-white rounded-lg shadow-2xl p-6 w-full max-w-md transform transition-all"> |
| <div className="flex justify-between items-center mb-4"> |
| <h2 id="confirm-modal-title" className="text-lg font-semibold text-slate-800"> |
| {title} |
| </h2> |
| <button |
| onClick={onCancel} |
| className="text-slate-400 hover:text-slate-600 transition-colors" |
| aria-label="Close confirmation dialog" |
| > |
| <CloseIcon className="w-5 h-5" /> |
| </button> |
| </div> |
| |
| <div className="mb-6 text-sm text-slate-600"> |
| {typeof message === 'string' ? <p>{message}</p> : message} |
| </div> |
| |
| <div className="flex flex-col sm:flex-row justify-end gap-3"> |
| <button |
| onClick={onCancel} |
| className="px-4 py-2 bg-slate-200 text-slate-700 rounded-md hover:bg-slate-300 transition-colors disabled:opacity-50 disabled:cursor-not-allowed text-sm font-medium w-full sm:w-auto" |
| > |
| {cancelText} |
| </button> |
| <button |
| onClick={onConfirm} |
| className={`px-4 py-2 text-white rounded-md transition-colors disabled:opacity-50 disabled:cursor-not-allowed text-sm font-medium w-full sm:w-auto |
| ${isConfirmDestructive ? 'bg-red-600 hover:bg-red-700 focus:ring-red-500' |
| : 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500'} |
| focus:ring-2 focus:ring-offset-2`} |
| > |
| {confirmText} |
| </button> |
| </div> |
| </div> |
| </div> |
| ); |
| }; |
|
|
| export default ConfirmModal; |
|
|