2016-03-26 17:22:39 +08:00
|
|
|
import React, { 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() {
|
|
|
|
}
|
|
|
|
|
2016-03-26 17:22:39 +08:00
|
|
|
export default class Search extends React.Component {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
placeholder: '',
|
|
|
|
onChange: noop,
|
|
|
|
handleClear: noop,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
placeholder: PropTypes.string,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
handleClear: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:50:44 +08:00
|
|
|
handleChange = (e) => {
|
2015-11-26 16:07:11 +08:00
|
|
|
this.props.onChange(e);
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:50:44 +08:00
|
|
|
handleClear = (e) => {
|
2016-01-13 16:28:36 +08:00
|
|
|
e.preventDefault();
|
|
|
|
this.props.handleClear(e);
|
|
|
|
}
|
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
render() {
|
2016-01-07 17:46:46 +08:00
|
|
|
const { placeholder, value, prefixCls } = this.props;
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-04-29 12:13:27 +08:00
|
|
|
<input placeholder={placeholder} className={`${prefixCls} ant-input`} value={value} ref="input"
|
2016-03-23 19:50:44 +08:00
|
|
|
onChange={this.handleChange} />
|
2016-04-29 12:13:27 +08:00
|
|
|
{value && value.length > 0 ?
|
|
|
|
<a href="#" className={`${prefixCls}-action`} onClick={this.handleClear}>
|
2016-01-07 14:21:29 +08:00
|
|
|
<Icon type="cross-circle" />
|
|
|
|
</a>
|
2016-04-29 12:13:27 +08:00
|
|
|
: <span className={`${prefixCls}-action`}><Icon type="search" /></span>
|
2016-01-07 14:21:29 +08:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
2015-11-25 23:17:06 +08:00
|
|
|
}
|
|
|
|
}
|