From abceb457c948df6d86c1db3425f96016c599c1f8 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Wed, 11 Jan 2017 18:18:47 +0100 Subject: [PATCH] Collapsible layer groups #66 --- src/components/layers/LayerList.jsx | 37 +++++++++++++++---------- src/components/layers/LayerListItem.jsx | 2 ++ src/styles/_layer.scss | 6 ++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/components/layers/LayerList.jsx b/src/components/layers/LayerList.jsx index 7e1e11d..ffdb680 100644 --- a/src/components/layers/LayerList.jsx +++ b/src/components/layers/LayerList.jsx @@ -1,4 +1,5 @@ import React from 'react' +import classnames from 'classnames' import cloneDeep from 'lodash.clonedeep' import Button from '../Button' @@ -31,6 +32,7 @@ class LayerListContainer extends React.Component { constructor(props) { super(props) this.state = { + collapsedGroups: {}, isOpen: { add: false, } @@ -92,37 +94,42 @@ class LayerListContainer extends React.Component { } toggleLayerGroup(groupPrefix) { - groupedLayers().forEach(layers => { - if(groupPrefix === layerPrefix(layers[0].id)) { - layers.forEach(layer => { - //HACK - //In this case it is ok to modify the metadata - //because no one else depends on it - layer.metadata = { - ...layer.metadata, - 'maputnik:visible': false - } - }) - } + const newGroups = { ...this.state.collapsedGroups } + if(groupPrefix in this.state.collapsedGroups) { + newGroups[groupPrefix] = !this.state.collapsedGroups[groupPrefix] + } else { + newGroups[groupPrefix] = true + } + this.setState({ + collapsedGroups: newGroups }) } render() { + const isCollapsed = groupPrefix => { + const collapsed = this.state.collapsedGroups[groupPrefix] + return collapsed === undefined ? false : collapsed + } + const listItems = [] let idx = 0 this.groupedLayers().forEach(layers => { + const groupPrefix = layerPrefix(layers[0].id) if(layers.length > 1) { - const groupPrefix = layerPrefix(layers[0].id) const grp = listItems.push(grp) } layers.forEach(layer => { const listItem = {this.props.layerId} diff --git a/src/styles/_layer.scss b/src/styles/_layer.scss index 9ca2f5b..6f259d6 100644 --- a/src/styles/_layer.scss +++ b/src/styles/_layer.scss @@ -62,6 +62,12 @@ color: $color-white; } + &-item-collapsed { + height: 0; + overflow: hidden; + padding: 0; + } + &-item-id { width: 115px; white-space: nowrap;