2020-04-27 02:12:43 +08:00

29 lines
645 B
TypeScript

import { IconType, TitleContent, isI18nData, TipContent } from '@ali/lowcode-types';
import { isValidElement } from 'react';
export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipContent, tipAsTitle?: boolean) {
if (!title) {
title = {};
if (!icon || tipAsTitle) {
title.label = tip;
tip = undefined;
}
}
if (icon || tip) {
if (typeof title !== 'object' || isValidElement(title) || isI18nData(title)) {
title = {
label: title,
icon,
tip,
};
} else {
title = {
...title,
icon,
tip
};
}
}
return title;
}