| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import React from 'react';
- import FormGroup from 'react-bootstrap/es/FormGroup';
- import Button from 'react-bootstrap/es/Button';
- import InputGroup from 'react-bootstrap/es/InputGroup';
- import SearchTypeahead from '../SearchTypeahead';
- // Header.SearchForm
- export default class SearchForm extends React.Component {
- constructor(props) {
- super(props);
- this.crowi = window.crowi; // FIXME
- this.state = {
- searchError: null,
- };
- this.onSearchError = this.onSearchError.bind(this);
- this.onChange = this.onChange.bind(this);
- this.onSubmit = this.onSubmit.bind(this);
- }
- componentDidMount() {
- }
- componentWillUnmount() {
- }
- onSearchError(err) {
- this.setState({
- searchError: err,
- });
- }
- onChange(selected) {
- const page = selected[0]; // should be single page selected
- // navigate to page
- if (page != null) {
- window.location = page.path;
- }
- }
- onSubmit(query) {
- this.refs.form.submit(query);
- }
- render() {
- const emptyLabel = (this.state.searchError !== null)
- ? 'Error on searching.'
- : 'No matches found on title... Hit [Enter] key so that search on contents.';
- return (
- <form
- ref='form'
- action='/_search'
- className='search-form form-group input-group search-input-group'
- >
- <FormGroup>
- <InputGroup>
- <SearchTypeahead
- crowi={this.crowi}
- onChange={this.onChange}
- onSubmit={this.onSubmit}
- emptyLabel={emptyLabel}
- placeholder="Search ..."
- />
- <InputGroup.Button>
- <Button type="submit" bsStyle="link">
- <i className="icon-magnifier"></i>
- </Button >
- </InputGroup.Button>
- </InputGroup>
- </FormGroup>
- </form>
- );
- }
- }
- SearchForm.propTypes = {
- };
- SearchForm.defaultProps = {
- };
|