maputnik/src/layers/list.jsx

62 lines
1.5 KiB
React
Raw Normal View History

2016-09-10 14:10:25 +02:00
import React from 'react'
import Immutable from 'immutable'
import { Heading, Toolbar, NavItem, Space} from 'rebass'
import { LayerEditor } from './editor.jsx'
import scrollbars from '../scrollbars.scss'
import PureRenderMixin from 'react-addons-pure-render-mixin';
2016-09-10 14:10:25 +02:00
// List of collapsible layer editors
export class LayerList extends React.Component {
static propTypes = {
2016-09-10 17:31:45 +02:00
layers: React.PropTypes.instanceOf(Immutable.OrderedMap),
2016-09-10 15:15:17 +02:00
onLayersChanged: React.PropTypes.func.isRequired
}
2016-09-10 14:10:25 +02:00
constructor(props) {
super(props)
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
2016-09-10 14:10:25 +02:00
}
onLayerDestroyed(deletedLayer) {
2016-09-10 17:31:45 +02:00
const remainingLayers = this.props.layers.delete(deletedLayer.get('id'))
this.props.onLayersChanged(remainingLayers)
2016-09-10 14:10:25 +02:00
}
2016-09-10 17:31:45 +02:00
onLayerChanged(layer) {
const changedLayers = this.props.layers.set(layer.get('id'), layer)
2016-09-10 14:10:25 +02:00
this.props.onLayersChanged(changedLayers)
}
render() {
var layerPanels = []
2016-09-10 17:31:45 +02:00
layerPanels = this.props.layers.map(layer => {
return <LayerEditor
2016-09-10 14:10:25 +02:00
key={layer.get('id')}
layer={layer}
onLayerDestroyed={this.onLayerDestroyed.bind(this)}
onLayerChanged={this.onLayerChanged.bind(this)}
2016-09-10 17:31:45 +02:00
/>
}).toIndexedSeq()
2016-09-10 14:10:25 +02:00
return <div>
<Toolbar style={{marginRight: 20}}>
<NavItem>
<Heading>Layers</Heading>
</NavItem>
<Space auto x={1} />
</Toolbar>
<div className={scrollbars.darkScrollbar} style={{
overflowY: "scroll",
bottom:0,
left:0,
right:0,
top:40,
position: "absolute",
}}>
{layerPanels}
</div>
</div>
}
}