UNPKG

@flexilla/collapsible

Version:

A utility for creating collapsible sections in web applications, conserving space and improving user experience.

47 lines (46 loc) 1.22 kB
const r = ({ element: t, callback: e, type: s, keysCheck: n }) => { const c = getComputedStyle(t), a = c.transition; if (a !== "none" && a !== "" && !n.includes(a)) { const o = "transitionend", l = () => { t.removeEventListener(o, l), e(); }; t.addEventListener(o, l, { once: !0 }); } else e(); }, h = ({ element: t, callback: e }) => { r({ element: t, callback: e, type: "transition", keysCheck: ["all 0s ease 0s", "all"] }); }, i = (t, e) => { t.setAttribute("aria-hidden", e === "open" ? "false" : "true"), t.setAttribute("data-state", e); }, p = (t, e = "close", s = "0px") => { t.style.height = e === "open" ? "auto" : s, i(t, e); }, u = (t) => { if (t.getAttribute("data-state") === "open") return; i(t, "open"); const e = t.scrollHeight; t.style.height = `${e}px`, h({ element: t, callback: () => { t.getAttribute("data-state") === "open" && (t.style.height = "auto"); } }); }, g = (t, e = "0px") => { t.getAttribute("data-state") !== "close" && (t.style.height = `${t.scrollHeight}px`, t.offsetHeight, t.style.height = e, i(t, "close")); }; export { g as collapseElement, u as expandElement, p as initCollapsible };