ayongui
Version:
34 lines (33 loc) • 1.15 kB
JavaScript
import f from "react";
import g from "react-dom";
let l = "notification-portal";
const y = async (e) => {
const i = document.getElementById(l);
if (i)
i.setAttribute("make", e);
else {
const t = document.createElement("div");
t.id = l, t.setAttribute("make", e), t.style.position = "absolute", t.style.zIndex = 1e3, document.body.appendChild(t);
}
}, a = [], x = (e) => {
const { YAxisPlacement: i = "top" } = e, t = e.placement || "message", d = e.baseHieght || 70;
y(t);
const n = document.getElementById(l);
n && window.requestIdleCallback(() => {
const o = n.cloneNode(!0);
n.setAttribute("make", ""), n.appendChild(o);
const s = () => {
n.removeChild(o);
const c = a.findIndex((u) => u.container === o);
c !== -1 && a.splice(c, 1), e.onClose && typeof e.onClose == "function" && e.onClose();
}, m = a.filter((c) => c.container.getAttribute("make") === t).length * d, r = f.createElement(e.element, {
onAyongClose: s,
...e,
style: { [i]: m + "px", ...e.style }
});
g.render(r, o), a.push({ container: o, onAyongClose: s });
});
};
export {
x as default
};