refactor: add typescript support to project

This commit is contained in:
HD
2022-06-21 15:08:35 +08:00
parent 88ec2b742a
commit bd799ebea8
259 changed files with 1042 additions and 458 deletions
+23
View File
@@ -0,0 +1,23 @@
import { useEffect, useState } from "react";
import { createPortal } from "react-dom";
export default function Modal({ id = "root-modal", mask = true, children }) {
const [wrapper, setWrapper] = useState(null);
// let eleRef = useRef(null);
useEffect(() => {
const modalRoot = document.getElementById(id);
if (mask) {
modalRoot.classList.add("mask");
}
const wrapper = document.createElement("div");
wrapper.classList.add("wrapper");
modalRoot.appendChild(wrapper);
setWrapper(wrapper);
return () => {
modalRoot.removeChild(wrapper);
};
}, [id, mask]);
if (!wrapper) return null;
console.log("create portal");
return createPortal(children, wrapper);
}