maputnik/src/components/inputs/AutocompleteInput.jsx

70 lines
1.7 KiB
React
Raw Normal View History

import React from 'react'
import Autocomplete from 'react-autocomplete'
import input from '../../config/input'
import colors from '../../config/colors'
import { margins, fontSizes } from '../../config/scales'
class AutocompleteInput extends React.Component {
static propTypes = {
2016-12-31 10:39:30 +01:00
value: React.PropTypes.string,
options: React.PropTypes.array,
2016-12-31 12:17:02 +01:00
wrapperStyle: React.PropTypes.object,
inputStyle: React.PropTypes.object,
2016-12-31 10:39:30 +01:00
onChange: React.PropTypes.func,
}
static defaultProps = {
onChange: () => {},
options: [],
}
render() {
return <Autocomplete
2017-01-10 21:28:30 +01:00
className="maputnik-autocomplete"
menuStyle={{
border: 'none',
padding: '2px 0',
position: 'fixed',
overflow: 'auto',
maxHeight: '50%',
background: colors.gray,
zIndex: 3,
}}
2016-12-31 12:17:02 +01:00
wrapperStyle={{
display: 'inline-block',
...this.props.wrapperStyle
}}
inputProps={{
style: {
...input.input,
2016-12-31 12:17:02 +01:00
width: '100%',
...this.props.inputStyle,
}
}}
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]}
style={{
userSelect: 'none',
color: colors.lowgray,
2016-12-30 20:53:12 +01:00
cursor: 'default',
background: isHighlighted ? colors.midgray : colors.gray,
padding: margins[0],
fontSize: fontSizes[5],
zIndex: 3,
}}
>
{item[1]}
</div>
)}
/>
}
}
export default AutocompleteInput