2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2020-03-02 12:09:38 +08:00
|
|
|
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
|
|
|
import SearchOutlined from '@ant-design/icons/SearchOutlined';
|
2019-08-13 14:07:17 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-16 23:52:03 +08:00
|
|
|
export default function Search(props: TransferSearchProps) {
|
|
|
|
const { placeholder = '', value, prefixCls, disabled, onChange, handleClear } = props;
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2021-01-16 23:52:03 +08:00
|
|
|
const handleChange = React.useCallback(
|
|
|
|
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
onChange?.(e);
|
|
|
|
},
|
|
|
|
[onChange],
|
|
|
|
);
|
2015-11-26 16:07:11 +08:00
|
|
|
|
2021-01-16 23:52:03 +08:00
|
|
|
const handleClearFn = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
2016-01-13 16:28:36 +08:00
|
|
|
e.preventDefault();
|
2018-11-29 00:41:49 +08:00
|
|
|
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
|
|
|
|
2021-01-16 23:52:03 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Input
|
|
|
|
placeholder={placeholder}
|
|
|
|
className={prefixCls}
|
|
|
|
value={value}
|
|
|
|
onChange={handleChange}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
{value && value.length > 0 ? (
|
|
|
|
<a className={`${prefixCls}-action`} onClick={handleClearFn}>
|
2019-08-13 14:07:17 +08:00
|
|
|
<CloseCircleFilled />
|
2018-12-07 16:17:45 +08:00
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<span className={`${prefixCls}-action`}>
|
2019-11-28 12:34:33 +08:00
|
|
|
<SearchOutlined />
|
2018-12-07 16:17:45 +08:00
|
|
|
</span>
|
2021-01-16 23:52:03 +08:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
2015-11-25 23:17:06 +08:00
|
|
|
}
|