Feat Tag CheckableTag (#2400)

* feat: update Tag CheckableTag

* fix:  merge event handler

* fix: merge event handler

* fix: delete dubugger

* fix: configProvider inject
pull/2415/head^2
孙运天 2020-06-12 12:54:21 +08:00 committed by GitHub
parent 237d55aa3e
commit ee3a7179f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 30 deletions

View File

@ -1,17 +1,17 @@
import { inject } from 'vue';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
export default { export default {
name: 'ACheckableTag', name: 'ACheckableTag',
model: {
prop: 'checked',
},
props: { props: {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
checked: Boolean, checked: PropTypes.bool,
}, },
inject: { setup() {
configProvider: { default: () => ConfigConsumerProps }, return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
}, },
computed: { computed: {
classes() { classes() {
@ -28,7 +28,7 @@ export default {
methods: { methods: {
handleClick() { handleClick() {
const { checked } = this; const { checked } = this;
this.$emit('input', !checked); this.$emit('update:checked', !checked);
this.$emit('change', !checked); this.$emit('change', !checked);
}, },
}, },
@ -36,7 +36,7 @@ export default {
const { classes, handleClick, $slots } = this; const { classes, handleClick, $slots } = this;
return ( return (
<div class={classes} onClick={handleClick}> <div class={classes} onClick={handleClick}>
{$slots.default} {$slots.default && $slots.default()}
</div> </div>
); );
}, },

View File

@ -1,10 +1,9 @@
import { Transition } from 'vue'; import { Transition, inject } from 'vue';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined'; import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import getTransitionProps from '../_util/getTransitionProps'; import getTransitionProps from '../_util/getTransitionProps';
import omit from 'omit.js';
import Wave from '../_util/wave'; 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 BaseMixin from '../_util/BaseMixin';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import warning from '../_util/warning';
@ -29,10 +28,6 @@ const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?
export default { export default {
name: 'ATag', name: 'ATag',
mixins: [BaseMixin], mixins: [BaseMixin],
model: {
prop: 'visible',
event: 'close.visible',
},
props: { props: {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
color: PropTypes.string, color: PropTypes.string,
@ -40,8 +35,10 @@ export default {
visible: PropTypes.bool, visible: PropTypes.bool,
afterClose: PropTypes.func, afterClose: PropTypes.func,
}, },
inject: { setup() {
configProvider: { default: () => ConfigConsumerProps }, return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
}, },
data() { data() {
let _visible = true; let _visible = true;
@ -68,7 +65,7 @@ export default {
methods: { methods: {
setVisible(visible, e) { setVisible(visible, e) {
this.$emit('close', e); this.$emit('close', e);
this.$emit('close.visible', false); this.$emit('update:visible', false);
const afterClose = this.afterClose; const afterClose = this.afterClose;
if (afterClose) { if (afterClose) {
// next version remove. // next version remove.
@ -120,16 +117,11 @@ export default {
render() { render() {
const { prefixCls: customizePrefixCls } = this.$props; const { prefixCls: customizePrefixCls } = this.$props;
const getPrefixCls = this.configProvider().getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('tag', customizePrefixCls); const prefixCls = getPrefixCls('tag', customizePrefixCls);
const { _visible: visible } = this.$data; const { _visible: visible } = this.$data;
const tag = ( const tag = (
<span <span v-show={visible} class={this.getTagClassName(prefixCls)} style={this.getTagStyle()}>
v-show={visible}
{...{ on: omit(getListeners(this), ['close']) }}
class={this.getTagClassName(prefixCls)}
style={this.getTagStyle()}
>
{this.$slots.default()} {this.$slots.default()}
{this.renderCloseIcon()} {this.renderCloseIcon()}
</span> </span>

View File

@ -1,14 +1,12 @@
import Tag from './Tag'; import Tag from './Tag';
import CheckableTag from './CheckableTag'; import CheckableTag from './CheckableTag';
import Base from '../base';
Tag.CheckableTag = CheckableTag; Tag.CheckableTag = CheckableTag;
/* istanbul ignore next */ /* istanbul ignore next */
Tag.install = function(Vue) { Tag.install = function(app) {
Vue.use(Base); app.component(Tag.name, Tag);
Vue.component(Tag.name, Tag); app.component(Tag.CheckableTag.name, Tag.CheckableTag);
Vue.component(Tag.CheckableTag.name, Tag.CheckableTag);
}; };
export default Tag; export default Tag;

View File

@ -21,6 +21,7 @@ import Col from 'ant-design-vue/col';
import Row from 'ant-design-vue/row'; import Row from 'ant-design-vue/row';
import Tooltip from 'ant-design-vue/tooltip'; import Tooltip from 'ant-design-vue/tooltip';
import Descriptions from 'ant-design-vue/descriptions'; import Descriptions from 'ant-design-vue/descriptions';
import Tag from 'ant-design-vue/tag';
import 'ant-design-vue/style.js'; import 'ant-design-vue/style.js';
createApp(App) createApp(App)
@ -44,4 +45,5 @@ createApp(App)
.use(Row) .use(Row)
.use(Tooltip) .use(Tooltip)
.use(Descriptions) .use(Descriptions)
.use(Tag)
.mount('#app'); .mount('#app');