2015-11-26 16:07:11 +08:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2015-12-23 23:12:20 +08:00
|
|
|
import Icon from '../icon';
|
2015-11-25 23:17:06 +08:00
|
|
|
function noop() {
|
|
|
|
}
|
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
class Search extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
2015-11-25 23:17:06 +08:00
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
handleChange(e) {
|
|
|
|
this.props.onChange(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2015-12-16 23:02:49 +08:00
|
|
|
const {placeholder, value, prefixCls} = this.props;
|
2015-12-17 16:08:16 +08:00
|
|
|
return <div>
|
2015-12-21 15:29:02 +08:00
|
|
|
<input placeholder={placeholder} className={ prefixCls + ' ant-input' } value={ value } ref="input"
|
|
|
|
onChange={this.handleChange.bind(this)}/>
|
2015-12-17 16:08:16 +08:00
|
|
|
{ value && value.length > 0 ?
|
2015-12-23 23:12:20 +08:00
|
|
|
<a href="javascirpt:;" className={ prefixCls + '-action' } onClick={this.props.handleClear}>
|
|
|
|
<Icon type="cross-circle" />
|
|
|
|
</a>
|
|
|
|
: <span className={ prefixCls + '-action' }><Icon type="search" /></span>
|
2015-12-17 16:08:16 +08:00
|
|
|
}
|
|
|
|
</div>;
|
2015-11-25 23:17:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
Search.defaultProps = {
|
|
|
|
placeholder: '请输入搜索内容',
|
2015-11-25 23:17:06 +08:00
|
|
|
onChange: noop,
|
|
|
|
};
|
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
Search.propTypes = {
|
2015-11-25 23:17:06 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2015-11-26 16:07:11 +08:00
|
|
|
placeholder: PropTypes.string,
|
|
|
|
onChange: PropTypes.func
|
2015-11-25 23:17:06 +08:00
|
|
|
};
|
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
export default Search;
|