You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.6 KiB
63 lines
1.6 KiB
6 years ago
|
import PropTypes from '../_util/vue-types';
|
||
4 years ago
|
import { getOptionProps } from '../_util/props-util';
|
||
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||
5 years ago
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
||
|
import SearchOutlined from '@ant-design/icons-vue/SearchOutlined';
|
||
6 years ago
|
import Input from '../input';
|
||
4 years ago
|
import { defineComponent } from 'vue';
|
||
7 years ago
|
|
||
|
export const TransferSearchProps = {
|
||
|
prefixCls: PropTypes.string,
|
||
|
placeholder: PropTypes.string,
|
||
|
value: PropTypes.any,
|
||
7 years ago
|
handleClear: PropTypes.func,
|
||
4 years ago
|
disabled: PropTypes.looseBool,
|
||
4 years ago
|
onChange: PropTypes.func,
|
||
6 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
export default defineComponent({
|
||
7 years ago
|
name: 'Search',
|
||
4 years ago
|
inheritAttrs: false,
|
||
7 years ago
|
props: initDefaultProps(TransferSearchProps, {
|
||
|
placeholder: '',
|
||
|
}),
|
||
|
methods: {
|
||
6 years ago
|
handleChange(e) {
|
||
|
this.$emit('change', e);
|
||
7 years ago
|
},
|
||
6 years ago
|
handleClear2(e) {
|
||
|
e.preventDefault();
|
||
|
const { handleClear, disabled } = this.$props;
|
||
6 years ago
|
if (!disabled && handleClear) {
|
||
6 years ago
|
handleClear(e);
|
||
7 years ago
|
}
|
||
7 years ago
|
},
|
||
|
},
|
||
6 years ago
|
render() {
|
||
|
const { placeholder, value, prefixCls, disabled } = getOptionProps(this);
|
||
|
const icon =
|
||
|
value && value.length > 0 ? (
|
||
|
<a href="#" class={`${prefixCls}-action`} onClick={this.handleClear2}>
|
||
5 years ago
|
<CloseCircleFilled />
|
||
6 years ago
|
</a>
|
||
|
) : (
|
||
|
<span class={`${prefixCls}-action`}>
|
||
5 years ago
|
<SearchOutlined />
|
||
6 years ago
|
</span>
|
||
|
);
|
||
7 years ago
|
|
||
|
return (
|
||
4 years ago
|
<>
|
||
7 years ago
|
<Input
|
||
|
placeholder={placeholder}
|
||
|
class={prefixCls}
|
||
|
value={value}
|
||
|
onChange={this.handleChange}
|
||
6 years ago
|
disabled={disabled}
|
||
7 years ago
|
/>
|
||
|
{icon}
|
||
4 years ago
|
</>
|
||
6 years ago
|
);
|
||
7 years ago
|
},
|
||
4 years ago
|
});
|