/** * @author oldj * @blog https://oldj.net */ 'use strict' import React from 'react' import { Icon, Input, Button, Row, Col } from 'antd' import Agent from '../Agent' import styles from './SearchBar.less' export default class SearchBar extends React.Component { constructor (props) { super(props) this.state = { kw: undefined, current: 0, count: 0, cursor: null, has_previous: false, has_next: false, pos: [] } } gotoPrevious () { Agent.emit('search:goto_previous') } gotoNext () { Agent.emit('search:goto_next') } doSearch () { clearTimeout(this._t) this._t = setTimeout(() => { Agent.emit('search:kw', this.state.kw) }, 300) } searchEnd () { Agent.emit('search:kw', '') Agent.emit('search:end') this.setState({kw: undefined}) } componentDidMount () { this.refs.ipt.focus() Agent.on('search:state', d => this.setState({...d})) Agent.on('search:start', () => { let ipt = this.refs.ipt ipt && ipt.focus() }) } render () { let {kw, count, has_previous, has_next} = this.state let {lang} = this.props return (
this.setState({kw: e.target.value}, () => this.doSearch())} placeholder={lang.search_placeholder} allowClear={true} //onPressEnter={this.gotoNext.bind(this)} prefix={} onKeyDown={e => { let ne = e.nativeEvent if (ne.keyCode === 27) { // esc this.searchEnd() } else if (ne.keyCode === 13 && ne.shiftKey) { this.gotoPrevious() } else if (ne.keyCode === 13) { this.gotoNext() } }} />
) } }