SearchForm.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import UserPicture from '../User/UserPicture';
  7. import PageListMeta from '../PageList/PageListMeta';
  8. import PagePath from '../PageList/PagePath';
  9. import PropTypes from 'prop-types';
  10. // Header.SearchForm
  11. export default class SearchForm extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.crowi = window.crowi; // FIXME
  15. this.state = {
  16. searchError: null,
  17. };
  18. this.onSearchError = this.onSearchError.bind(this);
  19. this.onChange = this.onChange.bind(this);
  20. }
  21. componentDidMount() {
  22. }
  23. componentWillUnmount() {
  24. }
  25. onSearchError(err) {
  26. this.setState({
  27. searchError: err,
  28. });
  29. }
  30. onChange(selected) {
  31. const page = selected[0]; // should be single page selected
  32. // navigate to page
  33. if (page != null) {
  34. window.location = page.path;
  35. }
  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. action="/_search"
  44. className="search-form form-group input-group search-top-input-group"
  45. >
  46. <FormGroup>
  47. <InputGroup>
  48. <SearchTypeahead
  49. crowi={this.crowi}
  50. onChange={this.onChange}
  51. emptyLabel={emptyLabel}
  52. placeholder="Search ..."
  53. />
  54. <InputGroup.Button>
  55. <Button type="submit">
  56. <i className="search-top-icon fa fa-search"></i>
  57. </Button >
  58. </InputGroup.Button>
  59. </InputGroup>
  60. </FormGroup>
  61. </form>
  62. );
  63. }
  64. }
  65. SearchForm.propTypes = {
  66. };
  67. SearchForm.defaultProps = {
  68. };