maputnik/src/components/layers/LayerListItem.jsx

125 lines
3.2 KiB
React
Raw Normal View History

2016-12-17 16:43:25 +01:00
import React from 'react'
2016-12-19 11:46:48 +01:00
import Color from 'color'
2017-01-11 09:35:48 +01:00
import classnames from 'classnames'
2016-12-17 16:43:25 +01:00
2016-12-20 19:20:56 +01:00
import CopyIcon from 'react-icons/lib/md/content-copy'
import VisibilityIcon from 'react-icons/lib/md/visibility'
import VisibilityOffIcon from 'react-icons/lib/md/visibility-off'
import DeleteIcon from 'react-icons/lib/md/delete'
2016-12-20 11:44:22 +01:00
import LayerIcon from '../icons/LayerIcon'
import LayerEditor from './LayerEditor'
import {SortableElement, SortableHandle} from 'react-sortable-hoc'
import colors from '../../config/colors.js'
import { fontSizes, margins } from '../../config/scales.js'
2016-12-17 16:43:25 +01:00
2016-12-18 17:28:59 +01:00
@SortableHandle
class LayerTypeDragHandle extends React.Component {
static propTypes = LayerIcon.propTypes
render() {
return <LayerIcon
{...this.props}
2016-12-22 13:40:23 +01:00
style={{
cursor: 'move',
2016-12-25 17:46:18 +01:00
width: fontSizes[4],
height: fontSizes[4],
2016-12-22 13:40:23 +01:00
paddingRight: margins[0],
}}
2016-12-18 17:28:59 +01:00
/>
}
}
2016-12-17 19:58:30 +01:00
2016-12-20 19:20:56 +01:00
class IconAction extends React.Component {
static propTypes = {
action: React.PropTypes.string.isRequired,
onClick: React.PropTypes.func.isRequired,
2016-12-20 19:20:56 +01:00
}
renderIcon() {
switch(this.props.action) {
2017-01-11 09:35:48 +01:00
case 'copy': return <CopyIcon />
case 'show': return <VisibilityIcon />
case 'hide': return <VisibilityOffIcon />
case 'delete': return <DeleteIcon />
2016-12-20 19:20:56 +01:00
default: return null
}
}
render() {
return <a
2017-01-10 21:28:30 +01:00
className="maputnik-icon-action"
onClick={this.props.onClick}
2016-12-20 19:20:56 +01:00
>
{this.renderIcon()}
</a>
2016-12-20 19:20:56 +01:00
}
}
2016-12-17 19:58:30 +01:00
@SortableElement
2016-12-17 16:43:25 +01:00
class LayerListItem extends React.Component {
static propTypes = {
2016-12-17 19:58:30 +01:00
layerId: React.PropTypes.string.isRequired,
2016-12-18 17:28:59 +01:00
layerType: React.PropTypes.string.isRequired,
2016-12-20 19:20:56 +01:00
isSelected: React.PropTypes.bool,
visibility: React.PropTypes.string,
2016-12-20 19:20:56 +01:00
onLayerSelect: React.PropTypes.func.isRequired,
onLayerCopy: React.PropTypes.func,
onLayerDestroy: React.PropTypes.func,
onLayerVisibilityToggle: React.PropTypes.func,
2016-12-20 19:20:56 +01:00
}
static defaultProps = {
isSelected: false,
visibility: 'visible',
onLayerCopy: () => {},
onLayerDestroy: () => {},
onLayerVisibilityToggle: () => {},
2016-12-20 19:20:56 +01:00
}
static childContextTypes = {
reactIconBase: React.PropTypes.object
}
constructor(props) {
super(props)
}
getChildContext() {
return {
2016-12-25 17:46:18 +01:00
reactIconBase: { size: fontSizes[4] }
2016-12-20 19:20:56 +01:00
}
2016-12-17 16:43:25 +01:00
}
render() {
2016-12-17 19:58:30 +01:00
return <li
key={this.props.layerId}
onClick={e => this.props.onLayerSelect(this.props.layerId)}
2017-01-11 09:35:48 +01:00
className={classnames({
"maputnik-layer-list-item": true,
"maputnik-layer-list-item-selected": this.props.isSelected,
})}>
2016-12-20 19:20:56 +01:00
<LayerTypeDragHandle type={this.props.layerType} />
2017-01-10 21:28:30 +01:00
<span className="maputnik-layer-list-item-id">{this.props.layerId}</span>
2016-12-20 19:20:56 +01:00
<span style={{flexGrow: 1}} />
2017-01-11 09:35:48 +01:00
<IconAction
2016-12-20 19:20:56 +01:00
action={'delete'}
onClick={e => this.props.onLayerDestroy(this.props.layerId)}
2016-12-20 19:20:56 +01:00
/>
2017-01-11 09:35:48 +01:00
<IconAction
2016-12-20 19:20:56 +01:00
action={'copy'}
onClick={e => this.props.onLayerCopy(this.props.layerId)}
2016-12-20 19:20:56 +01:00
/>
2017-01-11 09:35:48 +01:00
<IconAction
action={this.props.visibility === 'visible' ? 'hide' : 'show'}
onClick={e => this.props.onLayerVisibilityToggle(this.props.layerId)}
2016-12-20 19:20:56 +01:00
/>
2016-12-17 19:58:30 +01:00
</li>
2016-12-17 16:43:25 +01:00
}
}
2016-12-20 19:20:56 +01:00
export default LayerListItem;