UNPKG

catreact

Version:

Catavolt Core React Components

70 lines (69 loc) 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Created by rburson on 1/14/16. */ var React = require("react"); var catreact_core_1 = require("./catreact-core"); var catavolt_sdk_1 = require("catavolt-sdk"); /* *************************************************** * Render an EntityRec *************************************************** */ exports.CvRecord = React.createClass({ mixins: [catreact_core_1.CvBaseMixin], componentDidMount: function () { }, getChildContext: function () { var ctx = this.getDefaultChildContext(); ctx.cvContext.scopeCtx.scopeObj = this.props.entityRec; return ctx; }, getDefaultProps: function () { return { entityRec: null, paneContext: null, renderPropNames: null, propRenderer: null, renderer: null, wrapperElemName: 'span', wrapperElemProps: {} }; }, getInitialState: function () { return {}; }, paneContext: function () { return this.props.paneContext || this.findPaneContext(); }, render: function () { var _this = this; var entityRec = this.props.entityRec; if (entityRec) { if (this.props.renderer) { return this.props.renderer(this.getChildContext().cvContext); } else if (this.props.propRenderer) { var newChildren_1 = []; var renderPropNames = this.props.renderPropNames ? this.props.renderPropNames : entityRec.propNames; renderPropNames.forEach(function (name) { var prop = entityRec.propAtName(name); var newElement = React.cloneElement(_this.props.propRenderer(_this.getChildContext().cvContext, prop), { key: prop.name }); newChildren_1.push(newElement); }); var props = catavolt_sdk_1.ObjUtil.addAllProps(this.props.wrapperElemProps, {}); return React.createElement(this.props.wrapperElemName, props, newChildren_1); } else if (React.Children.count(this.props.children) > 0) { return this.props.children; } else { return null; } } else { return null; } } });