.
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
type PortalProps = {
|
||||
children: React.ReactNode;
|
||||
type: string;
|
||||
};
|
||||
export declare const Portal: ({ children, type }: PortalProps) => import("react").ReactPortal | null;
|
||||
export {};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "Portal", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return Portal;
|
||||
}
|
||||
});
|
||||
const _react = require("react");
|
||||
const _reactdom = require("react-dom");
|
||||
const Portal = ({ children, type })=>{
|
||||
const [portalNode, setPortalNode] = (0, _react.useState)(null);
|
||||
(0, _react.useEffect)(()=>{
|
||||
const element = document.createElement(type);
|
||||
document.body.appendChild(element);
|
||||
setPortalNode(element);
|
||||
return ()=>{
|
||||
document.body.removeChild(element);
|
||||
};
|
||||
}, [
|
||||
type
|
||||
]);
|
||||
return portalNode ? /*#__PURE__*/ (0, _reactdom.createPortal)(children, portalNode) : null;
|
||||
};
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/client/portal/index.tsx"],"sourcesContent":["import { useEffect, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\ntype PortalProps = {\n children: React.ReactNode\n type: string\n}\n\nexport const Portal = ({ children, type }: PortalProps) => {\n const [portalNode, setPortalNode] = useState<HTMLElement | null>(null)\n\n useEffect(() => {\n const element = document.createElement(type)\n document.body.appendChild(element)\n setPortalNode(element)\n return () => {\n document.body.removeChild(element)\n }\n }, [type])\n\n return portalNode ? createPortal(children, portalNode) : null\n}\n"],"names":["Portal","children","type","portalNode","setPortalNode","useState","useEffect","element","document","createElement","body","appendChild","removeChild","createPortal"],"mappings":";;;;+BAQaA;;;eAAAA;;;uBARuB;0BACP;AAOtB,MAAMA,SAAS,CAAC,EAAEC,QAAQ,EAAEC,IAAI,EAAe;IACpD,MAAM,CAACC,YAAYC,cAAc,GAAGC,IAAAA,eAAQ,EAAqB;IAEjEC,IAAAA,gBAAS,EAAC;QACR,MAAMC,UAAUC,SAASC,aAAa,CAACP;QACvCM,SAASE,IAAI,CAACC,WAAW,CAACJ;QAC1BH,cAAcG;QACd,OAAO;YACLC,SAASE,IAAI,CAACE,WAAW,CAACL;QAC5B;IACF,GAAG;QAACL;KAAK;IAET,OAAOC,2BAAaU,IAAAA,sBAAY,EAACZ,UAAUE,cAAc;AAC3D","ignoreList":[0]}
|
||||
Reference in New Issue
Block a user