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.
ant-design-vue/components/tag/CheckableTag.tsx

46 lines
1.2 KiB

4 years ago
import { defineComponent, PropType, computed } from 'vue';
import classNames from '../_util/classNames';
4 years ago
import PropTypes from '../_util/vue-types';
4 years ago
import useConfigInject from '../_util/hooks/useConfigInject';
4 years ago
const CheckableTag = defineComponent({
name: 'ACheckableTag',
props: {
prefixCls: PropTypes.string,
checked: PropTypes.looseBool,
4 years ago
onChange: {
type: Function as PropType<(checked: boolean) => void>,
},
onClick: {
type: Function as PropType<(e: MouseEvent) => void>,
},
},
emits: ['update:checked', 'change', 'click'],
setup(props, { slots, emit }) {
4 years ago
const { prefixCls } = useConfigInject('tag', props);
4 years ago
const handleClick = (e: MouseEvent) => {
const { checked } = props;
emit('update:checked', !checked);
emit('change', !checked);
emit('click', e);
};
4 years ago
const cls = computed(() =>
classNames(prefixCls.value, {
[`${prefixCls.value}-checkable`]: true,
[`${prefixCls.value}-checkable-checked`]: props.checked,
}),
);
4 years ago
return () => {
4 years ago
return (
4 years ago
<span class={cls.value} onClick={handleClick}>
4 years ago
{slots.default?.()}
</span>
);
};
},
});
export default CheckableTag;