index.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use client";
  2. import { Mask } from "antd-mobile";
  3. import { forwardRef, PropsWithChildren, ReactNode, useImperativeHandle, useState } from "react";
  4. type Props = {
  5. title?: string | ReactNode;
  6. onBeforeClose?: () => void;
  7. };
  8. export type ModalProps = {
  9. onClose: () => void;
  10. onOpen: () => void;
  11. };
  12. const TipsModal = forwardRef<ModalProps, PropsWithChildren<Props>>(function TipsModal(props, ref) {
  13. const { children, title, onBeforeClose } = props;
  14. const [visible, setVisible] = useState(false);
  15. useImperativeHandle(ref, () => {
  16. return {
  17. onClose: () => setVisible(false),
  18. onOpen: () => setVisible(true),
  19. };
  20. });
  21. return (
  22. <Mask visible={visible} onMaskClick={() => setVisible(false)}>
  23. <div className="flex h-[100dvh] h-[100vh] items-center justify-center">
  24. <div className="mask-box w-[3.4rem] rounded-[10px] bg-[#fff] p-[0.1389rem] text-[#000]">
  25. <div className={"mb-[10px] flex"}>
  26. <div className="flex-1 text-center text-[0.18rem] font-bold text-[#009d81]">
  27. {title}
  28. </div>
  29. <span
  30. className="iconfont icon-guanbi"
  31. onClick={() => {
  32. onBeforeClose && onBeforeClose();
  33. setVisible(false);
  34. }}
  35. ></span>
  36. </div>
  37. <div className="popUpMain">{children}</div>
  38. </div>
  39. </div>
  40. </Mask>
  41. );
  42. });
  43. export default TipsModal;