mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-15 09:21:19 +01:00
Support updating of ArrayInput #39
This commit is contained in:
parent
e00cdde3af
commit
b0e9790382
1 changed files with 26 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import input from '../../config/input.js'
|
import input from '../../config/input.js'
|
||||||
import StringInput from './StringInput'
|
import StringInput from './StringInput'
|
||||||
import NumberInput from './StringInput'
|
import NumberInput from './NumberInput'
|
||||||
|
|
||||||
import { margins } from '../../config/scales.js'
|
import { margins } from '../../config/scales.js'
|
||||||
|
|
||||||
|
@ -15,17 +15,38 @@ class ArrayInput extends React.Component {
|
||||||
onChange: React.PropTypes.func,
|
onChange: React.PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeValue(idx, newValue) {
|
||||||
|
console.log(idx, newValue)
|
||||||
|
const values = this.values.slice(0)
|
||||||
|
values[idx] = newValue
|
||||||
|
this.props.onChange(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
get values() {
|
||||||
|
return this.props.value || this.props.default || []
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const values = this.props.value || this.props.default || []
|
|
||||||
const commonStyle = {
|
const commonStyle = {
|
||||||
width: '49%',
|
width: '49%',
|
||||||
marginRight: '1%',
|
marginRight: '1%',
|
||||||
}
|
}
|
||||||
const inputs = values.map((v, i) => {
|
const inputs = this.values.map((v, i) => {
|
||||||
if(this.props.type === 'number') {
|
if(this.props.type === 'number') {
|
||||||
return <NumberInput key={i} value={v} style={commonStyle} />
|
return <NumberInput
|
||||||
|
key={i}
|
||||||
|
value={v}
|
||||||
|
style={commonStyle}
|
||||||
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
/>
|
||||||
|
} else {
|
||||||
|
return <StringInput
|
||||||
|
key={i}
|
||||||
|
value={v}
|
||||||
|
style={commonStyle}
|
||||||
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
return <StringInput key={i} value={v} style={commonStyle} />
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return <div style={{display: 'inline-block', width: '50%'}}>
|
return <div style={{display: 'inline-block', width: '50%'}}>
|
||||||
|
|
Loading…
Reference in a new issue