UNPKG

@mankindui/core

Version:

- a react component library - you can see how @mankindui/core can be used via examples: [usage examples](https://github.com/clarklindev/mankindui-test)

34 lines (33 loc) 1.3 kB
import { j as r } from "../../_virtual/jsx-runtime.js"; import { createContext as a, useState as p, useContext as u, useRef as d, useEffect as m } from "react"; const i = a(void 0), v = ({ children: t }) => { const [e, o] = p(!1), s = () => { o((n) => !n); }; return /* @__PURE__ */ r.jsx(i.Provider, { value: { isVisible: e, togglePopover: s }, children: /* @__PURE__ */ r.jsx("div", { className: "popover-container", children: t }) }); }; v.Trigger = ({ children: t }) => { const e = u(i); if (!e) throw new Error("Popover.Trigger must be used within a Popover"); const { togglePopover: o } = e; return /* @__PURE__ */ r.jsx("div", { onClick: o, children: t }); }; v.Content = ({ children: t }) => { const e = u(i), o = d(null); if (!e) throw new Error("Popover.Content must be used within a Popover"); const { isVisible: s, togglePopover: n } = e; return m(() => { const c = (l) => { o.current && !o.current.contains(l.target) && n(); }; return document.addEventListener("mousedown", c), () => { document.removeEventListener("mousedown", c); }; }, [n]), s ? /* @__PURE__ */ r.jsx("div", { className: "popover-content absolute z-1000", ref: o, children: t }) : null; }; export { v as Popover }; //# sourceMappingURL=index.js.map