Skip to content

Commit 5a593d6

Browse files
committed
fix(alert): close属性同步为closeBtn,close即将废弃
closed #5618
1 parent 02c9fd3 commit 5a593d6

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

packages/components/alert/__tests__/index.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('Alert', () => {
1717
expect(wrapper.find('.t-alert__description').text()).toBe('text');
1818
});
1919

20-
it(':close', () => {
21-
const wrapper = mount(() => <Alert close>text</Alert>);
20+
it(':closeBtn', () => {
21+
const wrapper = mount(() => <Alert closeBtn>text</Alert>);
2222
const close = wrapper.find('.t-alert__close');
2323
expect(close.exists()).toBeTruthy();
2424
expect(wrapper.findComponent(CloseIcon).exists()).toBeTruthy();
@@ -116,7 +116,7 @@ describe('Alert', () => {
116116
it(':onClose', async () => {
117117
const fn = vi.fn();
118118
const wrapper = mount(() => (
119-
<Alert close onClose={fn}>
119+
<Alert closeBtn onClose={fn}>
120120
text
121121
</Alert>
122122
));

packages/components/alert/alert.en-US.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
name | type | default | description | required
88
-- | -- | -- | -- | --
9-
close | String / Boolean / Slot / Function | false | Typescript:`string \| boolean \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
9+
close | String / Boolean / Slot / Function | false | Deprecated, use closeBtn instead.。Typescript:`string \| boolean \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
10+
closeBtn | String / Boolean / Slot / Function | false | Close button. Value "true" show the close button. Value "False" hide close button. Value type string display as is. Use TNode to custom the close trigger.。Typescript:`string \| boolean \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1011
default | String / Slot / Function | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1112
icon | Slot / Function | - | Typescript:`TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1213
maxLine | Number | 0 | \- | N
1314
message | String / Slot / Function | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1415
operation | Slot / Function | - | Typescript:`TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
15-
theme | String | info | optionssuccess/info/warning/error | N
16+
theme | String | info | options: success/info/warning/error | N
1617
title | String / Slot / Function | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1718
onClose | Function | | Typescript:`(context: { e: MouseEvent }) => void`<br/> | N
1819
onClosed | Function | | Typescript:`(context: { e: TransitionEvent }) => void`<br/> | N

packages/components/alert/alert.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
:: BASE_DOC ::
22

33
## API
4+
45
### Alert Props
56

6-
名称 | 类型 | 默认值 | 说明 | 必传
7+
名称 | 类型 | 默认值 | 描述 | 必传
78
-- | -- | -- | -- | --
8-
close | String / Boolean / Slot / Function | false | 关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮。TS 类型:`string \| boolean \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
9+
close | String / Boolean / Slot / Function | false | 即将废弃,请使用 closeBtn 属性。关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮。TS 类型:`string \| boolean \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
10+
closeBtn | String / Boolean / Slot / Function | false | 关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮。TS 类型:`string \| boolean \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
911
default | String / Slot / Function | - | 内容,同 message。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1012
icon | Slot / Function | - | 图标。TS 类型:`TNode`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/packages/components/common.ts) | N
1113
maxLine | Number | 0 | 内容显示最大行数,超出的内容会折叠收起,用户点击后再展开。值为 0 表示不折叠 | N

packages/components/alert/alert.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { on, off, addClass } from '@tdesign/shared-utils';
1212
import props from './props';
1313
import { SlotReturnValue } from '../common';
1414
import { useIcon, useConfig, useTNodeJSX, useGlobalIcon, usePrefixClass } from '@tdesign/shared-hooks';
15+
import log from '@tdesign/common-js/log/log';
1516

1617
export default defineComponent({
1718
name: 'TAlert',
@@ -54,7 +55,13 @@ export default defineComponent({
5455
};
5556

5657
const renderClose = () => {
57-
const { close } = props;
58+
// close属性变更为closeBtn过渡期使用,close废弃后可删除。(需兼容标签上直接写close和closeBtn的场景)
59+
const { closeBtn } = props;
60+
const isUsingClose = props.close || typeof props.close === 'string';
61+
const close = isUsingClose ? props.close : closeBtn;
62+
if (isUsingClose) {
63+
log.warnOnce('TAlert', 'prop `close` is going to be deprecated, please use `closeBtn` instead.');
64+
}
5865
let closeContent = null;
5966
if (close === true || close === '') {
6067
closeContent = <CloseIcon />;

packages/components/alert/props.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
/**
44
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
5-
* updated at 2021-12-12 19:17:30
65
* */
76

87
import { TdAlertProps } from './type';
98
import { PropType } from 'vue';
109

1110
export default {
12-
/** 关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮 */
11+
/** 即将废弃,请使用 closeBtn 属性。关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮 */
1312
close: {
1413
type: [String, Boolean, Function] as PropType<TdAlertProps['close']>,
15-
default: false,
14+
default: false as TdAlertProps['close'],
15+
},
16+
/** 关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮 */
17+
closeBtn: {
18+
type: [String, Boolean, Function] as PropType<TdAlertProps['closeBtn']>,
19+
default: false as TdAlertProps['closeBtn'],
1620
},
1721
/** 内容,同 message */
1822
default: {
@@ -40,6 +44,7 @@ export default {
4044
type: String as PropType<TdAlertProps['theme']>,
4145
default: 'info' as TdAlertProps['theme'],
4246
validator(val: TdAlertProps['theme']): boolean {
47+
if (!val) return true;
4348
return ['success', 'info', 'warning', 'error'].includes(val);
4449
},
4550
},

packages/components/alert/type.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
/**
44
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
5-
* updated at 2021-12-12 19:17:30
65
* */
76

87
import { TNode } from '../common';
98

109
export interface TdAlertProps {
1110
/**
12-
* 关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮
11+
* 即将废弃,请使用 closeBtn 属性。关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮
1312
* @default false
1413
*/
1514
close?: string | boolean | TNode;
15+
/**
16+
* 关闭按钮。值为 true 则显示默认关闭按钮;值为 false 则不显示按钮;值类型为 string 则直接显示;值类型为 Function 则可以自定关闭按钮
17+
* @default false
18+
*/
19+
closeBtn?: string | boolean | TNode;
1620
/**
1721
* 内容,同 message
1822
*/

0 commit comments

Comments
 (0)