chore: improve tag type
parent
2b6ef8e10f
commit
981470f393
|
@ -1,13 +1,13 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Tag visibility can be controlled by visible with hidden as initial value 1`] = `<span class="ant-tag" style="display: none;"><!----><!----></span>`;
|
exports[`Tag visibility can be controlled by visible with hidden as initial value 1`] = `<span class="ant-tag ant-tag-hidden"><!----><!----></span>`;
|
||||||
|
|
||||||
exports[`Tag visibility can be controlled by visible with hidden as initial value 2`] = `<span class="ant-tag" style=""><!----><!----></span>`;
|
exports[`Tag visibility can be controlled by visible with hidden as initial value 2`] = `<span class="ant-tag"><!----><!----></span>`;
|
||||||
|
|
||||||
exports[`Tag visibility can be controlled by visible with hidden as initial value 3`] = `<span class="ant-tag" style="display: none;"><!----><!----></span>`;
|
exports[`Tag visibility can be controlled by visible with hidden as initial value 3`] = `<span class="ant-tag ant-tag-hidden"><!----><!----></span>`;
|
||||||
|
|
||||||
exports[`Tag visibility can be controlled by visible with visible as initial value 1`] = `<span class="ant-tag"><!----><!----></span>`;
|
exports[`Tag visibility can be controlled by visible with visible as initial value 1`] = `<span class="ant-tag"><!----><!----></span>`;
|
||||||
|
|
||||||
exports[`Tag visibility can be controlled by visible with visible as initial value 2`] = `<span class="ant-tag" style="display: none;"><!----><!----></span>`;
|
exports[`Tag visibility can be controlled by visible with visible as initial value 2`] = `<span class="ant-tag ant-tag-hidden"><!----><!----></span>`;
|
||||||
|
|
||||||
exports[`Tag visibility can be controlled by visible with visible as initial value 3`] = `<span class="ant-tag" style=""><!----><!----></span>`;
|
exports[`Tag visibility can be controlled by visible with visible as initial value 3`] = `<span class="ant-tag"><!----><!----></span>`;
|
||||||
|
|
|
@ -19,21 +19,17 @@ describe('Tag', () => {
|
||||||
await asyncExpect(() => {
|
await asyncExpect(() => {
|
||||||
expect(wrapper.findAll('.anticon-close').length).toBe(1);
|
expect(wrapper.findAll('.anticon-close').length).toBe(1);
|
||||||
expect(
|
expect(
|
||||||
wrapper.findAll('.ant-tag').filter(w => {
|
wrapper.findAll('.ant-tag').filter(w => w.element.classList.contains('ant-tag-hidden'))
|
||||||
const style = window.getComputedStyle(w.element, null);
|
.length,
|
||||||
return style.display !== 'none';
|
).toBe(0);
|
||||||
}).length,
|
|
||||||
).toBe(1);
|
|
||||||
wrapper.find('.anticon-close').trigger('click');
|
wrapper.find('.anticon-close').trigger('click');
|
||||||
expect(onClose).toBeCalled();
|
expect(onClose).toBeCalled();
|
||||||
});
|
});
|
||||||
await asyncExpect(() => {
|
await asyncExpect(() => {
|
||||||
expect(
|
expect(
|
||||||
wrapper.findAll('.ant-tag').filter(w => {
|
wrapper.findAll('.ant-tag').filter(w => w.element.classList.contains('ant-tag-hidden'))
|
||||||
const style = window.getComputedStyle(w.element, null);
|
.length,
|
||||||
return style.display !== 'none';
|
).toBe(1);
|
||||||
}).length,
|
|
||||||
).toBe(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,11 +48,9 @@ describe('Tag', () => {
|
||||||
await asyncExpect(() => {
|
await asyncExpect(() => {
|
||||||
expect(wrapper.findAll('.anticon-close').length).toBe(1);
|
expect(wrapper.findAll('.anticon-close').length).toBe(1);
|
||||||
expect(
|
expect(
|
||||||
wrapper.findAll('.ant-tag').filter(w => {
|
wrapper.findAll('.ant-tag').filter(w => w.element.classList.contains('ant-tag-hidden'))
|
||||||
const style = window.getComputedStyle(w.element, null);
|
.length,
|
||||||
return style.display !== 'none';
|
).toBe(0);
|
||||||
}).length,
|
|
||||||
).toBe(1);
|
|
||||||
wrapper.find('.anticon-close').trigger('click');
|
wrapper.find('.anticon-close').trigger('click');
|
||||||
});
|
});
|
||||||
// await asyncExpect(() => {
|
// await asyncExpect(() => {
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
import { inject, ref, HTMLAttributes, defineComponent, App, VNodeTypes, watchEffect } from 'vue';
|
import {
|
||||||
|
inject,
|
||||||
|
ref,
|
||||||
|
HTMLAttributes,
|
||||||
|
defineComponent,
|
||||||
|
App,
|
||||||
|
watchEffect,
|
||||||
|
PropType,
|
||||||
|
ExtractPropTypes,
|
||||||
|
} from 'vue';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
||||||
|
@ -16,15 +25,21 @@ import CheckableTag from './CheckableTag';
|
||||||
const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?$`);
|
const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?$`);
|
||||||
const PresetStatusColorRegex = new RegExp(`^(${PresetStatusColorTypes.join('|')})$`);
|
const PresetStatusColorRegex = new RegExp(`^(${PresetStatusColorTypes.join('|')})$`);
|
||||||
|
|
||||||
export interface TagProps extends HTMLAttributes {
|
const tagProps = {
|
||||||
prefixCls?: string;
|
prefixCls: PropTypes.string,
|
||||||
color?: LiteralUnion<PresetColorType | PresetStatusColorType, string>;
|
color: {
|
||||||
closable?: boolean;
|
type: String as PropType<LiteralUnion<PresetColorType | PresetStatusColorType, string>>,
|
||||||
closeIcon?: VNodeTypes;
|
},
|
||||||
visible?: boolean;
|
closable: PropTypes.looseBool.def(false),
|
||||||
onClose?: (e: MouseEvent) => void;
|
closeIcon: PropTypes.VNodeChild,
|
||||||
icon?: VNodeTypes;
|
visible: PropTypes.looseBool,
|
||||||
}
|
onClose: {
|
||||||
|
type: Function as PropType<(e: MouseEvent) => void>,
|
||||||
|
},
|
||||||
|
icon: PropTypes.VNodeChild,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TagProps = HTMLAttributes & Partial<ExtractPropTypes<typeof tagProps>>;
|
||||||
|
|
||||||
const Tag = defineComponent({
|
const Tag = defineComponent({
|
||||||
name: 'ATag',
|
name: 'ATag',
|
||||||
|
@ -110,7 +125,7 @@ const Tag = defineComponent({
|
||||||
const isNeedWave = 'onClick' in attrs;
|
const isNeedWave = 'onClick' in attrs;
|
||||||
|
|
||||||
const tagNode = (
|
const tagNode = (
|
||||||
<span v-show={visible.value} class={tagClassName} style={tagStyle}>
|
<span class={tagClassName} style={tagStyle}>
|
||||||
{kids}
|
{kids}
|
||||||
{renderCloseIcon()}
|
{renderCloseIcon()}
|
||||||
</span>
|
</span>
|
||||||
|
@ -121,22 +136,16 @@ const Tag = defineComponent({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Tag.props = {
|
Tag.props = tagProps;
|
||||||
prefixCls: PropTypes.string,
|
|
||||||
color: PropTypes.string,
|
|
||||||
closable: PropTypes.looseBool.def(false),
|
|
||||||
closeIcon: PropTypes.any,
|
|
||||||
visible: PropTypes.looseBool,
|
|
||||||
onClose: PropTypes.func,
|
|
||||||
icon: PropTypes.any,
|
|
||||||
};
|
|
||||||
|
|
||||||
Tag.CheckableTag = CheckableTag;
|
Tag.CheckableTag = CheckableTag;
|
||||||
|
|
||||||
Tag.install = (app: App) => {
|
Tag.install = function(app: App) {
|
||||||
app.component(Tag.name, Tag);
|
app.component(Tag.name, Tag);
|
||||||
app.component(CheckableTag.name, CheckableTag);
|
app.component(CheckableTag.name, CheckableTag);
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Tag;
|
export default Tag as typeof Tag & {
|
||||||
|
readonly CheckableTag: typeof CheckableTag;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue