SearchForm.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. getHelpElement() {
  34. return <table className="table m-1">
  35. <caption className="text-left text-primary p-2 pb-2">
  36. <h5 className="m-1"><i className="icon-magnifier pr-2"/>Search Help</h5>
  37. </caption>
  38. <tr>
  39. <td className="text-right mt-0 p-1 "><code>keyword</code></td>
  40. <th><h6 className="m-0 pt-1">記事名 or 本文に<samp>"keyword"</samp>を含む</h6></th>
  41. </tr>
  42. <tr>
  43. <td className="text-right mt-0 p-1"><code>title:keyword</code></td>
  44. <th><h6 className="m-0 pt-1">記事名に<samp>"keyword"</samp>を含む</h6></th>
  45. </tr>
  46. <tr>
  47. <td className="text-right mt-0 p-1"><code>a b</code></td>
  48. <th><h6 className="m-0 pt-1">文字列<samp>"a"</samp>と<samp>"b"</samp>を含む (スペース区切り)</h6></th>
  49. </tr>
  50. <tr>
  51. <td className="text-right mt-0 p-1"><code>-keyword</code></td>
  52. <th><h6 className="m-0 pt-1">文字列<samp>"keyword"</samp>を含まない</h6></th>
  53. </tr>
  54. </table>;
  55. }
  56. render() {
  57. const emptyLabel = (this.state.searchError !== null)
  58. ? 'Error on searching.'
  59. : 'No matches found on title... Hit [Enter] key so that search on contents.';
  60. return (
  61. <form
  62. action="/_search"
  63. className="search-form form-group input-group search-input-group"
  64. >
  65. <FormGroup>
  66. <InputGroup>
  67. <SearchTypeahead
  68. crowi={this.crowi}
  69. onChange={this.onChange}
  70. emptyLabel={emptyLabel}
  71. placeholder="Search ..."
  72. promptText={this.getHelpElement()}
  73. />
  74. <InputGroup.Button>
  75. <Button type="submit" bsStyle="link">
  76. <i className="icon-magnifier"></i>
  77. </Button >
  78. </InputGroup.Button>
  79. </InputGroup>
  80. </FormGroup>
  81. </form>
  82. );
  83. }
  84. }
  85. SearchForm.propTypes = {
  86. };
  87. SearchForm.defaultProps = {
  88. };