Skip to content

Commit a205615

Browse files
authored
refactor(tag): less to cssinjs (#6227)
1 parent 9b5a072 commit a205615

File tree

12 files changed

+215
-220
lines changed

12 files changed

+215
-220
lines changed

components/style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import './radio/style';
44
import './checkbox/style';
55
// import './grid/style';
6-
import './tag/style';
6+
// import './tag/style';
77
import './rate/style';
88
import './pagination/style';
99
// import './avatar/style';

components/tag/CheckableTag.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ExtractPropTypes, PropType } from 'vue';
22
import { defineComponent, computed } from 'vue';
33
import classNames from '../_util/classNames';
44
import useConfigInject from '../config-provider/hooks/useConfigInject';
5+
import useStyle from './style';
56

67
const checkableTagProps = () => ({
78
prefixCls: String,
@@ -19,10 +20,14 @@ export type CheckableTagProps = Partial<ExtractPropTypes<ReturnType<typeof check
1920
const CheckableTag = defineComponent({
2021
compatConfig: { MODE: 3 },
2122
name: 'ACheckableTag',
23+
inheritAttrs: false,
2224
props: checkableTagProps(),
2325
// emits: ['update:checked', 'change', 'click'],
24-
setup(props, { slots, emit }) {
26+
setup(props, { slots, emit, attrs }) {
2527
const { prefixCls } = useConfigInject('tag', props);
28+
// Style
29+
const [wrapSSR, hashId] = useStyle(prefixCls);
30+
2631
const handleClick = (e: MouseEvent) => {
2732
const { checked } = props;
2833
emit('update:checked', !checked);
@@ -31,17 +36,17 @@ const CheckableTag = defineComponent({
3136
};
3237

3338
const cls = computed(() =>
34-
classNames(prefixCls.value, {
39+
classNames(prefixCls.value, hashId.value, {
3540
[`${prefixCls.value}-checkable`]: true,
3641
[`${prefixCls.value}-checkable-checked`]: props.checked,
3742
}),
3843
);
3944

4045
return () => {
41-
return (
42-
<span class={cls.value} onClick={handleClick}>
46+
return wrapSSR(
47+
<span {...attrs} class={cls.value} onClick={handleClick}>
4348
{slots.default?.()}
44-
</span>
49+
</span>,
4550
);
4651
};
4752
},

components/tag/demo/controlled.vue

-33
This file was deleted.

components/tag/demo/index.vue

-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<Checkable />
55
<Colorful />
66
<Control />
7-
<Controlled />
87
<HotTags />
98
<Icon />
109
<Status />
@@ -16,7 +15,6 @@ import Basic from './basic.vue';
1615
import Checkable from './checkable.vue';
1716
import Colorful from './colorful.vue';
1817
import Control from './control.vue';
19-
import Controlled from './controlled.vue';
2018
import HotTags from './hot-tags.vue';
2119
import Icon from './icon.vue';
2220
import Status from './status.vue';
@@ -32,7 +30,6 @@ export default defineComponent({
3230
Checkable,
3331
Colorful,
3432
Control,
35-
Controlled,
3633
HotTags,
3734
Icon,
3835
Status,

components/tag/index.en-US.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ Tag for categorizing or markup.
1616

1717
### Tag
1818

19-
| Property | Description | Type | Default | Version |
20-
| ---------------- | -------------------------------- | ------------- | ------- | ------- |
21-
| closable | Whether the Tag can be closed | boolean | `false` | |
22-
| closeIcon | Custom close icon | VNode \| slot | - | 2.0.0 |
23-
| color | Color of the Tag | string | - | |
24-
| icon | Set the icon of tag | VNode \| slot | - | 2.0.0 |
25-
| visible(v-model) | Whether the Tag is closed or not | boolean | `true` | |
19+
| Property | Description | Type | Default | Version |
20+
| --------- | ----------------------------- | ------------- | ------- | ------- |
21+
| closable | Whether the Tag can be closed | boolean | `false` | |
22+
| closeIcon | Custom close icon | VNode \| slot | - | 2.0.0 |
23+
| color | Color of the Tag | string | - | |
24+
| icon | Set the icon of tag | VNode \| slot | - | 2.0.0 |
2625

2726
### Tag Events
2827

components/tag/index.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { isPresetColor, isPresetStatusColor } from '../_util/colors';
99
import type { LiteralUnion } from '../_util/type';
1010
import CheckableTag from './CheckableTag';
1111
import useConfigInject from '../config-provider/hooks/useConfigInject';
12+
import warning from '../_util/warning';
13+
14+
import useStyle from './style';
1215

1316
export const tagProps = () => ({
1417
prefixCls: String,
@@ -17,6 +20,7 @@ export const tagProps = () => ({
1720
},
1821
closable: { type: Boolean, default: false },
1922
closeIcon: PropTypes.any,
23+
/** @deprecated `visible` will be removed in next major version. */
2024
visible: { type: Boolean, default: undefined },
2125
onClose: {
2226
type: Function as PropType<(e: MouseEvent) => void>,
@@ -30,14 +34,26 @@ export type TagProps = HTMLAttributes & Partial<ExtractPropTypes<ReturnType<type
3034
const Tag = defineComponent({
3135
compatConfig: { MODE: 3 },
3236
name: 'ATag',
37+
inheritAttrs: false,
3338
props: tagProps(),
3439
// emits: ['update:visible', 'close'],
3540
slots: ['closeIcon', 'icon'],
3641
setup(props: TagProps, { slots, emit, attrs }) {
3742
const { prefixCls, direction } = useConfigInject('tag', props);
3843

44+
const [wrapSSR, hashId] = useStyle(prefixCls);
45+
3946
const visible = ref(true);
4047

48+
// Warning for deprecated usage
49+
if (process.env.NODE_ENV !== 'production') {
50+
warning(
51+
!('visible' in props),
52+
'Tag',
53+
'`visible` is deprecated, please use `<Tag v-show="visible" />` instead.',
54+
);
55+
}
56+
4157
watchEffect(() => {
4258
if (props.visible !== undefined) {
4359
visible.value = props.visible!;
@@ -70,7 +86,7 @@ const Tag = defineComponent({
7086
);
7187

7288
const tagClassName = computed(() =>
73-
classNames(prefixCls.value, {
89+
classNames(prefixCls.value, hashId.value, {
7490
[`${prefixCls.value}-${props.color}`]: isInternalColor.value,
7591
[`${prefixCls.value}-has-color`]: props.color && !isInternalColor.value,
7692
[`${prefixCls.value}-hidden`]: !visible.value,
@@ -117,13 +133,13 @@ const Tag = defineComponent({
117133
const isNeedWave = 'onClick' in attrs;
118134

119135
const tagNode = (
120-
<span class={tagClassName.value} style={tagStyle}>
136+
<span {...attrs} class={tagClassName.value} style={tagStyle}>
121137
{kids}
122138
{renderCloseIcon()}
123139
</span>
124140
);
125141

126-
return isNeedWave ? <Wave>{tagNode}</Wave> : tagNode;
142+
return wrapSSR(isNeedWave ? <Wave>{tagNode}</Wave> : tagNode);
127143
};
128144
},
129145
});

components/tag/index.zh-CN.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ cover: https://gw.alipayobjects.com/zos/alicdn/cH1BOLfxC/Tag.svg
1717

1818
### Tag
1919

20-
| 参数 | 说明 | 类型 | 默认值 | 版本 |
21-
| ---------------- | ---------------- | ------------- | ------ | ----- |
22-
| closable | 标签是否可以关闭 | boolean | false | |
23-
| closeIcon | 自定义关闭按钮 | VNode \| slot | - | 2.0.0 |
24-
| color | 标签色 | string | - | |
25-
| icon | 设置图标 | VNode \| slot | - | 2.0.0 |
26-
| visible(v-model) | 是否显示标签 | boolean | `true` | |
20+
| 参数 | 说明 | 类型 | 默认值 | 版本 |
21+
| --------- | ---------------- | ------------- | ------ | ----- |
22+
| closable | 标签是否可以关闭 | boolean | false | |
23+
| closeIcon | 自定义关闭按钮 | VNode \| slot | - | 2.0.0 |
24+
| color | 标签色 | string | - | |
25+
| icon | 设置图标 | VNode \| slot | - | 2.0.0 |
2726

2827
### 事件
2928

components/tag/style/index.less

-129
This file was deleted.

0 commit comments

Comments
 (0)