maputnik/src/layers/list.jsx

77 lines
2 KiB
React
Raw Normal View History

2016-09-10 14:10:25 +02:00
import React from 'react'
import Immutable from 'immutable'
2016-09-15 09:13:23 +02:00
import Heading from 'rebass/dist/Heading'
import Toolbar from 'rebass/dist/Toolbar'
import NavItem from 'rebass/dist/NavItem'
import Space from 'rebass/dist/Space'
2016-09-10 14:10:25 +02:00
import { LayerEditor } from './editor.jsx'
import scrollbars from '../scrollbars.scss'
import PureRenderMixin from 'react-addons-pure-render-mixin';
2016-12-17 16:09:37 +01:00
import theme from '../theme.js'
2016-09-10 14:10:25 +02:00
// List of collapsible layer editors
export class LayerList extends React.Component {
2016-12-04 17:03:36 +01:00
static propTypes = {
layers: React.PropTypes.instanceOf(Immutable.OrderedMap),
2016-12-17 16:09:37 +01:00
onLayersChanged: React.PropTypes.func.isRequired,
onLayerSelected: React.PropTypes.func,
}
static defaultProps = {
onLayerSelected: () => {},
2016-12-04 17:03:36 +01:00
}
constructor(props) {
super(props)
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
onLayerDestroyed(deletedLayer) {
const remainingLayers = this.props.layers.delete(deletedLayer.get('id'))
this.props.onLayersChanged(remainingLayers)
}
onLayerChanged(layer) {
const changedLayers = this.props.layers.set(layer.get('id'), layer)
this.props.onLayersChanged(changedLayers)
}
render() {
var layerPanels = []
layerPanels = this.props.layers.map(layer => {
2016-12-17 16:09:37 +01:00
const layerId = layer.get('id')
return <div key={layerId} style={{
padding: theme.scale[0],
borderBottom: 1,
borderTop: 1,
borderLeft: 2,
borderRight: 0,
borderStyle: "solid",
borderColor: theme.borderColor
}}>
<Toolbar onClick={() => this.props.onLayerSelected(layerId)}>
<NavItem style={{fontWeight: 400}}>
#{layerId}
</NavItem>
<Space auto x={1} />
</Toolbar>
</div>
2016-12-04 17:03:36 +01:00
}).toIndexedSeq()
return <div>
<div className={scrollbars.darkScrollbar} style={{
overflowY: "scroll",
bottom:0,
left:0,
right:0,
top:1,
position: "absolute",
}}>
{layerPanels}
</div>
</div>
}
2016-09-10 14:10:25 +02:00
}