maputnik/src/components/layers/LayerEditorGroup.jsx

64 lines
1.8 KiB
React
Raw Normal View History

2016-12-21 11:24:32 +01:00
import React from 'react'
2016-12-22 12:06:04 +01:00
import Color from 'color'
2016-12-21 11:24:32 +01:00
import colors from '../../config/colors'
import { margins, fontSizes } from '../../config/scales'
2016-12-22 11:52:21 +01:00
import Collapse from 'react-collapse'
2016-12-21 11:24:32 +01:00
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 ? <CollapseCloseIcon style={iconStyle}/> : <CollapseOpenIcon style={iconStyle} />
}
}
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
}
2016-12-22 12:06:04 +01:00
constructor(props) {
super(props)
this.state = { hover: false }
}
2016-12-21 11:24:32 +01:00
render() {
2016-12-21 11:27:49 +01:00
return <div>
2016-12-21 11:24:32 +01:00
<div style={{
fontSize: fontSizes[4],
2016-12-22 12:06:04 +01:00
backgroundColor: this.state.hover ? Color(colors.black).lighten(0.30).string() : Color(colors.black).lighten(0.15).string(),
2016-12-21 11:24:32 +01:00
color: colors.lowgray,
2016-12-22 12:06:04 +01:00
cursor: 'pointer',
userSelect: 'none',
2016-12-21 11:24:32 +01:00
padding: margins[1],
display: 'flex',
flexDirection: 'row',
lineHeight: '20px',
2016-12-21 11:27:49 +01:00
}}
2016-12-22 12:06:04 +01:00
onMouseOver={e => this.setState({hover: true})}
onMouseOut={e => this.setState({hover: false})}
2016-12-21 11:27:49 +01:00
onClick={e => this.props.onActiveToggle(!this.props.isActive)}
>
2016-12-21 11:24:32 +01:00
<span>{this.props.title}</span>
<span style={{flexGrow: 1}} />
<Collapser isCollapsed={this.props.isActive} />
</div>
2016-12-22 12:06:04 +01:00
<Collapse isOpened={this.props.isActive}>
{this.props.children}
</Collapse>
2016-12-21 11:24:32 +01:00
</div>
}
}