ant-design/components/transfer/search.tsx

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2016-09-21 11:54:53 +08:00
import React from 'react';
2015-12-23 23:12:20 +08:00
import Icon from '../icon';
import Input from '../input';
2015-11-25 23:17:06 +08:00
function noop() {
}
2016-07-07 20:25:03 +08:00
export interface SearchProps {
2016-07-13 11:14:24 +08:00
prefixCls?: string;
placeholder?: string;
onChange?: (e: React.FormEvent) => void;
handleClear?: (e: React.MouseEvent) => void;
value?: any;
}
export default class Search extends React.Component<SearchProps, any> {
static defaultProps = {
placeholder: '',
onChange: noop,
handleClear: noop,
2016-07-13 11:14:24 +08:00
};
handleChange = (e) => {
2015-11-26 16:07:11 +08:00
this.props.onChange(e);
}
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() {
const { placeholder, value, prefixCls } = this.props;
return (
<div>
<Input placeholder={placeholder} className={prefixCls} value={value} ref="input"
onChange={this.handleChange}
/>
{value && value.length > 0 ?
<a href="#" className={`${prefixCls}-action`} onClick={this.handleClear}>
<Icon type="cross-circle" />
</a>
: <span className={`${prefixCls}-action`}><Icon type="search" /></span>
}
</div>
);
2015-11-25 23:17:06 +08:00
}
}