UNPKG

@clubmed/trident-ui

Version:

Shared ClubMed React UI components

32 lines (31 loc) 962 B
import { jsx as l } from "react/jsx-runtime"; import { useState as i, useEffect as f, Children as d } from "react"; import { createPortal as m } from "react-dom"; const p = (t) => { if (typeof document > "u") return console.warn("createDivElementWithId() can not be run outside of a browser"), null; const e = document.createElement("div"); return e.id = t, e.classList.add("relative", "isolate", "z-1"), document.body.append(e), e; }; function C({ children: t, target: e = "portal", disabled: n = !1, key: u }) { const [a, s] = i(!1), [o, c] = i(null); return f(() => { if (s(!0), o === null) { const r = document.getElementById(e) || p(e); r && c(r); } }, [e]), a ? n ? t : d.count(t) && o ? m(t, o, u) : null : null; } function P(t, e) { return (n) => /* @__PURE__ */ l(C, { target: t, children: /* @__PURE__ */ l(e, { ...n }) }); } export { C as Portal, P as withPortal }; //# sourceMappingURL=Portal.js.map