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