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

56 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-01-05 19:12:31 +02:00
const React = require('react');
const Select = require('react-select');
2017-01-06 12:56:19 +02:00
const SelectAsync = Select.Async
2017-01-05 19:12:31 +02:00
const SearchAsync = React.createClass({
getInitialState: function() {
return {
selectValue: ''
}
},
updateValue: function(newValue) {
console.log('State changed to ' + newValue);
this.setState({
selectValue: newValue
});
},
2017-01-06 12:56:19 +02:00
options: function(input, callback) {
setTimeout(function() {
callback(null, {
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' },
],
// CAREFUL! Only set this to true when there are no more options,
// or more specific queries will not be sent to the server.
complete: true
}, 10000);
});
},
2017-01-05 19:12:31 +02:00
2017-01-06 12:56:19 +02:00
render: function () {
2017-01-05 19:12:31 +02:00
return (
<div>
<h1> Async Search </h1>
<SelectAsync
2017-01-06 12:56:19 +02:00
ref="stateSelectAsync"
loadOptions={this.options}
2017-01-05 19:12:31 +02:00
value={this.state.selectValue}
onChange={this.updateValue}
2017-01-06 12:56:19 +02:00
multi={true}
2017-01-05 19:12:31 +02:00
/>
</div>
)
}
})
module.exports = SearchAsync