SearchForm.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import FormGroup from 'react-bootstrap/es/FormGroup';
  3. import Button from 'react-bootstrap/es/Button';
  4. import InputGroup from 'react-bootstrap/es/InputGroup';
  5. import SearchTypeahead from '../SearchTypeahead';
  6. // Header.SearchForm
  7. export default class SearchForm extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.crowi = window.crowi; // FIXME
  11. this.state = {
  12. searchError: null,
  13. };
  14. this.onSearchError = this.onSearchError.bind(this);
  15. this.onChange = this.onChange.bind(this);
  16. this.onSubmit = this.onSubmit.bind(this);
  17. }
  18. componentDidMount() {
  19. }
  20. componentWillUnmount() {
  21. }
  22. onSearchError(err) {
  23. this.setState({
  24. searchError: err,
  25. });
  26. }
  27. onChange(selected) {
  28. const page = selected[0]; // should be single page selected
  29. // navigate to page
  30. if (page != null) {
  31. window.location = page.path;
  32. }
  33. }
  34. onSubmit(query) {
  35. this.refs.form.submit(query);
  36. }
  37. render() {
  38. const emptyLabel = (this.state.searchError !== null)
  39. ? 'Error on searching.'
  40. : 'No matches found on title... Hit [Enter] key so that search on contents.';
  41. return (
  42. <form
  43. ref='form'
  44. action='/_search'
  45. className='search-form form-group input-group search-input-group'
  46. >
  47. <FormGroup>
  48. <InputGroup>
  49. <SearchTypeahead
  50. crowi={this.crowi}
  51. onChange={this.onChange}
  52. onSubmit={this.onSubmit}
  53. emptyLabel={emptyLabel}
  54. placeholder="Search ..."
  55. />
  56. <InputGroup.Button>
  57. <Button type="submit" bsStyle="link">
  58. <i className="icon-magnifier"></i>
  59. </Button >
  60. </InputGroup.Button>
  61. </InputGroup>
  62. </FormGroup>
  63. </form>
  64. );
  65. }
  66. }
  67. SearchForm.propTypes = {
  68. };
  69. SearchForm.defaultProps = {
  70. };