UNPKG

igniteui-react-core

Version:
68 lines (67 loc) 2.31 kB
import * as React from 'react'; export class IgrComponentRendererContainer extends React.Component { constructor(props) { super(props); this.createdListeners = []; this.clearedListeners = []; this._currentRoot = null; this.rootCreated = this.rootCreated.bind(this); this.state = {}; } createObject(t, container, context, portalChildren, nameContext) { let C = t; t = new C(); return t; } rootCreated(rootRef) { let toRemove = []; if (!rootRef) { toRemove = []; for (let i = 0; i < this.clearedListeners.length; i++) { toRemove.push(this.clearedListeners[i]); } this.clearedListeners.length = 0; for (let i = 0; i < toRemove.length; i++) { toRemove[i](rootRef); } this._currentRoot = null; return; } this._currentRoot = rootRef; toRemove = []; for (let i = 0; i < this.createdListeners.length; i++) { toRemove.push(this.createdListeners[i]); } this.createdListeners.length = 0; for (let i = 0; i < toRemove.length; i++) { toRemove[i](rootRef); } } replaceRootItem(t, deferAttach, continueActions) { let act = (r) => { continueActions(true); }; this.createdListeners.push(act); this.setState({ rootComponentType: t }); } clearContainer(continueActions) { this.createdListeners.length = 0; let act = (r) => { continueActions(true); }; this.clearedListeners.push(act); this.setState({ rootComponentType: null }); } getRootObject() { return this._currentRoot; } render() { if (this.state.rootComponentType) { let ele = React.createElement(this.state.rootComponentType, { ref: this.rootCreated, width: "100%", height: "100%" }); return React.createElement("div", { style: this.props.style ? this.props.style : { width: "100%", height: "100%" } }, ele); } else { return React.createElement("div", { style: this.props.style ? this.props.style : { width: "100%", height: "100%" } }); } } }