UNPKG

@vs-form/vs-form

Version:

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

82 lines (77 loc) 3 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'); var isUndefined = _interopDefault(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_3 = require('./chunk-7581cbb1.js'); var classNames = _interopDefault(require('classnames')); var __chunk_9 = require('./chunk-e28442a5.js'); class VsButtonBase extends React.Component { constructor(props) { super(props); this.componentEventParams = this.props.schemaManager.getComponentEventParams(this.props.comp); this.btnClick = (event) => { const comp = this.props.comp; if (comp.action === __chunk_3.ButtonAction.save) { event.preventDefault(); this.props.schemaManager.submit(); } if (comp.action === __chunk_3.ButtonAction.cancel) { this.props.schemaManager.cancelValues(); } if (comp.onClick) { comp.onClick(this.componentEventParams); } }; this.initProps = () => { if (this.comp.action) { if (isUndefined(this.comp.disabled)) { this.props.buttonProps.disabled = !this.props.schemaManager.dataStateChanged; } if (!this.comp.label) { this.comp.label = __chunk_9.buttonAction[this.comp.action]; } if (isUndefined(this.comp.icon)) ; if (this.comp.action === __chunk_3.ButtonAction.save) { this.props.buttonProps.type = 'submit'; } } if (isUndefined(this.props.buttonProps.color)) { this.props.buttonProps.color = 'primary'; } this.props.buttonProps.onClick = this.btnClick; this.props.IconProps.className = classNames(this.props.IconProps.className, 'mdi', 'mdi-' + this.comp.icon, this.props.classes.icon); }; this.initProps(); } get comp() { return this.props.comp; } render() { const { btnClick } = this; return this.props.children({ btnClick, ...this.props }); } } exports.VsButtonBase = VsButtonBase;