fix: 🐛 title缺少icon字段,临时转接一下

需要后续相关同学增加api,已经标注
This commit is contained in:
凤矗 2020-05-05 14:38:19 +08:00
parent 89064f5c29
commit 2f9bb2567c

View File

@ -7,6 +7,8 @@ import {
TitleContent,
TransformedComponentMetadata,
NestingFilter,
isTitleConfig,
I18nData,
} from '@ali/lowcode-types';
import { computed } from '@ali/lowcode-editor-core';
import { Node, ParentalNode } from './document';
@ -17,6 +19,7 @@ import { IconPage } from './icons/page';
import { IconComponent } from './icons/component';
import { IconRemove } from './icons/remove';
import { IconClone } from './icons/clone';
import { ReactElement } from 'react';
function ensureAList(list?: string | string[]): string[] | null {
if (!list) {
@ -91,12 +94,20 @@ export class ComponentMeta {
private childWhitelist?: NestingFilter | null;
private _title?: TitleContent;
get title() {
get title(): string | I18nData | ReactElement {
// TODO: 标记下。这块需要康师傅加一下API页面正常渲染。
// string | i18nData | ReactElement
// TitleConfig title.label
if (isTitleConfig(this._title)) {
return (this._title.label as any) || this.componentName;
}
return this._title || this.componentName;
}
@computed get icon() {
// TODO: 标记下。这块需要康师傅加一下API页面正常渲染。
// give Slot default icon
// if _title is TitleConfig get _title.icon
return (
this._transformedMetadata?.icon ||
(this.componentName === 'Page' ? IconPage : this.isContainer ? IconContainer : IconComponent)
@ -131,10 +142,10 @@ export class ComponentMeta {
this._title =
typeof title === 'string'
? {
type: 'i18n',
'en-US': this.componentName,
'zh-CN': title,
}
type: 'i18n',
'en-US': this.componentName,
'zh-CN': title,
}
: title;
}