forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
46 lines (45 loc) · 1.1 KB
/
utils.ts
File metadata and controls
46 lines (45 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { IconType, TitleContent, isI18nData, TipContent, isTitleConfig } from '@alilc/lowcode-types';
import { isValidElement } from 'react';
export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipContent, tipAsTitle?: boolean, noIcon?: boolean) {
if (!title) {
title = {};
if (!icon || tipAsTitle) {
title.label = tip;
tip = undefined;
}
}
if (icon || tip) {
if (typeof title !== 'object' || isValidElement(title) || isI18nData(title)) {
if (isValidElement(title)) {
if (title.type === 'svg' || (title.type as any).getIcon) {
if (!icon) {
icon = title as any;
}
if (tipAsTitle) {
title = tip as any;
tip = null;
} else {
title = undefined;
}
}
}
title = {
label: title,
icon,
tip,
};
} else {
title = {
...title,
icon,
tip,
};
}
}
if (isTitleConfig(title) && noIcon) {
if (!isValidElement(title)) {
title.icon = undefined;
}
}
return title;
}