diff --git a/src/components/layers/LayerEditor.jsx b/src/components/layers/LayerEditor.jsx index 7596a933..03f3e9df 100644 --- a/src/components/layers/LayerEditor.jsx +++ b/src/components/layers/LayerEditor.jsx @@ -1,11 +1,9 @@ import React from 'react' -import Toolbar from 'rebass/dist/Toolbar' -import NavItem from 'rebass/dist/NavItem' - import SourceEditor from './SourceEditor' import FilterEditor from '../filter/FilterEditor' import PropertyGroup from '../fields/PropertyGroup' +import LayerEditorGroup from './LayerEditorGroup' import ScrollContainer from '../ScrollContainer' @@ -37,7 +35,30 @@ export default class LayerEditor extends React.Component { } constructor(props) { - super(props); + super(props) + + //TODO: Clean this up and refactor into function + const editorGroups = {} + layout[this.props.layer.type].groups.forEach(group => { + editorGroups[group.title] = true + }) + editorGroups['Source'] = true + + this.state = { editorGroups } + } + + componentWillReceiveProps(nextProps) { + const additionalGroups = { ...this.state.editorGroups } + + layout[nextProps.layer.type].groups.forEach(group => { + if(!(group.title in additionalGroups)) { + additionalGroups[group.title] = true + } + }) + + this.setState({ + editorGroups: additionalGroups + }) } getChildContext () { @@ -71,41 +92,62 @@ export default class LayerEditor extends React.Component { this.props.onLayerChanged(changedLayer) } + onGroupToggle(groupTitle, active) { + const changedActiveGroups = { + ...this.state.editorGroups, + [groupTitle]: active, + } + this.setState({ + editorGroups: changedActiveGroups + }) + } + render() { + console.log('editor groups', this.state.editorGroups) const layerType = this.props.layer.type const groups = layout[layerType].groups const propertyGroups = groups.map(group => { - return + return + + }) + let dataGroup = null + if(this.props.layer.type !== 'background') { + dataGroup = + this.onFilterChange(f)} + /> + + + } + return
- - - {this.props.layer.id} - - - {propertyGroups} - {this.props.layer.type !== 'background' &&
- this.onFilterChange(f)} - /> - -
} + {propertyGroups} + {dataGroup}
} } diff --git a/src/components/layers/LayerEditorGroup.jsx b/src/components/layers/LayerEditorGroup.jsx new file mode 100644 index 00000000..60fe0407 --- /dev/null +++ b/src/components/layers/LayerEditorGroup.jsx @@ -0,0 +1,57 @@ +import React from 'react' +import colors from '../../config/colors' +import { margins, fontSizes } from '../../config/scales' + +import CollapseOpenIcon from 'react-icons/lib/md/arrow-drop-down' +import CollapseCloseIcon from 'react-icons/lib/md/arrow-drop-up' + +class Collapser extends React.Component { + static propTypes = { + isCollapsed: React.PropTypes.bool.isRequired, + } + + render() { + const iconStyle = { + width: 20, + height: 20, + } + return this.props.isCollapsed ? : + } +} + +export default class LayerEditorGroup extends React.Component { + static propTypes = { + title: React.PropTypes.string.isRequired, + isActive: React.PropTypes.bool.isRequired, + children: React.PropTypes.element.isRequired, + onActiveToggle: React.PropTypes.func.isRequired + } + + render() { + return
this.props.onActiveToggle(!this.props.isActive)} + > +
+ {this.props.title} + + +
+
+ {this.props.children} +
+
+ } +}