UNPKG

vs-form-mui-4x

Version:

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

58 lines (53 loc) 2.32 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); var isUndefined = _interopDefault(require('lodash/isUndefined')); var index = require('./index-7e71e00b.js'); var classNames = _interopDefault(require('classnames')); var strings = require('./strings-7db01665.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 === index.ButtonAction.save) { event.preventDefault(); this.props.schemaManager.submit(); } if (comp.action === index.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 = strings.buttonAction[this.comp.action]; } if (isUndefined(this.comp.icon)) ; if (this.comp.action === index.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;