2016-11-10 21:03:12 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-11-29 20:55:31 +00:00
|
|
|
import {debounce} from '../../../common/misc';
|
2016-11-10 21:03:12 +00:00
|
|
|
|
|
|
|
class DebouncedInput extends Component {
|
2016-11-29 20:55:31 +00:00
|
|
|
_handleValueChange = debounce(this.props.onChange, 500);
|
|
|
|
_handleChange = e => this._handleValueChange(e.target.value);
|
2016-11-10 21:03:12 +00:00
|
|
|
|
|
|
|
render () {
|
|
|
|
// NOTE: Strip out onChange because we're overriding it
|
2016-11-29 20:55:31 +00:00
|
|
|
const {onChange, textarea, ...props} = this.props;
|
|
|
|
if (textarea) {
|
|
|
|
return (
|
|
|
|
<textarea {...props} onChange={this._handleChange}/>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<input {...props} onChange={this._handleChange}/>
|
|
|
|
)
|
|
|
|
}
|
2016-11-10 21:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DebouncedInput.propTypes = {
|
2016-11-29 20:55:31 +00:00
|
|
|
// Required
|
2016-11-10 21:03:12 +00:00
|
|
|
onChange: PropTypes.func.isRequired,
|
2016-11-29 20:55:31 +00:00
|
|
|
|
|
|
|
// Optional
|
|
|
|
textarea: PropTypes.bool,
|
2016-11-10 21:03:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DebouncedInput;
|