@zag-js/preact
Version:
The preact wrapper for zag
45 lines (43 loc) • 1.84 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/portal.tsx
var portal_exports = {};
__export(portal_exports, {
Portal: () => Portal
});
module.exports = __toCommonJS(portal_exports);
var import_compat = require("preact/compat");
var Portal = (props) => {
const { children, container, disabled, getRootNode } = props;
const [, forceUpdate] = (0, import_compat.useReducer)((c) => c + 1, 0);
(0, import_compat.useLayoutEffect)(() => {
forceUpdate({});
}, []);
const isServer = typeof window === "undefined";
if (isServer || disabled) return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
const doc = getRootNode?.().ownerDocument ?? document;
const mountNode = container?.current ?? doc.body;
return /* @__PURE__ */ React.createElement(React.Fragment, null, import_compat.Children.map(children, (child) => {
return (0, import_compat.createPortal)(/* @__PURE__ */ React.createElement(React.Fragment, null, child), mountNode);
}));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Portal
});