maputnik/src/components/inputs/AutocompleteInput.jsx

52 lines
1.3 KiB
React
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
2017-01-11 14:03:48 +01:00
import classnames from 'classnames'
import Autocomplete from 'react-autocomplete'
2017-01-11 14:03:48 +01:00
class AutocompleteInput extends React.Component {
static propTypes = {
value: PropTypes.string,
options: PropTypes.array,
onChange: PropTypes.func,
2016-12-31 10:39:30 +01:00
}
static defaultProps = {
onChange: () => {},
options: [],
}
render() {
2017-11-08 09:47:36 +01:00
const AutocompleteMenu = (items, value, style) => <div className={"maputnik-autocomplete-menu"}>{items}</div>
2017-01-11 14:03:48 +01:00
return <Autocomplete
2017-01-11 13:34:38 +01:00
wrapperProps={{
className: "maputnik-autocomplete",
style: null
}}
2017-01-11 14:03:48 +01:00
renderMenu={AutocompleteMenu}
inputProps={{
2017-01-11 13:34:38 +01:00
className: "maputnik-string"
}}
value={this.props.value}
items={this.props.options}
getItemValue={(item) => item[0]}
onSelect={v => this.props.onChange(v)}
onChange={(e, v) => this.props.onChange(v)}
renderItem={(item, isHighlighted) => (
<div
key={item[0]}
2017-01-11 14:03:48 +01:00
className={classnames({
"maputnik-autocomplete-menu-item": true,
"maputnik-autocomplete-menu-item-selected": isHighlighted,
})}
>
{item[1]}
</div>
)}
/>
}
}
export default AutocompleteInput