import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { Components } from 'meteor/vulcan:core'; import classNames from 'classnames'; import { registerComponent } from 'meteor/vulcan:core'; import mergeWithComponents from '../modules/mergeWithComponents'; const FormGroupHeader = ({ toggle, collapsed, label }) => (

{label}

{collapsed ? ( ) : ( )}
); FormGroupHeader.propTypes = { toggle: PropTypes.func.isRequired, label: PropTypes.string.isRequired, collapsed: PropTypes.bool }; registerComponent({ name: 'FormGroupHeader', component: FormGroupHeader }); const FormGroupLayout = ({ children, heading, collapsed, hasErrors }) => (
{heading}
{children}
); FormGroupLayout.propTypes = { hasErrors: PropTypes.bool, collapsed: PropTypes.bool, heading: PropTypes.node, children: PropTypes.node }; registerComponent({ name: 'FormGroupLayout', component: FormGroupLayout }); class FormGroup extends PureComponent { constructor(props) { super(props); this.toggle = this.toggle.bind(this); this.renderHeading = this.renderHeading.bind(this); this.state = { collapsed: props.startCollapsed || false }; } toggle() { this.setState({ collapsed: !this.state.collapsed }); } renderHeading(FormComponents) { return ( ); } // if at least one of the fields in the group has an error, the group as a whole has an error hasErrors = () => _.some(this.props.fields, field => { return !!this.props.errors.filter(error => error.path === field.path) .length; }); render() { const { name, fields, formComponents } = this.props; const { collapsed } = this.state; const FormComponents = mergeWithComponents(formComponents); return ( {fields.map(field => ( ))} ); } } FormGroup.propTypes = { name: PropTypes.string, label: PropTypes.string, order: PropTypes.number, fields: PropTypes.array.isRequired, errors: PropTypes.array.isRequired, throwError: PropTypes.func.isRequired, currentValues: PropTypes.object.isRequired, updateCurrentValues: PropTypes.func.isRequired, deletedValues: PropTypes.array.isRequired, addToDeletedValues: PropTypes.func.isRequired, clearFieldErrors: PropTypes.func.isRequired, formType: PropTypes.string.isRequired, currentUser: PropTypes.object }; module.exports = FormGroup; registerComponent('FormGroup', FormGroup); const IconRight = ({ width = 24, height = 24 }) => ( ); registerComponent('IconRight', IconRight); const IconDown = ({ width = 24, height = 24 }) => ( ); registerComponent('IconDown', IconDown);