mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-14 20:23:27 +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 input from '../../config/input.js'
|
||||
import StringInput from './StringInput'
|
||||
import NumberInput from './StringInput'
|
||||
import NumberInput from './NumberInput'
|
||||
|
||||
import { margins } from '../../config/scales.js'
|
||||
|
||||
|
@ -15,17 +15,38 @@ class ArrayInput extends React.Component {
|
|||
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() {
|
||||
const values = this.props.value || this.props.default || []
|
||||
const commonStyle = {
|
||||
width: '49%',
|
||||
marginRight: '1%',
|
||||
}
|
||||
const inputs = values.map((v, i) => {
|
||||
const inputs = this.values.map((v, i) => {
|
||||
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%'}}>
|
||||
|
|
Loading…
Reference in a new issue