SearchForm.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  17. componentDidMount() {
  18. }
  19. componentWillUnmount() {
  20. }
  21. onSearchError(err) {
  22. this.setState({
  23. searchError: err,
  24. });
  25. }
  26. onChange(selected) {
  27. const page = selected[0]; // should be single page selected
  28. // navigate to page
  29. if (page != null) {
  30. window.location = page.path;
  31. }
  32. }
  33. render() {
  34. const emptyLabel = (this.state.searchError !== null)
  35. ? 'Error on searching.'
  36. : 'No matches found on title... Hit [Enter] key so that search on contents.';
  37. return (
  38. <form
  39. action="/_search"
  40. className="search-form form-group input-group search-input-group"
  41. >
  42. <FormGroup>
  43. <InputGroup>
  44. <SearchTypeahead
  45. crowi={this.crowi}
  46. onChange={this.onChange}
  47. emptyLabel={emptyLabel}
  48. placeholder="Search ..."
  49. />
  50. <InputGroup.Button>
  51. <Button type="submit" bsStyle="link">
  52. <i className="icon-magnifier"></i>
  53. </Button >
  54. </InputGroup.Button>
  55. </InputGroup>
  56. </FormGroup>
  57. </form>
  58. );
  59. }
  60. }
  61. SearchForm.propTypes = {
  62. };
  63. SearchForm.defaultProps = {
  64. };