fix: don't add opacity modifier for variable colors by michaelgold3n · Pull Request #250 · bernaferrari/FigmaToCode · GitHub
Skip to content

fix: don't add opacity modifier for variable colors#250

Merged
bernaferrari merged 1 commit into
bernaferrari:mainfrom
michaelgold3n:fix-variable-color-opacity
Feb 4, 2026
Merged

fix: don't add opacity modifier for variable colors#250
bernaferrari merged 1 commit into
bernaferrari:mainfrom
michaelgold3n:fix-variable-color-opacity

Conversation

@michaelgold3n

Copy link
Copy Markdown
Contributor

Problem

When a color is from a Figma variable that already contains alpha (e.g., rgba(255,0,0,0.5)), the Tailwind output was incorrectly adding an opacity modifier.

Expected: bg-myVar
Actual: bg-myVar/50

This is incorrect because:

  1. The variable already contains the alpha value
  2. Adding /50 compounds the opacity (50% of 50% = 25%)

Solution

Skip the opacity modifier when colorType is 'variable' since the alpha is already baked into the variable definition.

Changes made in tailwindColor.ts:

  • tailwindSolidColor(): Return early for variable colors without opacity suffix
  • tailwindGradientStop(): Same fix for gradient stops

Testing

  • Build passes
  • No TypeScript errors

Fixes #232

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 bernaferrari#232
@bernaferrari bernaferrari merged commit 3b77692 into bernaferrari:main Feb 4, 2026
1 check passed
@bernaferrari

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Tailwind output is adding /${opacity} even if color variable already contains alpha

2 participants