Skip to content

Commit 483310b

Browse files
authored
feat(welcome): support vnode getter (#343)
1 parent 0fa333b commit 483310b

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

docs/component/welcome.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ welcome/background
4242
| 属性 | 说明 | 类型 | 默认值 | 版本 |
4343
| --- | --- | --- | --- | --- |
4444
| classNames | 自定义样式类名,用于各个提示项的不同部分。 | Record<'icon' \| 'title' \| 'description' \| 'extra', string> | - | - |
45-
| description | 显示在提示列表中的描述。 | VNode \| string | - | - |
46-
| extra | 显示在提示列表末尾的额外操作。 | VNode | - | - |
47-
| icon | 显示在提示列表前侧的图标。 | VNode | - | - |
45+
| description | 显示在提示列表中的描述。 | VNode \| string \| (() => VNode \| string) | - | - |
46+
| extra | 显示在提示列表末尾的额外操作。 | VNode \| string \| (() => VNode \| string) | - | - |
47+
| icon | 显示在提示列表前侧的图标。 | VNode \| () => VNode | - | - |
4848
| rootClassName | 根节点的样式类名。 | string | - | - |
4949
| styles | 自定义样式,用于各个提示项的不同部分。 | Record<'icon' \| 'title' \| 'description' \| 'extra', CSSProperties> | - | - |
50-
| title | 显示在提示列表顶部的标题。 | VNode \| string | - | - |
50+
| title | 显示在提示列表顶部的标题。 | VNode \| string \| (() => VNode \| string) | - | - |
5151
| variant | 变体类型。 | 'filled' \| 'borderless' | 'filled' | - |
5252

5353
### Welcome Slots

src/welcome/Welcome.vue

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
4747
4848
// ============================= Icon =============================
4949
const iconNode = computed(() => {
50-
const _icon = slots.icon ? slots.icon() : icon;
50+
const _icon = slots.icon
51+
? slots.icon()
52+
: typeof icon === 'function'
53+
? icon()
54+
: icon;
55+
5156
if (!_icon) {
5257
return null;
5358
}
@@ -67,7 +72,12 @@ const iconNode = computed(() => {
6772
});
6873
6974
const titleNode = computed(() => {
70-
const _title = slots.title ? slots.title() : title;
75+
const _title = slots.title
76+
? slots.title()
77+
: typeof title === 'function'
78+
? title()
79+
: title;
80+
7181
if (!_title) {
7282
return null;
7383
}
@@ -92,11 +102,16 @@ const descriptionNode = computed(() => {
92102
if (slots.description) {
93103
return slots.description();
94104
}
95-
return description;
105+
return typeof description === 'function' ? description() : description;
96106
})
97107
98108
const extraNode = computed(() => {
99-
const _extra = slots.extra ? slots.extra() : extra;
109+
const _extra = slots.extra
110+
? slots.extra()
111+
: typeof extra === 'function'
112+
? extra()
113+
: extra;
114+
100115
if (!_extra) {
101116
return null;
102117
}

src/welcome/interface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface WelcomeProps {
1414
styles?: Partial<Record<SemanticType, CSSProperties>>;
1515

1616
// Layout
17-
icon?: VNode | string;
18-
title?: VNode | string;
19-
description?: VNode | string;
20-
extra?: VNode;
17+
icon?: VNode | string | (() => VNode | string);
18+
title?: VNode | string | (() => VNode | string);
19+
description?: VNode | string | (() => VNode | string);
20+
extra?: VNode | string | (() => VNode | string);
2121
}

0 commit comments

Comments
 (0)