@vs-form/vs-form
Version:
A schema-based form generator component for React using material-ui
94 lines (89 loc) • 3.83 kB
JavaScript
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var React__default = _interopDefault(React);
require('lodash/capitalize');
require('lodash/cloneDeep');
require('lodash/get');
require('lodash/has');
require('lodash/isArray');
require('lodash/isDate');
require('lodash/isBoolean');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/isInteger');
var isNull = _interopDefault(require('lodash/isNull'));
require('lodash/isNumber');
require('lodash/isObject');
require('lodash/isPlainObject');
require('lodash/isRegExp');
require('lodash/isString');
var isUndefined = _interopDefault(require('lodash/isUndefined'));
require('lodash/merge');
require('lodash/set');
require('lodash/toInteger');
var toNumber = _interopDefault(require('lodash/toNumber'));
require('lodash/trimEnd');
require('lodash/uniq');
require('lodash/debounce');
require('lodash/throttle');
var __chunk_2 = require('./chunk-e8808437.js');
require('@material-ui/core/FormControl');
require('@material-ui/core/FormHelperText');
require('@material-ui/core/FormLabel');
var __chunk_3 = require('./chunk-7581cbb1.js');
var classNames = _interopDefault(require('classnames'));
var Radio = _interopDefault(require('@material-ui/core/Radio'));
var RadioGroup = _interopDefault(require('@material-ui/core/RadioGroup'));
var FormControlLabel = _interopDefault(require('@material-ui/core/FormControlLabel'));
const styles = {
radioHeight: {
height: '30px'
}
};
class VsRadioGroup extends React.Component {
constructor(props) {
super(props);
this.RadioGroupProps = {};
this.RadioProps = {};
this.FormControlLabelProps = {};
this.renderComp = (dataProps) => {
return (React.createElement(RadioGroup, Object.assign({ value: this.getValue(dataProps.state.value), onChange: this.changeValue(dataProps) }, this.RadioGroupProps), this.renderItems(dataProps)));
};
this.renderItems = (_dataProps) => {
const items = this.comp.data.items;
return items.map((item, ind) => {
return React.createElement(FormControlLabel, Object.assign({ inputRef: ind === 0 && this.inputRef, value: item.value.toString(), key: item.value, control: React.createElement(Radio, Object.assign({}, this.RadioProps)), label: item.text }, this.FormControlLabelProps));
});
};
this.changeValue = (dataProps) => (_evt, value) => {
const schemaValue = this.comp.data.dataType === __chunk_3.DataType.number ? toNumber(value) : value;
dataProps.updateValue(value, schemaValue);
};
this.initProps();
this.inputRef = React.createRef();
props.schemaManager.addInputRef(props.comp, this.inputRef);
}
get comp() { return this.props.comp; }
render() {
return (React.createElement(__chunk_2.VsBaseFormControl, Object.assign({}, this.props, { showLabel: true }), this.renderComp));
}
getValue(value) {
return (isUndefined(value) || isNull(value)) ? '' : value.toString();
}
initProps() {
const { FormControlProps, FormHelperTextProps, FormLabelProps, RadioProps, FormControlLabelProps, ...RadioGroupProps } = this.comp.props;
if (RadioGroupProps) {
this.RadioGroupProps = RadioGroupProps;
}
if (RadioProps) {
this.RadioProps = RadioProps;
}
if (FormControlLabelProps) {
this.FormControlLabelProps = FormControlLabelProps;
}
this.RadioProps.className = classNames(this.props.classes.radioHeight, this.RadioProps.className);
}
}
exports.default = VsRadioGroup;
exports.styles = styles;