2020-06-12 12:54:21 +08:00
|
|
|
import { inject } from 'vue';
|
2019-09-20 19:19:59 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
|
|
|
|
2017-11-09 15:58:53 +08:00
|
|
|
export default {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ACheckableTag',
|
2017-11-09 15:58:53 +08:00
|
|
|
props: {
|
2019-09-20 19:19:59 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2020-06-12 12:54:21 +08:00
|
|
|
checked: PropTypes.bool,
|
2020-06-12 13:50:59 +08:00
|
|
|
onChange: PropTypes.func,
|
2017-11-09 15:58:53 +08:00
|
|
|
},
|
2020-06-12 12:54:21 +08:00
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
|
|
|
};
|
2019-09-20 19:19:59 +08:00
|
|
|
},
|
2017-11-09 15:58:53 +08:00
|
|
|
computed: {
|
2019-01-12 11:33:27 +08:00
|
|
|
classes() {
|
2019-09-20 19:19:59 +08:00
|
|
|
const { checked, prefixCls: customizePrefixCls } = this;
|
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
|
|
|
const prefixCls = getPrefixCls('tag', customizePrefixCls);
|
2017-11-09 15:58:53 +08:00
|
|
|
return {
|
|
|
|
[`${prefixCls}`]: true,
|
|
|
|
[`${prefixCls}-checkable`]: true,
|
|
|
|
[`${prefixCls}-checkable-checked`]: checked,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-11-09 15:58:53 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
handleClick() {
|
|
|
|
const { checked } = this;
|
2020-06-12 12:54:21 +08:00
|
|
|
this.$emit('update:checked', !checked);
|
2019-01-12 11:33:27 +08:00
|
|
|
this.$emit('change', !checked);
|
2017-11-09 15:58:53 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
const { classes, handleClick, $slots } = this;
|
2018-03-19 09:43:31 +08:00
|
|
|
return (
|
|
|
|
<div class={classes} onClick={handleClick}>
|
2020-06-12 12:54:21 +08:00
|
|
|
{$slots.default && $slots.default()}
|
2018-03-19 09:43:31 +08:00
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-03-19 09:43:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|