UNPKG

vs-form-mui-4x

Version:

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

99 lines (94 loc) 3.56 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'); var isArray = _interopDefault(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'); var set = _interopDefault(require('lodash/set')); require('lodash/toInteger'); require('lodash/toNumber'); require('lodash/trimEnd'); require('lodash/uniq'); require('lodash/debounce'); require('lodash/throttle'); var index = require('./index-7e71e00b.js'); require('@material-ui/core/FormControl'); require('@material-ui/core/FormHelperText'); require('@material-ui/core/FormLabel'); require('@material-ui/core/TextField'); require('@material-ui/core/InputAdornment'); require('@material-ui/core/Tooltip'); require('@material-ui/core/styles'); require('classnames'); require('@material-ui/core/Icon'); require('@material-ui/core/SvgIcon'); require('date-fns'); require('events'); require('@material-ui/core/Typography'); require('@material-ui/core/Grid'); require('@material-ui/core/IconButton'); var Checkbox = _interopDefault(require('@material-ui/core/Checkbox')); var MenuItem = _interopDefault(require('@material-ui/core/MenuItem')); class VsSelect extends React.Component { constructor(props) { super(props); this.changeValue = (dataProps) => (evt) => { const value = evt.target.value; dataProps.updateValue(value); }; this.getProps = () => { set(this.comp, 'props.select', true); if (index.dataTypeIsArray(this.comp.data.dataType)) { set(this.comp, 'props.SelectProps.multiple', true); set(this.comp, 'props.SelectProps.renderValue', this.renderValue); } }; this.renderValue = (selected) => { const items = this.comp.data.items; const findItem = (s) => items.find(i => i.value === s) || { text: '' }; const find = (s) => findItem(s).text; const res = selected.map(s => find(s)); return res.join(', '); }; this.getItems = (value) => { const items = this.comp.data.items; return items.map((item) => { return (React.createElement(MenuItem, { key: item.value, value: item.value }, isArray(value) && React.createElement(Checkbox, { checked: value.indexOf(item.value) > -1 }), item.text)); }); }; this.getProps(); } get comp() { return this.props.comp; } render() { return React.createElement(index.VsBaseInput, Object.assign({ value: this.getValue, onChange: this.changeValue, renderItems: this.getItems }, this.props)); } getValue(dataProps) { let defaultValue; if (index.dataTypeIsArray(this.comp.data.dataType)) { defaultValue = []; } else { defaultValue = ''; } return dataProps.state.value || defaultValue; } } exports.default = VsSelect;