UNPKG

@vs-form/vs-form

Version:

A schema-based form generator component for React using material-ui

65 lines (62 loc) 2.34 kB
import { Component, createElement, createRef } from 'react'; import 'lodash/capitalize'; import 'lodash/cloneDeep'; import 'lodash/get'; import 'lodash/has'; import 'lodash/isArray'; import 'lodash/isDate'; import 'lodash/isBoolean'; import 'lodash/isEmpty'; import 'lodash/isFunction'; import 'lodash/isInteger'; import 'lodash/isNull'; import 'lodash/isNumber'; import 'lodash/isObject'; import 'lodash/isPlainObject'; import 'lodash/isRegExp'; import 'lodash/isString'; import 'lodash/isUndefined'; import 'lodash/merge'; import 'lodash/set'; import 'lodash/toInteger'; import 'lodash/toNumber'; import 'lodash/trimEnd'; import 'lodash/uniq'; import 'lodash/debounce'; import 'lodash/throttle'; import { b as VsBaseFormControl } from './chunk-6c10537c.js'; import '@material-ui/core/FormControl'; import '@material-ui/core/FormHelperText'; import '@material-ui/core/FormLabel'; import Checkbox from '@material-ui/core/Checkbox'; import FormControlLabel from '@material-ui/core/FormControlLabel'; class VsCheckbox extends Component { constructor(props) { super(props); this.CheckboxProps = {}; this.FormControlLabelProps = {}; this.renderComp = (dataProps) => { return (createElement(FormControlLabel, Object.assign({ control: createElement(Checkbox, Object.assign({ checked: dataProps.state.value, onChange: this.changeValue(dataProps) }, this.CheckboxProps)), label: this.comp.label, inputRef: this.inputRef }, this.FormControlLabelProps))); }; this.changeValue = (dataProps) => (_evt, checked) => { dataProps.updateValue(checked); }; this.initProps(); this.inputRef = createRef(); props.schemaManager.addInputRef(props.comp, this.inputRef); } get comp() { return this.props.comp; } render() { return (createElement(VsBaseFormControl, Object.assign({}, this.props), this.renderComp)); } initProps() { const { FormControlProps, FormHelperTextProps, FormLabelProps, FormControlLabelProps, ...CheckboxProps } = this.comp.props; if (CheckboxProps) { this.CheckboxProps = CheckboxProps; } if (FormControlLabelProps) { this.FormControlLabelProps = FormControlLabelProps; } } } export default VsCheckbox;