ConfirmModal.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use client';
  2. import { X } from 'lucide-react';
  3. interface ConfirmModalProps {
  4. isOpen: boolean;
  5. title: string;
  6. message: string;
  7. onConfirm: () => void;
  8. onCancel: () => void;
  9. }
  10. export default function ConfirmModal({ isOpen, onCancel, onConfirm, message, title }: ConfirmModalProps) {
  11. if (!isOpen) return null;
  12. return (
  13. <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4">
  14. <div className="bg-white rounded-xl shadow-2xl w-full max-w-md flex flex-col animate-in zoom-in duration-200">
  15. {/* Header */}
  16. <div className="px-6 py-4 border-b flex justify-between items-center bg-gray-50">
  17. <h3 className="font-bold text-gray-900 text-lg">{title}</h3>
  18. <button onClick={onCancel} className="text-gray-400 hover:text-gray-600 p-1 rounded-full hover:bg-gray-100 transition">
  19. <X size={24} />
  20. </button>
  21. </div>
  22. {/* Body */}
  23. <div className="p-6 flex-1 flex flex-col justify-center">
  24. <p className="text-sm text-gray-600 mb-6 text-center">{message}</p>
  25. </div>
  26. {/* Footer Buttons */}
  27. <div className="px-6 py-4 border-t bg-gray-50 flex justify-end gap-3">
  28. <button
  29. onClick={onCancel}
  30. className="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 text-sm font-medium transition"
  31. >
  32. 取消
  33. </button>
  34. <button
  35. onClick={() => {
  36. onConfirm(); // 调用确认回调
  37. onCancel(); // 关闭弹窗
  38. }}
  39. className="px-6 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm font-bold transition"
  40. >
  41. 确认
  42. </button>
  43. </div>
  44. </div>
  45. </div>
  46. );
  47. }