UNPKG

react-form-controlled

Version:

Intuitive react forms for building powerful applications

29 lines (24 loc) 901 B
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; import { Children } from 'react'; import PropTypes from 'prop-types'; import Element from './Element'; export default class If extends Element { render() { const value = this.getValue(); const { cond, children } = this.props; const parent = this.getParent(); if (typeof cond !== 'function' || !children) { return null; } const canShow = cond(value); if (!canShow) { return null; } return Children.only(parent.processChildren(children)); } } If.propTypes = _extends({}, Element.propTypes, { cond: PropTypes.func.isRequired, children: PropTypes.node }); //# sourceMappingURL=If.js.map