host.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use client";
  2. import { motion } from "framer-motion";
  3. import { confirmStore } from "./store";
  4. import { useConfirmQueue } from "./useConfirm";
  5. export function ConfirmHost() {
  6. const {queue} = useConfirmQueue();
  7. const current = queue[0];
  8. if (!current) return null;
  9. const close = (result: boolean) => {
  10. current.resolve(result);
  11. confirmStore.setState({
  12. queue: queue.slice(1),
  13. });
  14. };
  15. return (
  16. <motion.div
  17. layout
  18. initial={{ opacity: 0, }}
  19. animate={{ opacity: 1 }}
  20. exit={{ opacity: 0 }}
  21. className="fixed z-1000 flex justify-center items-center bg-black/50 inset-0"
  22. onClick={(e) => e.stopPropagation()}
  23. >
  24. {/* <div className="fixed z-1000 flex justify-center items-center bg-black/40 inset-0"> */}
  25. <div className="w-4/5 p-4 bg-white rounded-lg">
  26. <h3 className="text-center text-ly-18 font-bold mb-6">{current.title}</h3>
  27. <p className="text-ly-14 font-medium">{current.content}</p>
  28. <div className="w-full flex justify-end gap-3 mt-6">
  29. {!current.noOk && <button className="w-20 h-8 flex justify-center items-center rounded-xs bg-ly-green text-ly-12 font-medium text-white" onClick={() => close(true)}>OK</button>}
  30. {!current.noCancel && <button className="w-20 h-8 flex justify-center items-center rounded-xs bg-ly-gray text-ly-12 font-medium" onClick={() => close(false)}>Cancel</button>}
  31. </div>
  32. </div>
  33. {/* </div> */}
  34. </motion.div>
  35. );
  36. }