@alfalab/core-components-portal
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -0,3 +1,4 @@ | ||
/// <reference types="react" /> | ||
import React from 'react'; | ||
export declare type PortalProps = { | ||
type PortalProps = { | ||
/** | ||
@@ -8,2 +9,3 @@ * Функция, возвращающая контейнер, в который будут рендериться дочерние элементы | ||
}; | ||
export declare const Portal: React.FC<PortalProps>; | ||
declare const Portal: React.FC<PortalProps>; | ||
export { PortalProps, Portal }; |
@@ -1,13 +0,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
var react_dom_1 = require("react-dom"); | ||
var portalContainer_1 = require("./portalContainer"); | ||
exports.Portal = function (_a) { | ||
var children = _a.children, _b = _a.getPortalContainer, getPortalContainer = _b === void 0 ? portalContainer_1.getDefaultPortalContainer : _b; | ||
var _c = react_1.useState(false), isMount = _c[0], setIsMount = _c[1]; | ||
react_1.useEffect(function () { | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var react = require('react'); | ||
var reactDom = require('react-dom'); | ||
var portalContainer = require('./portalContainer.js'); | ||
var Portal = function (_a) { | ||
var children = _a.children, _b = _a.getPortalContainer, getPortalContainer = _b === void 0 ? portalContainer.getDefaultPortalContainer : _b; | ||
var _c = react.useState(false), isMount = _c[0], setIsMount = _c[1]; | ||
react.useEffect(function () { | ||
setIsMount(true); | ||
}, []); | ||
return isMount ? react_dom_1.createPortal(children, getPortalContainer()) : null; | ||
return isMount ? reactDom.createPortal(children, getPortalContainer()) : null; | ||
}; | ||
exports.Portal = Portal; |
@@ -1,1 +0,1 @@ | ||
export * from './Component'; | ||
export * from "./Component"; |
@@ -1,6 +0,12 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./Component")); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
require('react'); | ||
require('react-dom'); | ||
require('./portalContainer.js'); | ||
var Component = require('./Component.js'); | ||
exports.Portal = Component.Portal; |
@@ -0,3 +1,4 @@ | ||
/// <reference types="react" /> | ||
import React from 'react'; | ||
export declare type PortalProps = { | ||
type PortalProps = { | ||
/** | ||
@@ -8,2 +9,3 @@ * Функция, возвращающая контейнер, в который будут рендериться дочерние элементы | ||
}; | ||
export declare const Portal: React.FC<PortalProps>; | ||
declare const Portal: React.FC<PortalProps>; | ||
export { PortalProps, Portal }; |
import { useState, useEffect } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
import { getDefaultPortalContainer } from './portalContainer'; | ||
export const Portal = ({ children, getPortalContainer = getDefaultPortalContainer, }) => { | ||
import { getDefaultPortalContainer } from './portalContainer.js'; | ||
const Portal = ({ children, getPortalContainer = getDefaultPortalContainer, }) => { | ||
const [isMount, setIsMount] = useState(false); | ||
@@ -11,1 +12,3 @@ useEffect(() => { | ||
}; | ||
export { Portal }; |
@@ -1,1 +0,1 @@ | ||
export * from './Component'; | ||
export * from "./Component"; |
@@ -1,1 +0,4 @@ | ||
export * from './Component'; | ||
import 'react'; | ||
import 'react-dom'; | ||
import './portalContainer.js'; | ||
export { Portal } from './Component.js'; |
@@ -1,2 +0,3 @@ | ||
export declare const PORTAL_CONTAINER_ATTRIBUTE = "alfa-portal-container"; | ||
export declare const getDefaultPortalContainer: () => Element; | ||
declare const PORTAL_CONTAINER_ATTRIBUTE = "alfa-portal-container"; | ||
declare const getDefaultPortalContainer: () => Element; | ||
export { PORTAL_CONTAINER_ATTRIBUTE, getDefaultPortalContainer }; |
@@ -1,2 +0,2 @@ | ||
export const PORTAL_CONTAINER_ATTRIBUTE = 'alfa-portal-container'; | ||
const PORTAL_CONTAINER_ATTRIBUTE = 'alfa-portal-container'; | ||
function createPortalContainer() { | ||
@@ -8,2 +8,4 @@ const portalContainer = document.createElement('div'); | ||
} | ||
export const getDefaultPortalContainer = () => document.querySelector(`[${PORTAL_CONTAINER_ATTRIBUTE}]`) || createPortalContainer(); | ||
const getDefaultPortalContainer = () => document.querySelector(`[${PORTAL_CONTAINER_ATTRIBUTE}]`) || createPortalContainer(); | ||
export { PORTAL_CONTAINER_ATTRIBUTE, getDefaultPortalContainer }; |
@@ -1,2 +0,3 @@ | ||
export declare const PORTAL_CONTAINER_ATTRIBUTE = "alfa-portal-container"; | ||
export declare const getDefaultPortalContainer: () => Element; | ||
declare const PORTAL_CONTAINER_ATTRIBUTE = "alfa-portal-container"; | ||
declare const getDefaultPortalContainer: () => Element; | ||
export { PORTAL_CONTAINER_ATTRIBUTE, getDefaultPortalContainer }; |
@@ -1,12 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PORTAL_CONTAINER_ATTRIBUTE = 'alfa-portal-container'; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var PORTAL_CONTAINER_ATTRIBUTE = 'alfa-portal-container'; | ||
function createPortalContainer() { | ||
var portalContainer = document.createElement('div'); | ||
portalContainer.setAttribute(exports.PORTAL_CONTAINER_ATTRIBUTE, ''); | ||
portalContainer.setAttribute(PORTAL_CONTAINER_ATTRIBUTE, ''); | ||
document.body.appendChild(portalContainer); | ||
return portalContainer; | ||
} | ||
exports.getDefaultPortalContainer = function () { | ||
return document.querySelector("[" + exports.PORTAL_CONTAINER_ATTRIBUTE + "]") || createPortalContainer(); | ||
}; | ||
var getDefaultPortalContainer = function () { return document.querySelector("[" + PORTAL_CONTAINER_ATTRIBUTE + "]") || createPortalContainer(); }; | ||
exports.PORTAL_CONTAINER_ATTRIBUTE = PORTAL_CONTAINER_ATTRIBUTE; | ||
exports.getDefaultPortalContainer = getDefaultPortalContainer; |
{ | ||
"name": "@alfalab/core-components-portal", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Portal component", | ||
@@ -18,3 +18,3 @@ "keywords": [], | ||
}, | ||
"gitHead": "dc692d3f87268477e5b61271fa883588d251a88e" | ||
"gitHead": "c4e19f6c7f3104403716759f324b177fb3f706cf" | ||
} |
4167
85