Create a utility class with currentColor & opacity support. #20244
-
|
I try to create a utility class with current color and opacity support @utility rule-col-current {
column-rule-color: currentColor;
column-rule-color: --alpha(currentColor / calc(--modifier(integer) * 1%));
column-rule-color: --alpha(currentColor / --modifier([percentage]));
}Here's a demo: But it isn't working. I try so many different ways, has anyone a clue? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hey! The Do you only want to have this utility available for For example, you could setup a @theme {
--column-rule-color-current: currentColor;
}
@utility rule-col-* {
column-rule-color: --value(--column-rule-color-*);
column-rule-color: --alpha(--value(--column-rule-color-*) / calc(--modifier(integer) * 1%));
column-rule-color: --alpha(--value(--column-rule-color-*) / --modifier([percentage]));
}This way any color in that namespace will be exposed. You can then map a name like If you want to re-use the default @theme {
--color-current: currentColor;
}
@utility rule-col-* {
column-rule-color: --value(--color-*);
column-rule-color: --alpha(--value(--color-*) / calc(--modifier(integer) * 1%));
column-rule-color: --alpha(--value(--color-*) / --modifier([percentage]));
}If you're only interested in the @utility rule-col-current-* {
column-rule-color: --value(--default(currentColor));
column-rule-color: --alpha(--value(--default(currentColor)) / calc(--modifier(integer) * 1%));
column-rule-color: --alpha(--value(--default(currentColor)) / --modifier([percentage]));
}The idea here is that the value is optional, so therefore you can use Let me know if this works for you. If your use case is a bit different, let me know and we'll get to a better solution instead. |
Beta Was this translation helpful? Give feedback.
-
|
Nice Idea |
Beta Was this translation helpful? Give feedback.
Hey! The
--modifier(…)(and--value(…)) is only available in functional utilities, meaning they are defined as@utility foo-*(with the-*). The idea is that this way you accept values, without the-*it's a "static" utility.Do you only want to have this utility available for
currentor for any kind of color?For example, you could setup a
column-rule-colornamespace:This wa…