UNPKG

@cgi-learning-hub/ui

Version:

@cgi-learning-hub/ui is an open-source React component library that implements UI for HUB's features

86 lines (85 loc) 3.11 kB
import * as u from "react"; import * as E from "react-dom"; import { P as l } from "./index-B9vkf41S.js"; import { u as P } from "./useForkRef-u29GSuCu.js"; import { g as y } from "./elementAcceptingRef-CZLfau9O.js"; import { u as c } from "./useEventCallback-Y2KwRxBw.js"; function a(e, t) { typeof e == "function" ? e(t) : e && (e.current = t); } function N(e, t, o, n, i) { if (process.env.NODE_ENV === "production") return null; const r = e[t], s = i || t; return r == null ? null : r && r.nodeType !== 1 ? new Error(`Invalid ${n} \`${s}\` supplied to \`${o}\`. Expected an HTMLElement.`) : null; } const h = "exact-prop: ​"; function O(e) { return process.env.NODE_ENV === "production" ? e : { ...e, [h]: (t) => { const o = Object.keys(t).filter((n) => !e.hasOwnProperty(n)); return o.length > 0 ? new Error(`The following props are not supported: ${o.map((n) => `\`${n}\``).join(", ")}. Please remove them.`) : null; } }; } function T(e) { return typeof e == "function" ? e() : e; } const p = /* @__PURE__ */ u.forwardRef(function(t, o) { const { children: n, container: i, disablePortal: r = !1 } = t, [s, f] = u.useState(null), m = P(/* @__PURE__ */ u.isValidElement(n) ? y(n) : null, o); if (c(() => { r || f(T(i) || document.body); }, [i, r]), c(() => { if (s && !r) return a(o, s), () => { a(o, null); }; }, [o, s, r]), r) { if (/* @__PURE__ */ u.isValidElement(n)) { const d = { ref: m }; return /* @__PURE__ */ u.cloneElement(n, d); } return n; } return s && /* @__PURE__ */ E.createPortal(n, s); }); process.env.NODE_ENV !== "production" && (p.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * The children to render into the `container`. */ children: l.node, /** * An HTML element or function that returns one. * The `container` will have the portal children appended to it. * * You can also provide a callback, which is called in a React layout effect. * This lets you set the container from a ref, and also makes server-side rendering possible. * * By default, it uses the body of the top-level document object, * so it's simply `document.body` most of the time. */ container: l.oneOfType([N, l.func]), /** * The `children` will be under the DOM hierarchy of the parent component. * @default false */ disablePortal: l.bool }); process.env.NODE_ENV !== "production" && (p.propTypes = O(p.propTypes)); export { N as H, p as P, O as e, a as s };