mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-03-24 09:45:46 +01:00
36 lines
931 B
JavaScript
36 lines
931 B
JavaScript
import React from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import classnames from 'classnames'
|
|
import Button from '../Button'
|
|
|
|
class MultiButtonInput extends React.Component {
|
|
static propTypes = {
|
|
value: PropTypes.string.isRequired,
|
|
options: PropTypes.array.isRequired,
|
|
onChange: PropTypes.func.isRequired,
|
|
}
|
|
|
|
render() {
|
|
let options = this.props.options
|
|
if(options.length > 0 && !Array.isArray(options[0])) {
|
|
options = options.map(v => [v, v])
|
|
}
|
|
|
|
const selectedValue = this.props.value || options[0][0]
|
|
const buttons = options.map(([val, label])=> {
|
|
return <Button
|
|
key={val}
|
|
onClick={e => this.props.onChange(val)}
|
|
className={classnames({"maputnik-button-selected": val === selectedValue})}
|
|
>
|
|
{label}
|
|
</Button>
|
|
})
|
|
|
|
return <div className="maputnik-multibutton">
|
|
{buttons}
|
|
</div>
|
|
}
|
|
}
|
|
|
|
export default MultiButtonInput
|