ant-design/components/transfer/search.jsx

47 lines
1.1 KiB
React
Raw Normal View History

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 {
handleChange(e) {
this.props.onChange(e);
}
2016-01-13 16:28:36 +08:00
handleClear(e) {
e.preventDefault();
this.props.handleClear(e);
}
2015-11-26 16:07:11 +08:00
render() {
const { placeholder, value, prefixCls } = this.props;
return (
<div>
<input placeholder={placeholder} className={ `${prefixCls} ant-input` } value={ value } ref="input"
onChange={this.handleChange.bind(this)} />
{ value && value.length > 0 ?
<a href="#" className={ `${prefixCls}-action` } onClick={this.handleClear.bind(this)}>
<Icon type="cross-circle" />
</a>
: <span className={ `${prefixCls}-action` }><Icon type="search" /></span>
}
</div>
);
2015-11-25 23:17:06 +08:00
}
}
2015-11-26 16:07:11 +08:00
Search.defaultProps = {
2016-03-07 11:57:51 +08:00
placeholder: '',
2015-11-25 23:17:06 +08:00
onChange: noop,
2016-01-13 16:28:36 +08:00
handleClear: noop,
2015-11-25 23:17:06 +08:00
};
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,
2016-01-13 16:28:36 +08:00
onChange: PropTypes.func,
handleClear: PropTypes.func,
2015-11-25 23:17:06 +08:00
};
2015-11-26 16:07:11 +08:00
export default Search;