vs-form-mui-4x
Version:
A schema-based form generator component for React using material-ui 4.x
87 lines (84 loc) • 2.82 kB
JavaScript
import { Component, createElement } from 'react';
import 'lodash/capitalize';
import 'lodash/cloneDeep';
import 'lodash/get';
import has from 'lodash/has';
import 'lodash/isArray';
import isDate from '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 set from 'lodash/set';
import 'lodash/toInteger';
import 'lodash/toNumber';
import 'lodash/trimEnd';
import 'lodash/uniq';
import 'lodash/debounce';
import 'lodash/throttle';
import { a7 as stringToDate, C as Component$1, f as VsBaseInput, a8 as dateToString } from './index-5c5f12ca.js';
import '@material-ui/core/FormControl';
import '@material-ui/core/FormHelperText';
import '@material-ui/core/FormLabel';
import '@material-ui/core/TextField';
import '@material-ui/core/InputAdornment';
import '@material-ui/core/Tooltip';
import '@material-ui/core/styles';
import 'classnames';
import '@material-ui/core/Icon';
import '@material-ui/core/SvgIcon';
import 'date-fns';
import 'events';
import '@material-ui/core/Typography';
import '@material-ui/core/Grid';
import '@material-ui/core/IconButton';
class VsDate extends Component {
constructor(props) {
super(props);
this.changeValue = (dataProps) => (evt) => {
const value = evt.target.value;
const dt = value ? 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 === Component$1.date) {
props.type = 'date';
}
else if (type === Component$1.datetime) {
props.type = 'datetime-local';
}
else if (type === Component$1.time) {
props.type = 'time';
}
set(props, 'InputLabelProps.shrink', true);
};
this.initProps();
}
get comp() { return this.props.comp; }
render() {
return createElement(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 dateToString(dataProps.state.value, this.comp.type, withSeconds);
}
else {
return '';
}
}
}
export default VsDate;