UNPKG

vs-form-mui-4x

Version:

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

92 lines (87 loc) 3.08 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'); var has = _interopDefault(require('lodash/has')); require('lodash/isArray'); var isDate = _interopDefault(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'); class VsDate extends React.Component { constructor(props) { super(props); this.changeValue = (dataProps) => (evt) => { const value = evt.target.value; const dt = value ? index.stringToDate(this.comp.type, evt.target.value) : null; dataProps.updateValue(dt); }; this.initProps = () => { if (!this.comp.props) { this.comp.props = {}; } const props = this.comp.props; const type = this.comp.type; if (type === index.Component.date) { props.type = 'date'; } else if (type === index.Component.datetime) { props.type = 'datetime-local'; } else if (type === index.Component.time) { props.type = 'time'; } set(props, 'InputLabelProps.shrink', true); }; this.initProps(); } get comp() { return this.props.comp; } render() { return React.createElement(index.VsBaseInput, Object.assign({ value: this.getValue, onChange: this.changeValue }, this.props)); } getValue(dataProps) { if (isDate(dataProps.state.value)) { const withSeconds = has(this.comp, 'props.inputProps.step'); return index.dateToString(dataProps.state.value, this.comp.type, withSeconds); } else { return ''; } } } exports.default = VsDate;