mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-31 00:20:32 +01:00
Added default support to <ArrayInput/>
This commit is contained in:
parent
201ecac156
commit
92ee50a4a4
1 changed files with 11 additions and 8 deletions
|
@ -12,29 +12,32 @@ class ArrayInput extends React.Component {
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
value: [],
|
||||||
|
default: [],
|
||||||
|
}
|
||||||
|
|
||||||
changeValue(idx, newValue) {
|
changeValue(idx, newValue) {
|
||||||
console.log(idx, newValue)
|
console.log(idx, newValue)
|
||||||
const values = this.values.slice(0)
|
const values = this.props.value.slice(0)
|
||||||
values[idx] = newValue
|
values[idx] = newValue
|
||||||
this.props.onChange(values)
|
this.props.onChange(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
get values() {
|
|
||||||
return this.props.value || this.props.default || []
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const inputs = this.values.map((v, i) => {
|
const inputs = Array(this.props.length).fill(null).map((_, i) => {
|
||||||
if(this.props.type === 'number') {
|
if(this.props.type === 'number') {
|
||||||
return <NumberInput
|
return <NumberInput
|
||||||
key={i}
|
key={i}
|
||||||
value={v}
|
default={this.props.default[i]}
|
||||||
|
value={this.props.value[i]}
|
||||||
onChange={this.changeValue.bind(this, i)}
|
onChange={this.changeValue.bind(this, i)}
|
||||||
/>
|
/>
|
||||||
} else {
|
} else {
|
||||||
return <StringInput
|
return <StringInput
|
||||||
key={i}
|
key={i}
|
||||||
value={v}
|
default={this.props.default[i]}
|
||||||
|
value={this.props.value[i]}
|
||||||
onChange={this.changeValue.bind(this, i)}
|
onChange={this.changeValue.bind(this, i)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue