UNPKG

@vs-form/vs-form

Version:

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

77 lines (74 loc) 2.7 kB
import { Component } from 'react'; import 'lodash/capitalize'; import 'lodash/cloneDeep'; import 'lodash/get'; import 'lodash/has'; import 'lodash/isArray'; import '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 isUndefined from 'lodash/isUndefined'; import 'lodash/merge'; import 'lodash/set'; import 'lodash/toInteger'; import 'lodash/toNumber'; import 'lodash/trimEnd'; import 'lodash/uniq'; import 'lodash/debounce'; import 'lodash/throttle'; import { e as ButtonAction } from './chunk-68362596.js'; import classNames from 'classnames'; import { b as buttonAction } from './chunk-7293e165.js'; class VsButtonBase extends 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 === ButtonAction.save) { event.preventDefault(); this.props.schemaManager.submit(); } if (comp.action === 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 = buttonAction[this.comp.action]; } if (isUndefined(this.comp.icon)) ; if (this.comp.action === 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 }); } } export { VsButtonBase as a };