-
Notifications
You must be signed in to change notification settings - Fork 676
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
[css-color-5] color-scale()
for creating color scales via interpolation
#10034
Comments
I can see advantages (more generally useful) and disadvantages (cumbersome syntax) to the second option. I'm not sure which is the better option, 1 or 2. The functionality seems very useful, clearly. |
All the examples omit the optional percentage for stop position; it would be good to add an example that explicitly uses stop positioning. |
The success-failure scale does. |
As we noticed privately, I posted essentially the exact same idea just a few hours prior to yours (decent chance we overlapped in authoring the texts!) in #9992 (comment). Notable differences are:
If stops can have an implicit position, then you have to rely on numeric precision to allow overriding to work. Like, given |
As I wrote in my reply today:
|
I'm sorry, I'm not sure I understand what most of these replies have to do with what I was saying. I suspect you're reading some additional stuff I didn't say into my post.
In #9992 this seemed to be a relatively important part of the proposals for you. Why is it so much lower priority here?
I'm not sure what this entire paragraph is in reference to.
I'm not sure how what I said in my most recent reply has any bearing on this. Can you elaborate on what problem you're seeing here?
As I said, the end user being able to override a specific color choice from a design system's color scale seemed to be an important thing in your comments in #9992. What's different about this situation, where the color scale is encapsulated into a value rather than being implicit across multiple custom properties? |
I was reminded about this when I came across https://noahliebman.net/2024/04/recursion-in-the-stylesheet/ . These are the lengths authors have to go to today to achieve this. Here’s my attempt at a green-yellow-orange-red scale without a preprocessor: https://codepen.io/leaverou/pen/ZENWMZr?editors=1100 After thinking about it some more, I don’t think overriding individual colors is something that should drive the design of this feature, and certainly not something that warrants complicating the base case. Authors can always override the individual colors used to generate the scale, and design systems can make sure to include enough extension points if they want to enable this. I think we should keep the MVP as simple as possible. This means:
Something like this:
Which would look like this: --scale: in oklch, var(--color-green), var(--color-yellow) 40%, var(--color-orange) 60%, var(--color-red));
background: color-scale(at var(--progress) var(--scale)); I’m in two minds about whether the position you are selecting should be part of the preamble like above, slash separated, or even a separate argument. One consideration is that while colors are possibly the most pressing need, length scales are also in wide usage (example). Whatever syntax we come up with should be consistent across different types of scales. |
color-scale()
for interpolating across multiple colorscolor-scale()
for creating color scales via interpolation
During the discussion in #9992 it occurred to me that one of the things that could really help simplify the color-related design systems use cases would be a way to define a gradient line and pick a color on it.
Why?
color-mix()
is not very friendly to that. Super common example: the failure-success scale of red, orange, yellow, green. Yelp ratings are a popular application (and no, this is not just a simple polar interpolation between the endpoints):linear-gradient()
.Syntax
Option 1: Single function for both defining the scale, and selecting a color
Example usage:
This is basically modeled after
linear-gradient()
with the non relevant parts removed (lengths,to <whatever>
, angles).It could also allow
<1d-image>
/stripes()
to facilitate discrete scales.The reason the percentage is separated from the rest with a
/
is to facilitate storing the actual scale part into variables and passing them around without having to worry about whether you need to specify a comma or not (depending on whether the scale has a<color-interpolation-method>
).Pros:
Cons:
Option 2: Separate scale definition and color selection
This syntax decouples the scale from the color selection.
It seems more conceptually sound, but also too many parens.
Example:
the parens could be reduced if it would be possible to define tokens like:
Example:
but I suspect @tabatkins will have a good reason to rule that out 😁
We could also make it a variant of
color-mix()
:Example:
Though since conceptually we're not mixing anything, I don't think this is worth it.
More Examples
Yellow tints that skew oranger when darker
Option 1:
Transparent variations of a base color
Option 1:
Option 2:
Success/failure scales
This is super common to communicate varying levels of success/failure.
There are two main forms: red - orange - yellow - green - dark green, or red - white - green.
E.g. see screenshot from Coda’s conditional formatting:
Especially the red - orange - yellow - green scales almost always require manual correction, and cannot be done with a single 2 color interpolation (yes not even in polar spaces).
With
color-scale()
they can be as simple as:The text was updated successfully, but these errors were encountered: