2016-12-20 11:44:22 +01:00
|
|
|
import React from 'react'
|
|
|
|
import Color from 'color'
|
|
|
|
|
2016-12-25 18:30:23 +01:00
|
|
|
import Button from '../Button'
|
2016-12-20 11:44:22 +01:00
|
|
|
import SpecField from './SpecField'
|
2016-12-25 19:00:21 +01:00
|
|
|
import DocLabel from './DocLabel'
|
2016-12-20 11:44:22 +01:00
|
|
|
|
2016-12-25 18:30:23 +01:00
|
|
|
import AddIcon from 'react-icons/lib/md/add-circle-outline'
|
|
|
|
import DeleteIcon from 'react-icons/lib/md/delete'
|
|
|
|
|
2016-12-20 11:44:22 +01:00
|
|
|
import input from '../../config/input.js'
|
|
|
|
import colors from '../../config/colors.js'
|
2016-12-25 18:30:23 +01:00
|
|
|
import { margins, fontSizes } from '../../config/scales.js'
|
2016-12-20 11:44:22 +01:00
|
|
|
|
|
|
|
function isZoomField(value) {
|
2016-12-20 16:08:49 +01:00
|
|
|
return typeof value === 'object' && value.stops
|
2016-12-20 11:44:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const specFieldProps = {
|
|
|
|
onChange: React.PropTypes.func.isRequired,
|
|
|
|
fieldName: React.PropTypes.string.isRequired,
|
|
|
|
fieldSpec: React.PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Supports displaying spec field for zoom function objects
|
|
|
|
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
|
|
|
*/
|
|
|
|
export default class ZoomSpecField extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
onChange: React.PropTypes.func.isRequired,
|
|
|
|
fieldName: React.PropTypes.string.isRequired,
|
|
|
|
fieldSpec: React.PropTypes.object.isRequired,
|
|
|
|
|
|
|
|
value: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.object,
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.number,
|
|
|
|
React.PropTypes.bool,
|
|
|
|
]),
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-12-25 19:00:21 +01:00
|
|
|
let label = <DocLabel
|
|
|
|
label={labelFromFieldName(this.props.fieldName)}
|
|
|
|
doc={this.props.fieldSpec.doc}
|
|
|
|
/>
|
2016-12-20 11:44:22 +01:00
|
|
|
|
|
|
|
if(isZoomField(this.props.value)) {
|
2016-12-25 18:30:23 +01:00
|
|
|
const zoomFields = this.props.value.stops.map((stop, idx) => {
|
|
|
|
label = <label style={{...input.label, width: '30%'}}>
|
|
|
|
{labelFromFieldName(this.props.fieldName)}
|
|
|
|
</label>
|
|
|
|
|
|
|
|
if(idx > 0) {
|
|
|
|
label = <label style={{...input.label, width: '30%'}}></label>
|
|
|
|
}
|
|
|
|
|
|
|
|
if(idx === 1) {
|
|
|
|
label = <label style={{...input.label, width: '30%'}}>
|
|
|
|
<Button style={{fontSize: fontSizes[5]}}>
|
|
|
|
Add stop
|
|
|
|
</Button>
|
|
|
|
</label>
|
|
|
|
}
|
|
|
|
|
2016-12-20 16:08:49 +01:00
|
|
|
const zoomLevel = stop[0]
|
|
|
|
const value = stop[1]
|
2016-12-20 11:44:22 +01:00
|
|
|
|
|
|
|
return <div style={input.property} key={zoomLevel}>
|
|
|
|
{label}
|
2016-12-25 18:30:23 +01:00
|
|
|
<Button style={{backgroundColor: null}}>
|
|
|
|
<DeleteIcon />
|
|
|
|
</Button>
|
2016-12-20 11:44:22 +01:00
|
|
|
<input
|
|
|
|
style={{
|
|
|
|
...input.input,
|
|
|
|
width: '10%',
|
|
|
|
}}
|
|
|
|
type="number"
|
|
|
|
value={zoomLevel}
|
|
|
|
min={0}
|
|
|
|
max={22}
|
|
|
|
/>
|
2016-12-25 18:30:23 +01:00
|
|
|
<SpecField {...this.props}
|
|
|
|
value={value}
|
|
|
|
style={{
|
|
|
|
width: '33%',
|
|
|
|
marginLeft: margins[0],
|
|
|
|
}}
|
|
|
|
/>
|
2016-12-20 11:44:22 +01:00
|
|
|
</div>
|
2016-12-20 16:08:49 +01:00
|
|
|
})
|
2016-12-25 18:30:23 +01:00
|
|
|
return <div style={input.property}>
|
2016-12-20 11:44:22 +01:00
|
|
|
{zoomFields}
|
|
|
|
</div>
|
|
|
|
} else {
|
|
|
|
return <div style={input.property}>
|
|
|
|
{label}
|
|
|
|
<SpecField {...this.props} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function labelFromFieldName(fieldName) {
|
|
|
|
let label = fieldName.split('-').slice(1).join(' ')
|
|
|
|
if(label.length > 0) {
|
|
|
|
label = label.charAt(0).toUpperCase() + label.slice(1);
|
|
|
|
}
|
|
|
|
return label
|
|
|
|
}
|