UNPKG

@vs-form/vs-form

Version:

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

116 lines (111 loc) 4.73 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'); require('@material-ui/core/Tooltip'); var classNames = _interopDefault(require('classnames')); require('@material-ui/core/Icon'); require('@material-ui/core/SvgIcon'); var __chunk_5 = require('./chunk-41ea4037.js'); require('@material-ui/core/Typography'); var __chunk_7 = require('./chunk-819d0a62.js'); var __chunk_8 = require('./chunk-f9facc49.js'); var ExpansionPanel = _interopDefault(require('@material-ui/core/ExpansionPanel')); var ExpansionPanelSummary = _interopDefault(require('@material-ui/core/ExpansionPanelSummary')); var ExpansionPanelDetails = _interopDefault(require('@material-ui/core/ExpansionPanelDetails')); const styles = { root: { width: '100%' }, dense: { padding: '5px', } }; class VsExpansionPanel extends React.Component { constructor(props) { super(props); this.ExpansionPanelProps = {}; this.ExpansionPanelSummaryProps = {}; this.ExpansionPanelDetailsProps = {}; this.TypographyProps = {}; this.componentEventParams = this.props.schemaManager.getComponentEventParams(this.props.comp); this.changeExpanded = (_event, expanded) => { let canChange = true; const params = { ...this.componentEventParams, expanded }; if (this.comp.onBeforeChange) { const p = { ...params, canChange: true }; this.comp.onBeforeChange(p); canChange = p.canChange; } if (canChange) { this.setState({ expanded }); this.props.schemaManager.changeExpanded(this.comp, expanded, !!this.props.designMode); if (this.comp.onChange) { this.comp.onChange(params); } } }; this.initProps(); this.state = { expanded: !!(this.comp.expanded) }; } get comp() { return this.props.comp; } render() { return (React.createElement(ExpansionPanel, Object.assign({}, this.ExpansionPanelProps, { expanded: this.state.expanded }), React.createElement(ExpansionPanelSummary, Object.assign({}, this.ExpansionPanelSummaryProps), React.createElement(__chunk_7.Text, Object.assign({ text: this.comp.label }, this.TypographyProps))), React.createElement(ExpansionPanelDetails, Object.assign({}, this.ExpansionPanelDetailsProps), this.props.children))); } initProps() { const { ExpansionPanelSummaryProps, ExpansionPanelDetailsProps, TypographyProps, IconProps, ...ExpansionPanelProps } = this.comp.props; if (ExpansionPanelProps) { this.ExpansionPanelProps = ExpansionPanelProps; } if (ExpansionPanelSummaryProps) { this.ExpansionPanelSummaryProps = ExpansionPanelSummaryProps; } if (ExpansionPanelDetailsProps) { this.ExpansionPanelDetailsProps = ExpansionPanelDetailsProps; } if (TypographyProps) { this.TypographyProps = TypographyProps; } this.ExpansionPanelProps.onChange = this.changeExpanded; this.ExpansionPanelProps.className = classNames(this.props.classes.root, this.ExpansionPanelProps.className); if (this.comp.dense) { this.ExpansionPanelDetailsProps.className = classNames(this.props.classes.dense, this.ExpansionPanelDetailsProps.className); } this.ExpansionPanelSummaryProps.expandIcon = React.createElement(__chunk_5.BaseIcon, { svg: __chunk_8.chevronDown }); if (isUndefined(this.ExpansionPanelProps.expanded)) { this.ExpansionPanelProps.expanded = false; } } } exports.default = VsExpansionPanel; exports.styles = styles;