Skip to content

Commit 3e04282

Browse files
committed
Designer: Fix parent fill color handling
1 parent c2686d4 commit 3e04282

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

packages/adaptive-ui-designer-core/src/node.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ export abstract class PluginNode {
210210
*/
211211
public abstract get parent(): PluginNode | null;
212212

213+
/**
214+
* Gets the effective fill color of this node, either locally applied or from an ancestor.
215+
*/
216+
public abstract get effectiveFillColor(): Color | null;
217+
213218
/**
214219
* Gets the style properties this node supports.
215220
*/
@@ -332,9 +337,9 @@ export abstract class PluginNode {
332337
this._additionalData.set(AdditionalDataKeys.codeGenName, this.codeGenName);
333338
}
334339

335-
if (!this._additionalData.has(AdditionalDataKeys.toolParentFillColor) && this.parent?.fillColor) {
336-
// console.log("PluginNode.get_additionalData - adding:", AdditionalDataKeys.toolParentFillColor, this.debugInfo, formatHex8(this.parent?.fillColor));
337-
this._additionalData.set(AdditionalDataKeys.toolParentFillColor, formatHex8(this.parent.fillColor));
340+
if (!this._additionalData.has(AdditionalDataKeys.toolParentFillColor) && this.parent?.effectiveFillColor) {
341+
// console.log("PluginNode.get_additionalData - adding:", AdditionalDataKeys.toolParentFillColor, this.debugInfo, formatHex8(this.parent?.effectiveFillColor));
342+
this._additionalData.set(AdditionalDataKeys.toolParentFillColor, formatHex8(this.parent.effectiveFillColor));
338343
}
339344

340345
return this._additionalData;

packages/adaptive-ui-designer-figma-plugin/src/figma/node.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ export class FigmaPluginNode extends PluginNode {
749749
return null;
750750
}
751751

752-
// console.log(" get parent");
752+
// console.log(" get parent", this.debugInfo);
753753
return FigmaPluginNode.get(parent, false);
754754
}
755755

@@ -776,14 +776,24 @@ export class FigmaPluginNode extends PluginNode {
776776
return null;
777777
}
778778

779+
public get effectiveFillColor(): Color | null {
780+
if (this.fillColor) {
781+
return this.fillColor;
782+
}
783+
if (this.parent) {
784+
return this.parent.fillColor;
785+
}
786+
return null;
787+
}
788+
779789
private darkTarget: number = (-0.1 + Math.sqrt(0.21)) / 2;
780790

781791
public handleManualDarkMode(): boolean {
782792
if (isInstanceNode(this._node)) {
783793
if (this._node.variantProperties) {
784794
const currentDarkMode = this._node.variantProperties["Dark mode"];
785795
if (currentDarkMode) {
786-
const color = this.parent?.fillColor;
796+
const color = this.parent?.effectiveFillColor;
787797
if (color) {
788798
const containerIsDark = wcagLuminance(color) <= this.darkTarget;
789799
// eslint-disable-next-line max-len

packages/adaptive-ui-designer-figma-plugin/src/ui/ui-controller-elements.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ElementsController {
3939
this.rootElement.removeChild(child)
4040
);
4141

42-
this.resetFillColor(this.rootElement);
42+
this.resetFillColor();
4343

4444
this.controller.selectedNodes.forEach(node => this.setupDesignTokenElement(this.rootElement, node));
4545
}
@@ -182,13 +182,15 @@ export class ElementsController {
182182

183183
/**
184184
* Resets the `fill-color` token value on the full element tree.
185-
*
186-
* @param element - The top element, recursive
187185
*/
188-
public resetFillColor(element: FASTElement) {
186+
public resetFillColor() {
187+
this.resetFillColorForElement(this.rootElement);
188+
}
189+
190+
private resetFillColorForElement(element: FASTElement) {
189191
this.setDesignTokenForElement(element, fillColor, null);
190192
element.childNodes.forEach(child =>
191-
this.resetFillColor(child as unknown as FASTElement)
193+
this.resetFillColorForElement(child as unknown as FASTElement)
192194
);
193195
}
194196
}

packages/adaptive-ui-designer-figma-plugin/src/ui/ui-controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export class UIController {
168168
*/
169169
public refreshSelectedNodes(reason: string = "refreshSelectedNodes"): void {
170170
// console.log(" Evaluating all design tokens for all selected nodes");
171+
this._elements.resetFillColor();
172+
171173
this.evaluateEffectiveAppliedStyleValues(this._selectedNodes);
172174

173175
const message: PluginMessage = {
@@ -358,15 +360,15 @@ export class UIController {
358360
if (valueOriginal instanceof Color) {
359361
const swatch = valueOriginal;
360362
value = formatHex8(swatch.color);
361-
// valueDebug = swatch;
363+
// valueDebug = swatch.toColorString();
362364
} else if (typeof valueOriginal === "string") {
363365
if (valueOriginal.startsWith("calc")) {
364366
const ret = calc(valueOriginal as string);
365367
// console.log(` calc ${value} returns ${ret}`);
366368
value = ret;
367369
}
368370
}
369-
// const fillColorValue = this._elements.getDesignTokenValue(node, fillColor);
371+
// const fillColorValue = (this._elements.getDesignTokenValue(node, fillColor) as Swatch).toColorString();
370372
// console.log(" evaluateEffectiveAppliedDesignToken", target, " : ", token.name, " -> ", value, valueDebug, `(from ${source})`, "fillColor", fillColorValue);
371373

372374
const applied = new AppliedStyleValue(value);

0 commit comments

Comments
 (0)