2020-03-02 12:09:38 +08:00
|
|
|
import SearchOutlined from '@ant-design/icons/SearchOutlined';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
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;
|
2021-09-01 10:49:52 +08:00
|
|
|
handleClear?: () => void;
|
2019-06-16 20:51:47 +08:00
|
|
|
value?: string;
|
2018-11-29 00:41:49 +08:00
|
|
|
disabled?: boolean;
|
2016-07-01 20:52:17 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 15:09:03 +08:00
|
|
|
const Search: React.FC<TransferSearchProps> = (props) => {
|
2021-01-16 23:52:03 +08:00
|
|
|
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);
|
2021-09-01 10:49:52 +08:00
|
|
|
if (e.target.value === '') {
|
|
|
|
handleClear?.();
|
|
|
|
}
|
2021-01-16 23:52:03 +08:00
|
|
|
},
|
|
|
|
[onChange],
|
|
|
|
);
|
2015-11-26 16:07:11 +08:00
|
|
|
|
2021-01-16 23:52:03 +08:00
|
|
|
return (
|
2021-09-01 10:49:52 +08:00
|
|
|
<Input
|
|
|
|
placeholder={placeholder}
|
|
|
|
className={prefixCls}
|
|
|
|
value={value}
|
|
|
|
onChange={handleChange}
|
|
|
|
disabled={disabled}
|
|
|
|
allowClear
|
|
|
|
prefix={<SearchOutlined />}
|
|
|
|
/>
|
2021-01-16 23:52:03 +08:00
|
|
|
);
|
2023-01-04 15:09:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Search.displayName = 'Search';
|
2015-11-25 23:17:06 +08:00
|
|
|
}
|
2023-01-04 15:09:03 +08:00
|
|
|
|
|
|
|
export default Search;
|