joyent-portal/spikes/fuzzy-search/react-select/src/search.js

49 lines
939 B
JavaScript
Raw Normal View History

2017-01-05 18:26:17 +02:00
const React = require('react');
2017-01-05 19:12:31 +02:00
const Select = require('react-select');
2017-01-05 18:26:17 +02:00
2017-01-05 19:12:31 +02:00
const Search = React.createClass({
2017-01-05 18:26:17 +02:00
2017-01-05 19:12:31 +02:00
getInitialState: function() {
return {
selectValue: ''
}
},
updateValue: function(newValue) {
console.log('State changed to ' + newValue);
this.setState({
selectValue: newValue
});
},
render: function () {
var options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' },
{ value: 'three', label: 'Three' },
{ value: 'four', label: 'Four' },
{ value: 'five', label: 'Five' },
{ value: 'six', label: 'Six' },
];
return (
<div>
<h1> {this.props.multi ? 'Multi' : 'Single'} Search </h1>
<Select
ref="stateSelect"
2017-01-06 12:56:19 +02:00
className="is-open"
2017-01-05 19:12:31 +02:00
autofocus
options={options}
name="selected-state"
value={this.state.selectValue}
onChange={this.updateValue}
multi={this.props.multi}
/>
</div>
)
}
})
2017-01-05 18:26:17 +02:00
module.exports = Search