mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +00:00
fix panel title
This commit is contained in:
parent
73699ffe67
commit
ca1e49a969
@ -59,14 +59,14 @@ export default class PanelDock implements IWidget {
|
||||
this.id = uniqueId(`dock:${name}$`);
|
||||
this.panelName = config.panelName || name;
|
||||
if (content) {
|
||||
const _panelProps: any = { ...panelProps };
|
||||
if (_panelProps.title == null && props) {
|
||||
_panelProps.title = composeTitle(props.title, undefined, props.description, true, true);
|
||||
}
|
||||
this._panel = this.skeleton.add({
|
||||
type: "Panel",
|
||||
name: this.panelName,
|
||||
props: {
|
||||
// FIXME! give default title for panel
|
||||
title: props ? composeTitle(props?.title, props?.icon, props?.description, true) : '',
|
||||
...panelProps,
|
||||
},
|
||||
props: _panelProps,
|
||||
contentProps,
|
||||
content,
|
||||
area: panelProps?.area
|
||||
|
||||
@ -60,6 +60,9 @@ export default class Panel implements IWidget {
|
||||
this.plain = hideTitleBar || !title;
|
||||
this.help = help;
|
||||
if (Array.isArray(content)) {
|
||||
if (content.length === 1) {
|
||||
// todo: not show tabs
|
||||
}
|
||||
this.container = this.skeleton.createContainer(
|
||||
name,
|
||||
(item) => {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { IconType, TitleContent, isI18nData, TipContent } from '@ali/lowcode-types';
|
||||
import { IconType, TitleContent, isI18nData, TipContent, isTitleConfig } from '@ali/lowcode-types';
|
||||
import { isValidElement } from 'react';
|
||||
|
||||
export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipContent, tipAsTitle?: boolean) {
|
||||
export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipContent, tipAsTitle?: boolean, noIcon?: boolean) {
|
||||
if (!title) {
|
||||
title = {};
|
||||
if (!icon || tipAsTitle) {
|
||||
@ -11,6 +11,17 @@ export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipCon
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
title = {
|
||||
label: title,
|
||||
icon,
|
||||
@ -24,5 +35,8 @@ export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipCon
|
||||
};
|
||||
}
|
||||
}
|
||||
if (isTitleConfig(title) && noIcon) {
|
||||
title.icon = undefined;
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { ReactElement, ReactNode } from 'react';
|
||||
import { I18nData } from './i18n';
|
||||
import { I18nData, isI18nData } from './i18n';
|
||||
import { TipContent } from './tip';
|
||||
import { IconType } from './icon';
|
||||
|
||||
@ -13,6 +13,14 @@ export interface TitleConfig {
|
||||
|
||||
export type TitleContent = string | I18nData | ReactElement | TitleConfig;
|
||||
|
||||
export function isTitleConfig(obj: any): obj is TitleConfig {
|
||||
return obj && (obj.label || obj.tip || obj.icon);
|
||||
function isPlainObject(value: any): value is object {
|
||||
if (typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
const proto = Object.getPrototypeOf(value);
|
||||
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null;
|
||||
}
|
||||
|
||||
export function isTitleConfig(obj: any): obj is TitleConfig {
|
||||
return isPlainObject(obj) && !isI18nData(obj);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { isObject } from './is-object';
|
||||
|
||||
export function isPlainObject(value: any) {
|
||||
export function isPlainObject(value: any): value is object {
|
||||
if (!isObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user