SearchForm.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import FormGroup from 'react-bootstrap/es/FormGroup';
  4. import Button from 'react-bootstrap/es/Button';
  5. import InputGroup from 'react-bootstrap/es/InputGroup';
  6. import SearchTypeahead from '../SearchTypeahead';
  7. // Header.SearchForm
  8. export default class SearchForm extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.crowi = window.crowi; // FIXME
  12. this.state = {
  13. searchError: null,
  14. };
  15. this.onSearchError = this.onSearchError.bind(this);
  16. this.onChange = this.onChange.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. render() {
  35. const emptyLabel = (this.state.searchError !== null)
  36. ? 'Error on searching.'
  37. : 'No matches found on title... Hit [Enter] key so that search on contents.';
  38. return (
  39. <form
  40. action="/_search"
  41. className="search-form form-group input-group search-input-group"
  42. >
  43. <FormGroup>
  44. <InputGroup>
  45. <SearchTypeahead
  46. crowi={this.crowi}
  47. onChange={this.onChange}
  48. emptyLabel={emptyLabel}
  49. placeholder="Search ..."
  50. />
  51. <InputGroup.Button>
  52. <Button type="submit" bsStyle="link">
  53. <i className="icon-magnifier"></i>
  54. </Button >
  55. </InputGroup.Button>
  56. </InputGroup>
  57. </FormGroup>
  58. </form>
  59. );
  60. }
  61. }
  62. SearchForm.propTypes = {
  63. };
  64. SearchForm.defaultProps = {
  65. };