Skip to content

[css-values-5] Accept more than 2 values in *-mix(<progress>, ...) and progress() notations #11530

Open
@LeaVerou

Description

@LeaVerou

A common need in design systems is to get a value based on its position in a list. E.g. get the lightest color tint, or the smallest font-size etc.

In css-values-5 we define *-mix() functions (calc-mix(), color-mix() etc) that interpolate rather than mix, i.e. 0% gets you the first color and 100% the second one instead of the way around which is how the mixing version works.

This means they do not actually need to be limited to two arguments!
All we need to solve a lot of the use cases that motivated #10034 and a host more is to convert the grammars of these mix functions from:

<calc-mix()> = calc-mix( <progress>, <calc-sum>, <calc-sum> )
<color-mix()> =
  color-mix( [ <progress> && <color-interpolation-method>? ] , <color>, <color> ) |
  color-mix( <color-interpolation-method>, [<color> && <percentage [0,100]>?]#{2} )

to

<calc-mix()> = calc-mix( <progress>, <calc-sum># )
<color-mix()> =
  color-mix( [ <progress> && <color-interpolation-method>? ] , <color># ) |
  color-mix( <color-interpolation-method>, [<color> && <percentage [0,100]>?]#{2} )

And similarly for cross-fade() and transform-mix() though I haven't found use cases for these.

Yes, it can be emulated with the 2-value *-mix(), but the code to do it is abysmal and its complexity increases quadratically with the number of values.

The same argument applies to progress(), being the inverse of these. Currently it is defined as:

<progress()> = progress(<calc-sum>, <calc-sum>, <calc-sum>)

With this change, it would become:

<progress()> = progress(<calc-sum>, <calc-sum>#)

(or just progress( <calc-sum>#) but separating the first argument may be better for clarity)

A nice-to-have could also be to support percentages as well with the values, which would work in the same way as gradient color stops, i.e. affect how the interpolation works.

This is a change that only very slightly increases implementation effort for these functions, and would save authors a ton of pain, so it seems like a no-brainer to me.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Friday afternoon

    Status

    Tuesday Afternoon

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions