8000 [css-values-5] Add `spread()` to CSS · Issue #8391 · w3c/csswg-drafts · GitHub < 10000 meta http-equiv="x-pjax-css-version" content="57c9d6740d8537ca5f1993a321a39e33b170334d82f6f4aafea8acf63b700b98" data-turbo-track="reload">
[go: up one dir, main page]

Skip to content

[css-values-5] Add spread() to CSS #8391

@brandonmcconnell

Description

@brandonmcconnell

Proposal

It would help to add support for a new spread() in CSS that would work identically to var() except that it would spread any chained values contained in the variable as if they had each been used individually.

Syntax

The syntax would be something like this, expressed in JS/TS:

function spread(variable: string, currentDelimiter = ',', newDelimiter = currentDelimiter) {
  return variable.split(currentDelimiter).join(newDelimiter);
}

It could then be used in CSS like this:

* {
  --multiple-items: 1, 2, 3, 4, 5;
  --single-item: 6;
  some-prop: random-item(var(--ident); spread(--multiple-items); var(--multiple-items));
}

Using spread(), the random value in the example above would have an equal chance of being any of the six values—

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Without spread(), the random value generated would only be one of two options—

  • 1, 2, 3, 4, 5
  • 6

Alternative syntax

To keep this feature in line with others in CSS, I took a more functional approach using spread(), however, if we wanted to follow the trend of other languages, the traditional ... spread syntax could be employed, which would look like this:

* {
  --multiple-items: 1, 2, 3, 4, 5;
  --single-item: 6;
  some-prop: random-item(var(--ident); ...var(--multiple-items); var(--multiple-items));
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0