Skip to content

Commit 3b77692

Browse files
michaelgold3nMichael Golden
andauthored
fix: don't add opacity modifier for variable colors (#250)
When a color is from a Figma variable that already contains alpha, the output was incorrectly adding an opacity modifier like /50. For example, a variable 'myVar' defined as rgba(255,0,0,0.5) was generating 'bg-myVar/50' instead of just 'bg-myVar'. The fix skips the opacity modifier when colorType is 'variable' since the alpha is already baked into the variable definition. Adding the modifier would incorrectly compound the opacity. Fixes #232 Co-authored-by: Michael Golden <michael@wayframe.com>
1 parent 6fcdcc3 commit 3b77692

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

packages/backend/src/tailwind/builderImpl/tailwindColor.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ export const tailwindSolidColor = (
8181
}
8282

8383
// Original implementation for non-variable colors or when not using var syntax
84-
const { colorName } = getColorInfo(fill);
84+
const { colorName, colorType } = getColorInfo(fill);
85+
86+
// Don't add opacity modifier for variable colors - the alpha is already baked
87+
// into the variable definition. Adding /50 to a variable that's already
88+
// defined with alpha would incorrectly compound the opacity.
89+
if (colorType === "variable") {
90+
return `${kind}-${colorName}`;
91+
}
92+
8593
const effectiveOpacity = calculateEffectiveOpacity(fill);
8694
const opacity =
8795
effectiveOpacity !== 1.0 ? `/${nearestOpacity(effectiveOpacity)}` : "";
@@ -101,7 +109,14 @@ export const tailwindGradientStop = (
101109
stop: ColorStop,
102110
parentOpacity: number = 1.0,
103111
): string => {
104-
const { colorName } = getColorInfo(stop);
112+
const { colorName, colorType } = getColorInfo(stop);
113+
114+
// Don't add opacity modifier for variable colors - the alpha is already baked
115+
// into the variable definition
116+
if (colorType === "variable") {
117+
return colorName;
118+
}
119+
105120
const effectiveOpacity = calculateEffectiveOpacity(stop, parentOpacity);
106121
const opacity =
107122
effectiveOpacity !== 1.0 ? `/${nearestOpacity(effectiveOpacity)}` : "";

0 commit comments

Comments
 (0)