2020-10-04 14:08:12 +00:00
|
|
|
import { inject, defineComponent, PropType } from 'vue';
|
2020-09-23 09:51:02 +00:00
|
|
|
import classNames from '../_util/classNames';
|
2020-09-30 02:47:18 +00:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2020-10-04 14:08:12 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-08-23 11:33:01 +00:00
|
|
|
|
2020-10-04 14:08:12 +00:00
|
|
|
const CheckableTag = defineComponent({
|
|
|
|
name: 'ACheckableTag',
|
|
|
|
props: {
|
|
|
|
prefixCls: PropTypes.string,
|
2020-10-10 10:16:28 +00:00
|
|
|
checked: PropTypes.looseBool,
|
2020-10-04 14:08:12 +00:00
|
|
|
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);
|
|
|
|
};
|
2020-08-23 11:33:01 +00:00
|
|
|
|
2020-10-04 14:08:12 +00:00
|
|
|
return () => {
|
|
|
|
const { checked, prefixCls: customizePrefixCls } = props;
|
|
|
|
const prefixCls = getPrefixCls('tag', customizePrefixCls);
|
|
|
|
const cls = classNames(prefixCls, {
|
|
|
|
[`${prefixCls}-checkable`]: true,
|
|
|
|
[`${prefixCls}-checkable-checked`]: checked,
|
|
|
|
});
|
2020-08-23 11:33:01 +00:00
|
|
|
|
2020-10-04 14:08:12 +00:00
|
|
|
return (
|
|
|
|
<span class={cls} onClick={handleClick}>
|
|
|
|
{slots.default?.()}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2020-08-23 11:33:01 +00:00
|
|
|
|
|
|
|
export default CheckableTag;
|