Introduce doc label for help

This commit is contained in:
Lukas Martinelli 2016-12-25 19:00:21 +01:00
parent 436e0c2095
commit beb1a2a8d1
3 changed files with 56 additions and 4 deletions

View file

@ -0,0 +1,49 @@
import React from 'react'
import input from '../../config/input.js'
import colors from '../../config/colors.js'
import { margins, fontSizes } from '../../config/scales.js'
export default class DocLabel extends React.Component {
static propTypes = {
label: React.PropTypes.string.isRequired,
doc: React.PropTypes.string.isRequired,
style: React.PropTypes.object,
}
constructor(props) {
super(props)
this.state = { showDoc: false }
}
render() {
return <label
style={{
...input.label,
...this.props.style,
position: 'relative',
}}
>
<span
onMouseOver={e => this.setState({showDoc: true})}
onMouseOut={e => this.setState({showDoc: false})}
style={{
cursor: 'help',
}}
>
{this.props.label}
</span>
<div style={{
backgroundColor: colors.gray,
padding: margins[1],
position: 'absolute',
top: 20,
left: 0,
width: 100,
display: this.state.showDoc ? null : 'none',
zIndex: 3,
}}>
{this.props.doc}
</div>
</label>
}
}

View file

@ -1,5 +1,5 @@
import React from 'react'
import GlSpec from 'mapbox-gl-style-spec/reference/latest.min.js'
import GlSpec from 'mapbox-gl-style-spec/reference/latest.js'
import ZoomSpecField from './ZoomSpecField'
import colors from '../../config/colors'

View file

@ -8,6 +8,7 @@ import BooleanField from './BooleanField'
import ColorField from './ColorField'
import StringField from './StringField'
import SpecField from './SpecField'
import DocLabel from './DocLabel'
import AddIcon from 'react-icons/lib/md/add-circle-outline'
import DeleteIcon from 'react-icons/lib/md/delete'
@ -44,9 +45,11 @@ export default class ZoomSpecField extends React.Component {
}
render() {
let label = <label style={{...input.label}}>
{labelFromFieldName(this.props.fieldName)}
</label>
console.log(this.props.fieldSpec)
let label = <DocLabel
label={labelFromFieldName(this.props.fieldName)}
doc={this.props.fieldSpec.doc}
/>
if(isZoomField(this.props.value)) {
const zoomFields = this.props.value.stops.map((stop, idx) => {