ConfirmModal.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use client";
  2. import { AnimatePresence , motion } from "framer-motion";
  3. export interface ConfirmModalProps {
  4. isShow: boolean;
  5. title: string;
  6. content: string;
  7. okHandler?: () => void;
  8. cancelHandler?: () => void;
  9. noOk?: boolean;
  10. noCancel?: boolean;
  11. }
  12. export function ConfirmModal({
  13. isShow,
  14. title,
  15. content,
  16. okHandler,
  17. cancelHandler,
  18. noOk,
  19. noCancel,
  20. }: ConfirmModalProps) {
  21. const close = (result: boolean) => {
  22. if(result) {
  23. okHandler && okHandler();
  24. } else {
  25. cancelHandler && cancelHandler();
  26. }
  27. };
  28. return (
  29. <AnimatePresence >
  30. {isShow &&
  31. <motion.div
  32. layout
  33. initial={{ opacity: 0, }}
  34. animate={{ opacity: 1 }}
  35. exit={{ opacity: 0 }}
  36. className="fixed z-1000 flex justify-center items-center bg-black/50 inset-0"
  37. onClick={(e) => e.stopPropagation()}
  38. >
  39. {/* <div className="fixed z-1000 flex justify-center items-center bg-black/40 inset-0"> */}
  40. <div className="w-4/5 p-4 bg-white rounded-lg">
  41. <h3 className="text-center text-ly-18 font-bold mb-6">{title}</h3>
  42. <p className="text-ly-14 font-medium">{content}</p>
  43. <div className="w-full flex justify-end gap-3 mt-6">
  44. {!noOk &&
  45. <button className="w-20 h-8 flex justify-center items-center rounded-xs bg-ly-green text-ly-12 font-medium text-white"
  46. onClick={() => close(true)}
  47. >OK</button>
  48. }
  49. {!noCancel &&
  50. <button className="w-20 h-8 flex justify-center items-center rounded-xs bg-ly-gray text-ly-12 font-medium"
  51. onClick={() => close(false)}
  52. >Cancel</button>}
  53. </div>
  54. </div>
  55. {/* </div> */}
  56. </motion.div>
  57. }
  58. </AnimatePresence>
  59. );
  60. }