Skip to content

refactor(tag): less to cssinjs #6227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import './radio/style';
import './checkbox/style';
// import './grid/style';
import './tag/style';
// import './tag/style';
import './rate/style';
import './pagination/style';
// import './avatar/style';
Expand Down
15 changes: 10 additions & 5 deletions components/tag/CheckableTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ExtractPropTypes, PropType } from 'vue';
import { defineComponent, computed } from 'vue';
import classNames from '../_util/classNames';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import useStyle from './style';

const checkableTagProps = () => ({
prefixCls: String,
Expand All @@ -19,10 +20,14 @@ export type CheckableTagProps = Partial<ExtractPropTypes<ReturnType<typeof check
const CheckableTag = defineComponent({
compatConfig: { MODE: 3 },
name: 'ACheckableTag',
inheritAttrs: false,
props: checkableTagProps(),
// emits: ['update:checked', 'change', 'click'],
setup(props, { slots, emit }) {
setup(props, { slots, emit, attrs }) {
const { prefixCls } = useConfigInject('tag', props);
// Style
const [wrapSSR, hashId] = useStyle(prefixCls);

const handleClick = (e: MouseEvent) => {
const { checked } = props;
emit('update:checked', !checked);
Expand All @@ -31,17 +36,17 @@ const CheckableTag = defineComponent({
};

const cls = computed(() =>
classNames(prefixCls.value, {
classNames(prefixCls.value, hashId.value, {
[`${prefixCls.value}-checkable`]: true,
[`${prefixCls.value}-checkable-checked`]: props.checked,
}),
);

return () => {
return (
<span class={cls.value} onClick={handleClick}>
return wrapSSR(
<span {...attrs} class={cls.value} onClick={handleClick}>
{slots.default?.()}
</span>
</span>,
);
};
},
Expand Down
33 changes: 0 additions & 33 deletions components/tag/demo/controlled.vue

This file was deleted.

3 changes: 0 additions & 3 deletions components/tag/demo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<Checkable />
<Colorful />
<Control />
<Controlled />
<HotTags />
<Icon />
<Status />
Expand All @@ -16,7 +15,6 @@ import Basic from './basic.vue';
import Checkable from './checkable.vue';
import Colorful from './colorful.vue';
import Control from './control.vue';
import Controlled from './controlled.vue';
import HotTags from './hot-tags.vue';
import Icon from './icon.vue';
import Status from './status.vue';
Expand All @@ -32,7 +30,6 @@ export default defineComponent({
Checkable,
Colorful,
Control,
Controlled,
HotTags,
Icon,
Status,
Expand Down
13 changes: 6 additions & 7 deletions components/tag/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ Tag for categorizing or markup.

### Tag

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

### Tag Events

Expand Down
22 changes: 19 additions & 3 deletions components/tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { isPresetColor, isPresetStatusColor } from '../_util/colors';
import type { LiteralUnion } from '../_util/type';
import CheckableTag from './CheckableTag';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import warning from '../_util/warning';

import useStyle from './style';

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

const [wrapSSR, hashId] = useStyle(prefixCls);

const visible = ref(true);

// Warning for deprecated usage
if (process.env.NODE_ENV !== 'production') {
warning(
!('visible' in props),
'Tag',
'`visible` is deprecated, please use `<Tag v-show="visible" />` instead.',
);
}

watchEffect(() => {
if (props.visible !== undefined) {
visible.value = props.visible!;
Expand Down Expand Up @@ -70,7 +86,7 @@ const Tag = defineComponent({
);

const tagClassName = computed(() =>
classNames(prefixCls.value, {
classNames(prefixCls.value, hashId.value, {
[`${prefixCls.value}-${props.color}`]: isInternalColor.value,
[`${prefixCls.value}-has-color`]: props.color && !isInternalColor.value,
[`${prefixCls.value}-hidden`]: !visible.value,
Expand Down Expand Up @@ -117,13 +133,13 @@ const Tag = defineComponent({
const isNeedWave = 'onClick' in attrs;

const tagNode = (
<span class={tagClassName.value} style={tagStyle}>
<span {...attrs} class={tagClassName.value} style={tagStyle}>
{kids}
{renderCloseIcon()}
</span>
);

return isNeedWave ? <Wave>{tagNode}</Wave> : tagNode;
return wrapSSR(isNeedWave ? <Wave>{tagNode}</Wave> : tagNode);
};
},
});
Expand Down
13 changes: 6 additions & 7 deletions components/tag/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ cover: https://gw.alipayobjects.com/zos/alicdn/cH1BOLfxC/Tag.svg

### Tag

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

### 事件

Expand Down
129 changes: 0 additions & 129 deletions components/tag/style/index.less

This file was deleted.

Loading