question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

variable colors with <alpha-value> not working with theme function on plugins

See original GitHub issue

I’m trying to create a plugin for Tailwind 3.1.8, but when I use variables on colors with the new syntax - rgb(var(--primary) / <alpha-value>) - the color stop working.

I created an example on https://play.tailwindcss.com/2apCJBfHdC

Removing the / <alpha-value> from the color value make things work again.

I’m doing something wrong?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:23
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
thecrypticacecommented, Oct 20, 2022

No worries! Sorry for the late reply. We have been thinking this through some but other things took priority for the v3.2 release.

The reason it doesn’t work for plugins like this is two fold:

  1. addUtilities doesn’t do anything fancy like parsing data types. It’s basically to put pure CSS into the stylesheet whenever a utility is used (and it can handle variants ofc)
  2. matchUtilities does parse data types and it takes a type option that lists all acceptable “types” for a plugin — as well as a list of values. You get the <alpha-value> behavior for “free” when using it and your type list includes color.

For example, this works today: https://play.tailwindcss.com/1a6LIjNR2S?file=config — Except for the DEFAULT case + opacity modifier which I believe is a bug but I’ll have to check on that. However, we’re also thinking through what we want to work here.

I think that in an ideal world each plugin would take in the opacity and modify the color itself (or we provide a function to do this for you — not sure though). And we could remove this special case for the color type. We’re going to try to dedicate some time soon-ish to figuring out how this should work at a high level for plugin authors to see if:

  1. The existing matchUtilities API / workaround is what we want; OR
  2. If there’s a better, more automatic API that we can design and implement.
3reactions
Kosai106commented, Aug 27, 2022

Looks like a PR was opened about this in the past but somehow the behaviour isn’t working anymore. https://github.com/tailwindlabs/tailwindcss/pull/8652

~Related, it would be nice to be able to overwrite the <alpha-value> when using theme(), which I don’t believe is possible currently.~ Looks like that is possible. https://github.com/tailwindlabs/tailwindcss/pull/9008

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tailwind custom theme color opacity not being applied
I defined the colors as CSS variables in the index.css file, but setting alpha values does not work for those colors. Here is...
Read more >
How to combine SASS color functions and CSS Variables
A new method, supported in all browsers, to store your colors in CSS Variables and modify them using SASS functions.
Read more >
Tailwind CSS v3.1: You wanna get nuts? Come on, let's get nuts!
Change color opacity when using the theme function; Easier CSS variable color configuration; Border spacing utilities; Enabled and optional ...
Read more >
rgba color in CSS variable - WordPress.org
I'm not a dev but i did this function maybe you can make it better and add it on your plugin as feature...
Read more >
Theme Color | Visual Studio Code Extension API
If no alpha value is defined, it defaults to ff (opaque, no transparency). If alpha is set to 00 , the color is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found