|
|
@ -1,5 +1,4 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
inject,
|
|
|
|
|
|
|
|
ref,
|
|
|
|
ref,
|
|
|
|
HTMLAttributes,
|
|
|
|
HTMLAttributes,
|
|
|
|
defineComponent,
|
|
|
|
defineComponent,
|
|
|
@ -8,6 +7,7 @@ import {
|
|
|
|
PropType,
|
|
|
|
PropType,
|
|
|
|
ExtractPropTypes,
|
|
|
|
ExtractPropTypes,
|
|
|
|
Plugin,
|
|
|
|
Plugin,
|
|
|
|
|
|
|
|
computed,
|
|
|
|
} from 'vue';
|
|
|
|
} from 'vue';
|
|
|
|
import classNames from '../_util/classNames';
|
|
|
|
import classNames from '../_util/classNames';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
@ -20,8 +20,8 @@ import {
|
|
|
|
PresetStatusColorType,
|
|
|
|
PresetStatusColorType,
|
|
|
|
} from '../_util/colors';
|
|
|
|
} from '../_util/colors';
|
|
|
|
import { LiteralUnion } from '../_util/type';
|
|
|
|
import { LiteralUnion } from '../_util/type';
|
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
|
|
|
|
|
|
|
import CheckableTag from './CheckableTag';
|
|
|
|
import CheckableTag from './CheckableTag';
|
|
|
|
|
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
|
|
|
|
|
|
|
|
|
|
|
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('|')})$`);
|
|
|
@ -46,8 +46,9 @@ const Tag = defineComponent({
|
|
|
|
name: 'ATag',
|
|
|
|
name: 'ATag',
|
|
|
|
props: tagProps,
|
|
|
|
props: tagProps,
|
|
|
|
emits: ['update:visible', 'close'],
|
|
|
|
emits: ['update:visible', 'close'],
|
|
|
|
|
|
|
|
slots: ['closeIcon', 'icon'],
|
|
|
|
setup(props: TagProps, { slots, emit, attrs }) {
|
|
|
|
setup(props: TagProps, { slots, emit, attrs }) {
|
|
|
|
const { getPrefixCls } = inject('configProvider', defaultConfigProvider);
|
|
|
|
const { prefixCls, direction } = useConfigInject('tag', props);
|
|
|
|
|
|
|
|
|
|
|
|
const visible = ref(true);
|
|
|
|
const visible = ref(true);
|
|
|
|
|
|
|
|
|
|
|
@ -70,26 +71,31 @@ const Tag = defineComponent({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const isPresetColor = (): boolean => {
|
|
|
|
const isPresetColor = computed(() => {
|
|
|
|
const { color } = props;
|
|
|
|
const { color } = props;
|
|
|
|
if (!color) {
|
|
|
|
if (!color) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PresetColorRegex.test(color) || PresetStatusColorRegex.test(color);
|
|
|
|
return PresetColorRegex.test(color) || PresetStatusColorRegex.test(color);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tagClassName = computed(() =>
|
|
|
|
|
|
|
|
classNames(prefixCls.value, {
|
|
|
|
|
|
|
|
[`${prefixCls.value}-${props.color}`]: isPresetColor.value,
|
|
|
|
|
|
|
|
[`${prefixCls.value}-has-color`]: props.color && !isPresetColor.value,
|
|
|
|
|
|
|
|
[`${prefixCls.value}-hidden`]: !visible.value,
|
|
|
|
|
|
|
|
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
return () => {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
|
|
|
|
icon = slots.icon?.(),
|
|
|
|
icon = slots.icon?.(),
|
|
|
|
color,
|
|
|
|
color,
|
|
|
|
closeIcon = slots.closeIcon?.(),
|
|
|
|
closeIcon = slots.closeIcon?.(),
|
|
|
|
closable = false,
|
|
|
|
closable = false,
|
|
|
|
} = props;
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
|
|
const presetColor = isPresetColor();
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('tag', customizePrefixCls);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const renderCloseIcon = () => {
|
|
|
|
const renderCloseIcon = () => {
|
|
|
|
if (closable) {
|
|
|
|
if (closable) {
|
|
|
|
return closeIcon ? (
|
|
|
|
return closeIcon ? (
|
|
|
@ -104,15 +110,9 @@ const Tag = defineComponent({
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const tagStyle = {
|
|
|
|
const tagStyle = {
|
|
|
|
backgroundColor: color && !isPresetColor() ? color : undefined,
|
|
|
|
backgroundColor: color && !isPresetColor.value ? color : undefined,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const tagClassName = classNames(prefixCls, {
|
|
|
|
|
|
|
|
[`${prefixCls}-${color}`]: presetColor,
|
|
|
|
|
|
|
|
[`${prefixCls}-has-color`]: color && !presetColor,
|
|
|
|
|
|
|
|
[`${prefixCls}-hidden`]: !visible.value,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const iconNode = icon || null;
|
|
|
|
const iconNode = icon || null;
|
|
|
|
const children = slots.default?.();
|
|
|
|
const children = slots.default?.();
|
|
|
|
const kids = iconNode ? (
|
|
|
|
const kids = iconNode ? (
|
|
|
@ -127,7 +127,7 @@ const Tag = defineComponent({
|
|
|
|
const isNeedWave = 'onClick' in attrs;
|
|
|
|
const isNeedWave = 'onClick' in attrs;
|
|
|
|
|
|
|
|
|
|
|
|
const tagNode = (
|
|
|
|
const tagNode = (
|
|
|
|
<span class={tagClassName} style={tagStyle}>
|
|
|
|
<span class={tagClassName.value} style={tagStyle}>
|
|
|
|
{kids}
|
|
|
|
{kids}
|
|
|
|
{renderCloseIcon()}
|
|
|
|
{renderCloseIcon()}
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|