Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle variable colors that have variable fallback values #12049

Merged
merged 2 commits into from
Sep 20, 2023

Conversation

thecrypticace
Copy link
Contributor

We couldn't parse variables in arbitrary values which had a fallback that was itself a variable and as a result would produce nothing when such a color was used in bg-* or text-* or any other color utility.

Basically this didn't work because the presence of the alpha value forces us to parse the color format:

bg-[rgb(var(--some-var,var(--some-other-var)))]/50

This PR fixes it and it now produces the following CSS:

.bg-\[rgb\(var\(--some-var\,var\(--some-other-var\)\)\)\]\/50 {
  background-color: rgb(var(--some-var, var(--some-other-var)) / 0.5);
}

This implementation is limited because regexes are not recursive. For example, it can't handle another variable fallback like this:

bg-[rgb(var(--some-var,var(--some-other-var,var(--some-other-var-3))))]/50

Doing so would require replacing these regexes with an actual mini tokenizer and parser but that's a task for another day.

Fixes #12048

@thecrypticace thecrypticace changed the title Parse colors even when variable has fallback that is a variable Handle variable colors that have variable fallback values Sep 20, 2023
@thecrypticace thecrypticace merged commit d3f2221 into master Sep 20, 2023
10 checks passed
@thecrypticace thecrypticace deleted the fix/color-variable-with-variable-fallback branch September 20, 2023 20:34
thecrypticace added a commit that referenced this pull request Oct 23, 2023
* Parse colors even when variable has fallback that is a variable

* Update changelog
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.

Background opacity modifier does not work with CSS variable's fallback value
1 participant