UNPKG

ldx-widgets

Version:

widgets

86 lines (76 loc) 2.79 kB
(function() { var ContextWrapper, PropTypes, React, ReactDOM, assign, createClass, div; React = require('react'); PropTypes = require('prop-types'); createClass = require('create-react-class'); ReactDOM = require('react-dom'); div = require('react-dom-factories').div; assign = require('lodash/assign'); ContextWrapper = createClass({ childContextTypes: { clearValidationError: PropTypes.func, addValidationError: PropTypes.func, getValidationStatus: PropTypes.func, toggleValidationError: PropTypes.func, setTabErrorAnchors: PropTypes.func, openOverlay: PropTypes.func, closeOverlay: PropTypes.func }, getChildContext: function() { this.clearValidationError = sinon.spy(); this.addValidationError = sinon.spy(); this.getValidationStatus = sinon.spy(this.getValidationStatusStub); this.toggleValidationError = sinon.spy(); this.setTabErrorAnchors = sinon.spy(); this.openOverlay = sinon.spy(); this.closeOverlay = sinon.spy(); return { clearValidationError: this.clearValidationError, addValidationError: this.addValidationError, getValidationStatus: this.getValidationStatus, toggleValidationError: this.toggleValidationError, openOverlay: this.openOverlay, closeOverlay: this.closeOverlay }; }, componentWillMount: function() { var ref; return this.ref = ((ref = this.props.childProps) != null ? ref.ref : void 0) || 'input'; }, render: function() { var childProps, children, factory, props, ref; ref = this.props, factory = ref.factory, childProps = ref.childProps, children = ref.children; props = assign({}, childProps, { ref: this.ref }); return div({ key: 'wrapper' }, children || factory(props)); }, getInput: function() { return this.refs[this.ref]; }, getInputEl: function() { return ReactDOM.findDOMNode(this.refs[this.ref]); }, getValidationSpies: function() { return { clearValidationError: this.clearValidationError, addValidationError: this.addValidationError, getValidationStatus: this.getValidationStatus, toggleValidationError: this.toggleValidationError }; }, getValidationStatusStub: function() { var error, forceShowAllErrors, ref; ref = this.props, error = ref.error, forceShowAllErrors = ref.forceShowAllErrors; error = error != null ? error : null; forceShowAllErrors = forceShowAllErrors === true ? true : false; return { error: error, forceShowAllErrors: forceShowAllErrors }; } }); module.exports = React.createFactory(ContextWrapper); }).call(this);