Support colors with alpha values #95
RyanClementsHax
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hello! I would love this as an option. We do not tend to use opacity due to how our designers manage tokens and because we wish to use different primitives with different opacities between themes. This is currently preventing me from using your wonderful library. I'd be happy to forgo opacity support if it meant my alpha channels were not stripped. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Below is the feature request for supporting colors with alpha values when theming. I'd love feedback from the community before implementing this feature. Here are all of my thoughts so far. Let me know what y'all think and if there are any other implementations we could consider.
Background
Currently this plugin strips the alpha channel from any color it is configured to theme. This is to support tailwind's opacity classes.
For example, if you use a class like
text-gray-50
, a default tailwind class, the following class gets generated.Tailwind then is able to control the opacity with
--tw-text-opacity
. For example, the classtext-opacity-50
would generate the following class.tailwindcss-themer
tries to honor this feature. For example, if you have a plugin config like the following........and use a class like
text-primary
, the following classes will be generated.This allows colors to be themed and opacity classes to work. This plugin, as a result, needs to strip the alpha value from the specified color for this to work as there is no way to configure the
--tw-text-opacity
variable (to the best of my knowledge).Problem
There are real use cases for using
tailwindcss-themer
with colors with alpha values, but tailwind's doesn't allow for the default opacity value of colors to be specified. In other words:This thereby forces devs to choose between having a themed color that uses the alpha channel and that color's opacity being configurable via tailwind's opacity classes.
Use cases
Color palettes with alpha values
Some devs want to use palettes with that use alpha values like radix ui colors as exemplified in #74.
transparent
Some devs want to have
transparent
be a theme value as exemplified in #77.Options
(Preferred) Use the opacity modifier syntax.
Configure the default opacity value by using a value like
rgb(255 0 0 / <alpha-value>)
for all colors without alpha channels and replace<alpha-value>
with the alpha channel value for colors with alpha e.g.rgb(255 0 0 / 0.5)
. The docs unfortunately don't reflect this, but this is a supported behavior.Pros:
Cons:
(Preferred)Work with tailwind upstream to allow this to be configurableThis would entail getting this committed upstream so this plugin could configure that value.
Pros:
Cons:
Silently opt out of opacity classes when a color with an alpha channel is given
This would mean that this plugin preserves the alpha channel but doesn't allow that color to be configurable via opacity classes.
Pros:
Cons:
Resolution
Setting the default opacity value is supported via the opacity modifier syntax. The docs unfortunately don't reflect this which is why this took longer than expected to implement.
PR: #111
Beta Was this translation helpful? Give feedback.
All reactions