ldx-widgets
Version:
widgets
80 lines (70 loc) • 2.52 kB
JavaScript
(function() {
var ContextWrapper, PropTypes, React, ReactDOM, _, createClass, div;
React = require('react');
PropTypes = require('prop-types');
createClass = require('create-react-class');
ReactDOM = require('react-dom');
div = React.DOM.div;
_ = require('lodash');
ContextWrapper = createClass({
childContextTypes: {
clearValidationError: PropTypes.func,
addValidationError: PropTypes.func,
getValidationStatus: PropTypes.func,
toggleValidationError: PropTypes.func,
setTabErrorAnchors: 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();
return {
clearValidationError: this.clearValidationError,
addValidationError: this.addValidationError,
getValidationStatus: this.getValidationStatus,
toggleValidationError: this.toggleValidationError
};
},
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);