2016-12-30 20:38:50 +01:00
|
|
|
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 = {
|
|
|
|
value: React.PropTypes.string.isRequired,
|
|
|
|
options: React.PropTypes.array.isRequired,
|
|
|
|
style: React.PropTypes.object,
|
|
|
|
onChange: React.PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-12-30 20:46:27 +01:00
|
|
|
return <Autocomplete
|
|
|
|
menuStyle={{
|
|
|
|
border: 'none',
|
2016-12-30 20:38:50 +01:00
|
|
|
padding: '2px 0',
|
|
|
|
position: 'fixed',
|
|
|
|
overflow: 'auto',
|
|
|
|
maxHeight: '50%',
|
2016-12-30 20:46:27 +01:00
|
|
|
background: colors.gray,
|
|
|
|
zIndex: 3,
|
|
|
|
}}
|
|
|
|
inputProps={{
|
2016-12-30 20:38:50 +01:00
|
|
|
style: {
|
2016-12-30 20:46:27 +01:00
|
|
|
...input.input,
|
|
|
|
width: null,
|
2016-12-30 20:38:50 +01:00
|
|
|
...this.props.style,
|
2016-12-30 20:46:27 +01:00
|
|
|
}
|
|
|
|
}}
|
2016-12-30 20:38:50 +01:00
|
|
|
value={this.props.value}
|
2016-12-30 20:46:27 +01:00
|
|
|
items={this.props.options}
|
|
|
|
getItemValue={(item) => item[0]}
|
|
|
|
onSelect={v => this.props.onChange(v)}
|
2016-12-30 20:38:50 +01:00
|
|
|
onChange={(e, v) => this.props.onChange(v)}
|
2016-12-30 20:46:27 +01:00
|
|
|
renderItem={(item, isHighlighted) => (
|
|
|
|
<div
|
|
|
|
key={item[0]}
|
|
|
|
style={{
|
|
|
|
userSelect: 'none',
|
|
|
|
color: colors.lowgray,
|
2016-12-30 20:53:12 +01:00
|
|
|
cursor: 'default',
|
2016-12-30 20:46:27 +01:00
|
|
|
background: isHighlighted ? colors.midgray : colors.gray,
|
|
|
|
padding: margins[0],
|
|
|
|
fontSize: fontSizes[5],
|
|
|
|
zIndex: 3,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{item[1]}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
/>
|
2016-12-30 20:38:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AutocompleteInput
|