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.3 KiB

4 years ago
import { inject, defineComponent, PropType } from 'vue';
import classNames from '../_util/classNames';
import { defaultConfigProvider } from '../config-provider';
4 years ago
import PropTypes from '../_util/vue-types';
4 years ago
const CheckableTag = defineComponent({
name: 'ACheckableTag',
props: {
prefixCls: PropTypes.string,
checked: PropTypes.bool,
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 }) {
const { getPrefixCls } = inject('configProvider', defaultConfigProvider);
const handleClick = (e: MouseEvent) => {
const { checked } = props;
emit('update:checked', !checked);
emit('change', !checked);
emit('click', e);
};
4 years ago
return () => {
const { checked, prefixCls: customizePrefixCls } = props;
const prefixCls = getPrefixCls('tag', customizePrefixCls);
const cls = classNames(prefixCls, {
[`${prefixCls}-checkable`]: true,
[`${prefixCls}-checkable-checked`]: checked,
});
4 years ago
return (
<span class={cls} onClick={handleClick}>
{slots.default?.()}
</span>
);
};
},
});
export default CheckableTag;