UNPKG

@vs-form/vs-form

Version:

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

67 lines (62 loc) 2.53 kB
'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'); require('lodash/isNull'); require('lodash/isNumber'); require('lodash/isObject'); require('lodash/isPlainObject'); require('lodash/isRegExp'); require('lodash/isString'); require('lodash/isUndefined'); require('lodash/merge'); require('lodash/set'); require('lodash/toInteger'); 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 FormControlLabel = _interopDefault(require('@material-ui/core/FormControlLabel')); var Switch = _interopDefault(require('@material-ui/core/Switch')); class VsSwitch extends React.Component { constructor(props) { super(props); this.SwitchProps = {}; this.FormControlLabelProps = {}; this.renderComp = (dataProps) => { return (React.createElement(FormControlLabel, Object.assign({ control: React.createElement(Switch, Object.assign({ checked: dataProps.state.value, onChange: this.changeValue(dataProps) }, this.SwitchProps)), label: this.comp.label, inputRef: this.inputRef }, this.FormControlLabelProps))); }; this.changeValue = (dataProps) => (_evt, checked) => { dataProps.updateValue(checked); }; this.inputRef = React.createRef(); props.schemaManager.addInputRef(props.comp, this.inputRef); const { FormControlProps, FormHelperTextProps, FormLabelProps, FormControlLabelProps, ...SwitchProps } = this.comp.props; if (SwitchProps) { this.SwitchProps = SwitchProps; } if (FormControlLabelProps) { this.FormControlLabelProps = FormControlLabelProps; } } get comp() { return this.props.comp; } render() { return (React.createElement(__chunk_2.VsBaseFormControl, Object.assign({}, this.props), this.renderComp)); } } exports.default = VsSwitch;