2016-12-17 16:43:25 +01:00
|
|
|
import React from 'react'
|
2017-11-06 16:32:04 +01:00
|
|
|
import PropTypes from 'prop-types'
|
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'
|
|
|
|
|
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',
|
2017-01-11 14:11:45 +01:00
|
|
|
width: 14,
|
|
|
|
height: 14,
|
|
|
|
paddingRight: 3,
|
2016-12-22 13:40:23 +01:00
|
|
|
}}
|
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 = {
|
2017-11-06 16:32:04 +01:00
|
|
|
action: PropTypes.string.isRequired,
|
|
|
|
onClick: PropTypes.func.isRequired,
|
2018-01-05 18:45:55 +01:00
|
|
|
wdKey: PropTypes.string
|
2016-12-20 19:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderIcon() {
|
|
|
|
switch(this.props.action) {
|
2018-05-22 22:16:46 +02:00
|
|
|
case 'duplicate': return <CopyIcon />
|
2017-01-11 09:35:48 +01:00
|
|
|
case 'show': return <VisibilityIcon />
|
|
|
|
case 'hide': return <VisibilityOffIcon />
|
|
|
|
case 'delete': return <DeleteIcon />
|
2016-12-20 19:20:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-05-22 22:16:46 +02:00
|
|
|
return <button
|
|
|
|
tabIndex="-1"
|
|
|
|
title={this.props.action}
|
2017-01-11 15:48:15 +01:00
|
|
|
className="maputnik-layer-list-icon-action"
|
2018-01-05 18:45:55 +01:00
|
|
|
data-wd-key={this.props.wdKey}
|
2016-12-20 20:21:35 +01:00
|
|
|
onClick={this.props.onClick}
|
2016-12-20 19:20:56 +01:00
|
|
|
>
|
|
|
|
{this.renderIcon()}
|
2018-05-22 22:16:46 +02:00
|
|
|
</button>
|
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 = {
|
2017-11-06 16:32:04 +01:00
|
|
|
layerId: PropTypes.string.isRequired,
|
|
|
|
layerType: PropTypes.string.isRequired,
|
|
|
|
isSelected: PropTypes.bool,
|
|
|
|
visibility: PropTypes.string,
|
|
|
|
className: PropTypes.string,
|
2016-12-20 19:20:56 +01:00
|
|
|
|
2017-11-06 16:32:04 +01:00
|
|
|
onLayerSelect: PropTypes.func.isRequired,
|
|
|
|
onLayerCopy: PropTypes.func,
|
|
|
|
onLayerDestroy: PropTypes.func,
|
|
|
|
onLayerVisibilityToggle: PropTypes.func,
|
2016-12-20 19:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
isSelected: false,
|
2016-12-20 20:21:35 +01:00
|
|
|
visibility: 'visible',
|
|
|
|
onLayerCopy: () => {},
|
|
|
|
onLayerDestroy: () => {},
|
|
|
|
onLayerVisibilityToggle: () => {},
|
2016-12-20 19:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static childContextTypes = {
|
2017-11-06 16:32:04 +01:00
|
|
|
reactIconBase: PropTypes.object
|
2016-12-20 19:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getChildContext() {
|
|
|
|
return {
|
2017-01-11 14:11:45 +01:00
|
|
|
reactIconBase: { size: 14 }
|
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}
|
2016-12-20 20:21:35 +01:00
|
|
|
onClick={e => this.props.onLayerSelect(this.props.layerId)}
|
2018-01-05 18:45:55 +01:00
|
|
|
data-wd-key={"layer-list-item:"+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,
|
2017-01-11 18:18:47 +01:00
|
|
|
[this.props.className]: true,
|
2017-01-11 09:35:48 +01:00
|
|
|
})}>
|
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
|
2018-01-05 18:45:55 +01:00
|
|
|
wdKey={"layer-list-item:"+this.props.layerId+":delete"}
|
2016-12-20 19:20:56 +01:00
|
|
|
action={'delete'}
|
2016-12-20 20:21:35 +01:00
|
|
|
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
|
2018-01-05 18:45:55 +01:00
|
|
|
wdKey={"layer-list-item:"+this.props.layerId+":copy"}
|
2018-05-22 22:16:46 +02:00
|
|
|
action={'duplicate'}
|
2016-12-20 20:21:35 +01:00
|
|
|
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
|
2018-01-05 18:45:55 +01:00
|
|
|
wdKey={"layer-list-item:"+this.props.layerId+":toggle-visibility"}
|
2016-12-20 20:21:35 +01:00
|
|
|
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;
|