2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-10-20 16:45:49 +08:00
|
|
|
import { getOptionProps } from '../_util/props-util';
|
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
2020-03-28 15:52:26 +08:00
|
|
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
|
|
|
import SearchOutlined from '@ant-design/icons-vue/SearchOutlined';
|
2019-01-12 11:33:27 +08:00
|
|
|
import Input from '../input';
|
2020-10-20 16:45:49 +08:00
|
|
|
import { defineComponent } from 'vue';
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
export const TransferSearchProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
placeholder: PropTypes.string,
|
|
|
|
value: PropTypes.any,
|
2018-05-18 21:21:31 +08:00
|
|
|
handleClear: PropTypes.func,
|
2020-10-10 18:16:28 +08:00
|
|
|
disabled: PropTypes.looseBool,
|
2020-08-05 17:17:07 +08:00
|
|
|
onChange: PropTypes.func,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2020-10-20 16:45:49 +08:00
|
|
|
export default defineComponent({
|
2018-04-07 00:20:45 +08:00
|
|
|
name: 'Search',
|
2020-07-19 22:40:35 +08:00
|
|
|
inheritAttrs: false,
|
2018-04-07 00:20:45 +08:00
|
|
|
props: initDefaultProps(TransferSearchProps, {
|
|
|
|
placeholder: '',
|
|
|
|
}),
|
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
handleChange(e) {
|
|
|
|
this.$emit('change', e);
|
2018-04-07 00:20:45 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
handleClear2(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
const { handleClear, disabled } = this.$props;
|
2019-01-07 20:58:18 +08:00
|
|
|
if (!disabled && handleClear) {
|
2019-01-12 11:33:27 +08:00
|
|
|
handleClear(e);
|
2018-05-18 21:21:31 +08:00
|
|
|
}
|
2018-04-07 00:20:45 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
const { placeholder, value, prefixCls, disabled } = getOptionProps(this);
|
|
|
|
const icon =
|
|
|
|
value && value.length > 0 ? (
|
|
|
|
<a href="#" class={`${prefixCls}-action`} onClick={this.handleClear2}>
|
2020-03-28 15:52:26 +08:00
|
|
|
<CloseCircleFilled />
|
2019-01-12 11:33:27 +08:00
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<span class={`${prefixCls}-action`}>
|
2020-03-28 15:52:26 +08:00
|
|
|
<SearchOutlined />
|
2019-01-12 11:33:27 +08:00
|
|
|
</span>
|
|
|
|
);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
return (
|
2020-10-20 16:45:49 +08:00
|
|
|
<>
|
2018-04-07 00:20:45 +08:00
|
|
|
<Input
|
|
|
|
placeholder={placeholder}
|
|
|
|
class={prefixCls}
|
|
|
|
value={value}
|
|
|
|
onChange={this.handleChange}
|
2019-01-07 20:58:18 +08:00
|
|
|
disabled={disabled}
|
2018-04-07 00:20:45 +08:00
|
|
|
/>
|
|
|
|
{icon}
|
2020-10-20 16:45:49 +08:00
|
|
|
</>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-04-07 00:20:45 +08:00
|
|
|
},
|
2020-10-20 16:45:49 +08:00
|
|
|
});
|