react-form-controlled
Version:
Intuitive react forms for building powerful applications
44 lines (37 loc) • 1.27 kB
JavaScript
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 { cloneElement } from 'react';
import PropTypes from 'prop-types';
import Element from './Element';
export default class Integrate extends Element {
constructor(...args) {
var _temp;
return _temp = super(...args), _initialiseProps.call(this), _temp;
}
render() {
const { children, name, render } = this.props;
const currentValue = this.getValue();
const newProps = {
name,
value: currentValue,
onChange: this.handleChange
};
if (typeof render === 'function') {
return render(newProps);
} else if (typeof children === 'function') {
return children(newProps);
}
throw new Error('You need to set property render or children as function');
}
}
Integrate.propTypes = _extends({}, Element.propTypes, {
render: PropTypes.func
});
Integrate.defaultProps = {
render: undefined
};
var _initialiseProps = function () {
this.handleChange = (...args) => {
this.setValue(...args);
};
};
//# sourceMappingURL=Integrate.js.map