2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2015-12-23 23:12:20 +08:00
|
|
|
import Icon from '../icon';
|
2016-09-14 16:18:33 +08:00
|
|
|
import Input from '../input';
|
|
|
|
|
2017-12-14 10:49:44 +08:00
|
|
|
export interface TransferSearchProps {
|
2016-07-13 11:14:24 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
placeholder?: string;
|
2019-06-16 20:51:47 +08:00
|
|
|
onChange?: (e: React.FormEvent<HTMLElement>) => void;
|
|
|
|
handleClear?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
|
|
value?: string;
|
2018-11-29 00:41:49 +08:00
|
|
|
disabled?: boolean;
|
2016-07-01 20:52:17 +08:00
|
|
|
}
|
|
|
|
|
2017-12-14 10:49:44 +08:00
|
|
|
export default class Search extends React.Component<TransferSearchProps, any> {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
placeholder: '',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2017-11-20 17:41:32 +08:00
|
|
|
handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
2018-06-30 21:56:41 +08:00
|
|
|
const { onChange } = this.props;
|
2016-10-24 16:30:38 +08:00
|
|
|
if (onChange) {
|
|
|
|
onChange(e);
|
|
|
|
}
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2015-11-26 16:07:11 +08:00
|
|
|
|
2017-11-20 17:41:32 +08:00
|
|
|
handleClear = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
2016-01-13 16:28:36 +08:00
|
|
|
e.preventDefault();
|
2018-11-29 00:41:49 +08:00
|
|
|
const { handleClear, disabled } = this.props;
|
|
|
|
if (!disabled && handleClear) {
|
2016-10-24 16:30:38 +08:00
|
|
|
handleClear(e);
|
|
|
|
}
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2016-01-13 16:28:36 +08:00
|
|
|
|
2015-11-26 16:07:11 +08:00
|
|
|
render() {
|
2018-11-29 00:41:49 +08:00
|
|
|
const { placeholder, value, prefixCls, disabled } = this.props;
|
2018-12-07 16:17:45 +08:00
|
|
|
const icon =
|
|
|
|
value && value.length > 0 ? (
|
|
|
|
<a href="#" className={`${prefixCls}-action`} onClick={this.handleClear}>
|
|
|
|
<Icon type="close-circle" theme="filled" />
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<span className={`${prefixCls}-action`}>
|
|
|
|
<Icon type="search" />
|
|
|
|
</span>
|
|
|
|
);
|
2016-11-25 12:03:39 +08:00
|
|
|
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-11-23 17:53:10 +08:00
|
|
|
<Input
|
|
|
|
placeholder={placeholder}
|
|
|
|
className={prefixCls}
|
|
|
|
value={value}
|
2016-06-06 13:54:10 +08:00
|
|
|
onChange={this.handleChange}
|
2018-11-29 00:41:49 +08:00
|
|
|
disabled={disabled}
|
2016-06-06 13:54:10 +08:00
|
|
|
/>
|
2016-11-25 12:03:39 +08:00
|
|
|
{icon}
|
2016-01-07 14:21:29 +08:00
|
|
|
</div>
|
|
|
|
);
|
2015-11-25 23:17:06 +08:00
|
|
|
}
|
|
|
|
}
|