2016-12-30 18:13:41 +01:00
|
|
|
import React from 'react'
|
2016-12-30 20:53:12 +01:00
|
|
|
import AutocompleteInput from './AutocompleteInput'
|
2016-12-30 18:13:41 +01:00
|
|
|
|
|
|
|
class FontInput extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
value: React.PropTypes.array.isRequired,
|
2017-01-10 11:13:53 +01:00
|
|
|
fonts: React.PropTypes.array,
|
2016-12-30 18:13:41 +01:00
|
|
|
style: React.PropTypes.object,
|
|
|
|
onChange: React.PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
2017-01-10 11:13:53 +01:00
|
|
|
static defaultProps = {
|
|
|
|
fonts: []
|
|
|
|
}
|
|
|
|
|
2016-12-30 18:13:41 +01:00
|
|
|
get values() {
|
2016-12-30 18:56:16 +01:00
|
|
|
return this.props.value || this.props.default.slice(1) || []
|
2016-12-30 18:13:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
changeFont(idx, newValue) {
|
|
|
|
const changedValues = this.values.slice(0)
|
|
|
|
changedValues[idx] = newValue
|
|
|
|
this.props.onChange(changedValues)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const inputs = this.values.map((value, i) => {
|
2016-12-30 20:53:12 +01:00
|
|
|
return <AutocompleteInput
|
2016-12-30 18:13:41 +01:00
|
|
|
key={i}
|
|
|
|
value={value}
|
2017-01-10 11:13:53 +01:00
|
|
|
options={this.props.fonts.map(f => [f, f])}
|
2016-12-30 18:13:41 +01:00
|
|
|
onChange={this.changeFont.bind(this, i)}
|
|
|
|
/>
|
|
|
|
})
|
|
|
|
|
2017-01-11 14:03:48 +01:00
|
|
|
return <div className="maputnik-font">
|
2016-12-30 18:13:41 +01:00
|
|
|
{inputs}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FontInput
|