Add expand/collapse all layer groups feature (#130)

This commit is contained in:
Gregory Wolanski 2017-10-25 21:35:19 +02:00
parent ddb3bcde43
commit 06554b83dc
2 changed files with 45 additions and 6 deletions

View file

@ -49,6 +49,7 @@ class LayerListContainer extends React.Component {
super(props)
this.state = {
collapsedGroups: {},
areAllGroupsExpanded: false,
isOpen: {
add: false,
}
@ -94,6 +95,31 @@ class LayerListContainer extends React.Component {
})
}
toggleLayers() {
let idx=0
let newGroups=[]
this.groupedLayers().forEach(layers => {
const groupPrefix = layerPrefix(layers[0].id)
const lookupKey = [groupPrefix, idx].join('-')
if (layers.length > 1) {
newGroups[lookupKey] = this.state.areAllGroupsExpanded
}
layers.forEach((layer) => {
idx += 1
})
});
this.setState({
collapsedGroups: newGroups,
areAllGroupsExpanded: !this.state.areAllGroupsExpanded
})
}
groupedLayers() {
const groups = []
for (let i = 0; i < this.props.layers.length; i++) {
@ -176,12 +202,25 @@ class LayerListContainer extends React.Component {
/>
<header className="maputnik-layer-list-header">
<span className="maputnik-layer-list-header-title">Layers</span>
<div className="maputnik-default-property">
<div className="maputnik-multibutton">
<a
onClick={this.toggleLayers.bind(this)}
className="maputnik-button">
{this.state.areAllGroupsExpanded === true ? "Collapse" : "Expand"}
</a>
</div>
</div>
<span className="maputnik-space" />
<Button
<div className="maputnik-default-property">
<div className="maputnik-multibutton">
<a
onClick={this.toggleModal.bind(this, 'add')}
className="maputnik-add-layer">
className="maputnik-button maputnik-button-selected">
Add Layer
</Button>
</a>
</div>
</div>
</header>
<ul className="maputnik-layer-list-container">
{listItems}

View file

@ -1,7 +1,7 @@
// LAYER LIST
.maputnik-layer-list {
&-header {
padding: $margin-2;
padding: $margin-2 $margin-2 $margin-3;
@include flex-row;