Hack together add and delete button for stops

This commit is contained in:
Lukas Martinelli 2016-12-25 18:30:23 +01:00
parent e1bc2a321a
commit 436e0c2095

View file

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import Color from 'color' import Color from 'color'
import Button from '../Button'
import NumberField from './NumberField' import NumberField from './NumberField'
import EnumField from './EnumField' import EnumField from './EnumField'
import BooleanField from './BooleanField' import BooleanField from './BooleanField'
@ -8,9 +9,12 @@ import ColorField from './ColorField'
import StringField from './StringField' import StringField from './StringField'
import SpecField from './SpecField' import SpecField from './SpecField'
import AddIcon from 'react-icons/lib/md/add-circle-outline'
import DeleteIcon from 'react-icons/lib/md/delete'
import input from '../../config/input.js' import input from '../../config/input.js'
import colors from '../../config/colors.js' import colors from '../../config/colors.js'
import { margins } from '../../config/scales.js' import { margins, fontSizes } from '../../config/scales.js'
function isZoomField(value) { function isZoomField(value) {
return typeof value === 'object' && value.stops return typeof value === 'object' && value.stops
@ -40,43 +44,56 @@ export default class ZoomSpecField extends React.Component {
} }
render() { render() {
const label = <label style={input.label}> let label = <label style={{...input.label}}>
{labelFromFieldName(this.props.fieldName)} {labelFromFieldName(this.props.fieldName)}
</label> </label>
if(isZoomField(this.props.value)) { if(isZoomField(this.props.value)) {
const zoomFields = this.props.value.stops.map(stop => { 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>
}
const zoomLevel = stop[0] const zoomLevel = stop[0]
const value = stop[1] const value = stop[1]
return <div style={input.property} key={zoomLevel}> return <div style={input.property} key={zoomLevel}>
{label} {label}
<SpecField {...this.props} <Button style={{backgroundColor: null}}>
value={value} <DeleteIcon />
style={{ </Button>
width: '33%'
}}
/>
<input <input
style={{ style={{
...input.input, ...input.input,
width: '10%', width: '10%',
marginLeft: margins[0],
}} }}
type="number" type="number"
value={zoomLevel} value={zoomLevel}
min={0} min={0}
max={22} max={22}
/> />
<SpecField {...this.props}
value={value}
style={{
width: '33%',
marginLeft: margins[0],
}}
/>
</div> </div>
}) })
return <div style={{ return <div style={input.property}>
border: 1,
borderStyle: 'solid',
borderColor: Color(colors.gray).lighten(0.1).string(),
padding: margins[1],
}}>
{zoomFields} {zoomFields}
</div> </div>
} else { } else {