Feat Tag CheckableTag (#2400)
* feat: update Tag CheckableTag * fix: merge event handler * fix: merge event handler * fix: delete dubugger * fix: configProvider injectpull/2415/head^2
parent
237d55aa3e
commit
ee3a7179f6
|
@ -1,17 +1,17 @@
|
|||
import { inject } from 'vue';
|
||||
import PropTypes from '../_util/vue-types';
|
||||
import { ConfigConsumerProps } from '../config-provider';
|
||||
|
||||
export default {
|
||||
name: 'ACheckableTag',
|
||||
model: {
|
||||
prop: 'checked',
|
||||
},
|
||||
props: {
|
||||
prefixCls: PropTypes.string,
|
||||
checked: Boolean,
|
||||
checked: PropTypes.bool,
|
||||
},
|
||||
inject: {
|
||||
configProvider: { default: () => ConfigConsumerProps },
|
||||
setup() {
|
||||
return {
|
||||
configProvider: inject('configProvider', ConfigConsumerProps),
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
classes() {
|
||||
|
@ -28,7 +28,7 @@ export default {
|
|||
methods: {
|
||||
handleClick() {
|
||||
const { checked } = this;
|
||||
this.$emit('input', !checked);
|
||||
this.$emit('update:checked', !checked);
|
||||
this.$emit('change', !checked);
|
||||
},
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ export default {
|
|||
const { classes, handleClick, $slots } = this;
|
||||
return (
|
||||
<div class={classes} onClick={handleClick}>
|
||||
{$slots.default}
|
||||
{$slots.default && $slots.default()}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { Transition } from 'vue';
|
||||
import { Transition, inject } from 'vue';
|
||||
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
||||
import PropTypes from '../_util/vue-types';
|
||||
import getTransitionProps from '../_util/getTransitionProps';
|
||||
import omit from 'omit.js';
|
||||
import Wave from '../_util/wave';
|
||||
import { hasProp, getListeners, getOptionProps } from '../_util/props-util';
|
||||
import { hasProp, getOptionProps } from '../_util/props-util';
|
||||
import BaseMixin from '../_util/BaseMixin';
|
||||
import { ConfigConsumerProps } from '../config-provider';
|
||||
import warning from '../_util/warning';
|
||||
|
@ -29,10 +28,6 @@ const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?
|
|||
export default {
|
||||
name: 'ATag',
|
||||
mixins: [BaseMixin],
|
||||
model: {
|
||||
prop: 'visible',
|
||||
event: 'close.visible',
|
||||
},
|
||||
props: {
|
||||
prefixCls: PropTypes.string,
|
||||
color: PropTypes.string,
|
||||
|
@ -40,8 +35,10 @@ export default {
|
|||
visible: PropTypes.bool,
|
||||
afterClose: PropTypes.func,
|
||||
},
|
||||
inject: {
|
||||
configProvider: { default: () => ConfigConsumerProps },
|
||||
setup() {
|
||||
return {
|
||||
configProvider: inject('configProvider', ConfigConsumerProps),
|
||||
};
|
||||
},
|
||||
data() {
|
||||
let _visible = true;
|
||||
|
@ -68,7 +65,7 @@ export default {
|
|||
methods: {
|
||||
setVisible(visible, e) {
|
||||
this.$emit('close', e);
|
||||
this.$emit('close.visible', false);
|
||||
this.$emit('update:visible', false);
|
||||
const afterClose = this.afterClose;
|
||||
if (afterClose) {
|
||||
// next version remove.
|
||||
|
@ -120,16 +117,11 @@ export default {
|
|||
|
||||
render() {
|
||||
const { prefixCls: customizePrefixCls } = this.$props;
|
||||
const getPrefixCls = this.configProvider().getPrefixCls;
|
||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||
const prefixCls = getPrefixCls('tag', customizePrefixCls);
|
||||
const { _visible: visible } = this.$data;
|
||||
const tag = (
|
||||
<span
|
||||
v-show={visible}
|
||||
{...{ on: omit(getListeners(this), ['close']) }}
|
||||
class={this.getTagClassName(prefixCls)}
|
||||
style={this.getTagStyle()}
|
||||
>
|
||||
<span v-show={visible} class={this.getTagClassName(prefixCls)} style={this.getTagStyle()}>
|
||||
{this.$slots.default()}
|
||||
{this.renderCloseIcon()}
|
||||
</span>
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
import Tag from './Tag';
|
||||
import CheckableTag from './CheckableTag';
|
||||
import Base from '../base';
|
||||
|
||||
Tag.CheckableTag = CheckableTag;
|
||||
|
||||
/* istanbul ignore next */
|
||||
Tag.install = function(Vue) {
|
||||
Vue.use(Base);
|
||||
Vue.component(Tag.name, Tag);
|
||||
Vue.component(Tag.CheckableTag.name, Tag.CheckableTag);
|
||||
Tag.install = function(app) {
|
||||
app.component(Tag.name, Tag);
|
||||
app.component(Tag.CheckableTag.name, Tag.CheckableTag);
|
||||
};
|
||||
|
||||
export default Tag;
|
||||
|
|
|
@ -21,6 +21,7 @@ import Col from 'ant-design-vue/col';
|
|||
import Row from 'ant-design-vue/row';
|
||||
import Tooltip from 'ant-design-vue/tooltip';
|
||||
import Descriptions from 'ant-design-vue/descriptions';
|
||||
import Tag from 'ant-design-vue/tag';
|
||||
import 'ant-design-vue/style.js';
|
||||
|
||||
createApp(App)
|
||||
|
@ -44,4 +45,5 @@ createApp(App)
|
|||
.use(Row)
|
||||
.use(Tooltip)
|
||||
.use(Descriptions)
|
||||
.use(Tag)
|
||||
.mount('#app');
|
||||
|
|
Loading…
Reference in New Issue