Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit f26d0d0

Browse files
committed
Make form groups expandable
1 parent a7846d1 commit f26d0d0

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

packages/vulcan-base-styles/lib/stylesheets/_forms.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,22 @@ div.ReactTags__suggestions mark{
127127
&.danger{
128128
color: #EF1642;
129129
}
130+
}
131+
132+
.form-section-heading{
133+
display: flex;
134+
align-items: center;
135+
justify-content: space-between;
136+
cursor: pointer;
137+
padding-bottom: 10px;
138+
margin-bottom: 10px;
139+
border-bottom: 1px solid $light-grey;
140+
}
141+
142+
.form-section-heading-title{
143+
margin: 0;
144+
}
145+
146+
.form-section-collapsed{
147+
display: none;
130148
}

packages/vulcan-forms/lib/FormGroup.jsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
3-
import FormComponent from "./FormComponent.jsx";
3+
import FormComponent from './FormComponent.jsx';
4+
import { Components } from 'meteor/vulcan:core';
5+
import classNames from 'classnames';
46

57
class FormGroup extends PureComponent {
8+
9+
constructor(props) {
10+
super(props);
11+
this.toggle = this.toggle.bind(this);
12+
this.renderHeading = this.renderHeading.bind(this);
13+
this.state = {
14+
collapsed: props.startCollapsed || false
15+
}
16+
}
17+
18+
toggle() {
19+
this.setState({
20+
collapsed: !this.state.collapsed
21+
})
22+
}
23+
24+
renderHeading() {
25+
return (
26+
<div className="form-section-heading" onClick={this.toggle}>
27+
<h3 className="form-section-heading-title">{this.props.label}</h3>
28+
<span className="form-section-heading-toggle">
29+
{this.state.collapsed ? <Components.Icon name="expand" /> : <Components.Icon name="collapse" />}
30+
</span>
31+
</div>
32+
)
33+
}
34+
635
render() {
736
return (
837
<div className="form-section">
9-
{this.props.name === 'default' ? null : <h3 className="form-section-heading">{this.props.label}</h3>}
10-
{this.props.fields.map(field => <FormComponent key={field.name} {...field} updateCurrentValues={this.props.updateCurrentValues} />)}
38+
{this.props.name === 'default' ? null : this.renderHeading()}
39+
<div className={classNames({'form-section-collapsed': this.state.collapsed})}>
40+
{this.props.fields.map(field => <FormComponent key={field.name} {...field} updateCurrentValues={this.props.updateCurrentValues} />)}
41+
</div>
1142
</div>
1243
)
1344
}

0 commit comments

Comments
 (0)