Skip to content

Commit e819f57

Browse files
committed
1 parent d07b05a commit e819f57

File tree

6 files changed

+78
-12
lines changed

6 files changed

+78
-12
lines changed

packages/home/documentation-browser/model.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,10 @@ class Model {
397397
continue;
398398
}
399399

400-
let { label, icon, titleStyle } =
401-
getComponentVisualData(componentClass);
400+
let { label, icon, titleStyle } = getComponentVisualData(
401+
componentClass,
402+
undefined // projectStore is undefined here
403+
);
402404

403405
const componentInfoType = isProperSubclassOf(
404406
componentClass.objectClass.classInfo,

packages/project-editor/core/object.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,13 @@ export interface ClassInfo {
382382
icon?: React.ReactNode;
383383
getIcon?: (object: IEezObject) => React.ReactNode;
384384

385-
componentHeaderColor?: string;
385+
componentHeaderColor?:
386+
| ((
387+
object?: IEezObject,
388+
componentClass?: IObjectClassInfo,
389+
projectStore?: ProjectStore
390+
) => string)
391+
| string;
386392
componentHeaderTextColor?: string;
387393

388394
beforeLoadHook?: (

packages/project-editor/flow/component.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -4007,8 +4007,14 @@ function renderActionComponent(
40074007

40084008
let titleStyle: React.CSSProperties | undefined;
40094009
if (classInfo.componentHeaderColor) {
4010+
let backgroundColor;
4011+
if (typeof classInfo.componentHeaderColor == "string") {
4012+
backgroundColor = classInfo.componentHeaderColor;
4013+
} else {
4014+
backgroundColor = classInfo.componentHeaderColor(actionNode);
4015+
}
40104016
titleStyle = {
4011-
backgroundColor: classInfo.componentHeaderColor
4017+
backgroundColor
40124018
};
40134019
}
40144020

packages/project-editor/flow/components/actions/index.tsx

+41-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
getParent,
2222
MessageType,
2323
getId,
24-
IMessage
24+
IMessage,
25+
IObjectClassInfo
2526
} from "project-editor/core/object";
2627
import {
2728
getAncestorOfType,
@@ -30,6 +31,7 @@ import {
3031
getListLabel,
3132
getProjectStore,
3233
Message,
34+
ProjectStore,
3335
propertyNotFoundMessage,
3436
propertyNotSetMessage,
3537
Section
@@ -2106,7 +2108,28 @@ export class CallActionActionComponent extends ActionComponent {
21062108
<path d="M17 4a12.25 12.25 0 0 1 0 16"></path>
21072109
</svg>
21082110
),
2109-
componentHeaderColor: "#C7E9C0",
2111+
componentHeaderColor: (
2112+
object?: CallActionActionComponent,
2113+
componentClass?: IObjectClassInfo,
2114+
projectStore?: ProjectStore
2115+
) => {
2116+
let actionName;
2117+
if (object) {
2118+
actionName = object.action;
2119+
projectStore = ProjectEditor.getProjectStore(object);
2120+
} else if (componentClass) {
2121+
actionName = componentClass.props?.action;
2122+
}
2123+
2124+
if (projectStore && actionName) {
2125+
const action = findAction(projectStore.project, actionName);
2126+
if (action && action.implementationType == "native") {
2127+
return "#9CBA93";
2128+
}
2129+
}
2130+
2131+
return "#C7E9C0";
2132+
},
21102133
open: (object: CallActionActionComponent) => {
21112134
object.open();
21122135
},
@@ -4404,8 +4427,15 @@ export class LabelOutActionComponent extends ActionComponent {
44044427

44054428
let titleStyle: React.CSSProperties | undefined;
44064429
if (classInfo.componentHeaderColor) {
4430+
let backgroundColor;
4431+
if (typeof classInfo.componentHeaderColor == "string") {
4432+
backgroundColor = classInfo.componentHeaderColor;
4433+
} else {
4434+
backgroundColor = classInfo.componentHeaderColor(this);
4435+
}
4436+
44074437
titleStyle = {
4408-
backgroundColor: classInfo.componentHeaderColor
4438+
backgroundColor
44094439
};
44104440
}
44114441

@@ -4542,8 +4572,15 @@ export class LabelInActionComponent extends ActionComponent {
45424572

45434573
let titleStyle: React.CSSProperties | undefined;
45444574
if (classInfo.componentHeaderColor) {
4575+
let backgroundColor;
4576+
if (typeof classInfo.componentHeaderColor == "string") {
4577+
backgroundColor = classInfo.componentHeaderColor;
4578+
} else {
4579+
backgroundColor = classInfo.componentHeaderColor(this);
4580+
}
4581+
45454582
titleStyle = {
4546-
backgroundColor: classInfo.componentHeaderColor
4583+
backgroundColor
45474584
};
45484585
}
45494586

packages/project-editor/flow/components/components-registry.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ export function getComponentName(componentClassName: string) {
222222
return name;
223223
}
224224

225-
export function getComponentVisualData(componentClass: IObjectClassInfo) {
225+
export function getComponentVisualData(
226+
componentClass: IObjectClassInfo,
227+
projectStore: ProjectStore | undefined
228+
) {
226229
const classInfo = componentClass.objectClass.classInfo;
227230
let icon = classInfo.icon as any;
228231
let label = componentClass.displayName
@@ -232,10 +235,21 @@ export function getComponentVisualData(componentClass: IObjectClassInfo) {
232235

233236
let titleStyle: React.CSSProperties | undefined;
234237
if (classInfo.componentHeaderColor) {
238+
let backgroundColor;
239+
if (typeof classInfo.componentHeaderColor == "string") {
240+
backgroundColor = classInfo.componentHeaderColor;
241+
} else {
242+
backgroundColor = classInfo.componentHeaderColor(
243+
undefined,
244+
componentClass,
245+
projectStore
246+
);
247+
}
248+
235249
titleStyle = {
236-
backgroundColor: classInfo.componentHeaderColor,
250+
backgroundColor,
237251
color: tinycolor
238-
.mostReadable(classInfo.componentHeaderColor, ["#fff", "0x333"])
252+
.mostReadable(backgroundColor, ["#fff", "0x333"])
239253
.toHexString()
240254
};
241255
}

packages/project-editor/flow/editor/ComponentsPalette.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ const PaletteItem = observer(
377377
});
378378

379379
const { icon, label, titleStyle } = getComponentVisualData(
380-
this.props.componentClass
380+
this.props.componentClass,
381+
this.context
381382
);
382383

383384
return (

0 commit comments

Comments
 (0)