Skip to content

Commit

Permalink
[css-values-5] Define ident()
Browse files Browse the repository at this point in the history
  • Loading branch information
bramus committed Dec 30, 2024
1 parent 2f1a48a commit ba9fa30
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions css-values-5/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,94 @@ Security</h4>
''--foo: attr(foo type(&lt;number&gt;)); background-image: src(string(var(--foo)))''
needs to be invalid as well.

<!-- Big Text: ident()

████ ████▌ █████▌ █ █▌ █████▌ ██ ██
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
▐▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ▐█
▐▌ █▌ █▌ ████ █▌▐█ █▌ █▌ █▌ ▐█
▐▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ ▐█
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
████ ████▌ █████▌ █▌ ▐▌ █▌ ██ ██
-->

<h3 id=ident>
Constructing <<custom-ident>> values: the ''ident()'' function</h3>

<!-- https://github.com/w3c/csswg-drafts/issues/9141 -->

The <dfn>ident()</dfn> function is an [=arbitrary substitution function=]
that can be used to manually construct <<custom-ident>> values from several parts.

<pre class=prod>
<dfn><<ident-fn>></dfn> = ident(<<ident-args>>);
<dfn><<ident-args>></dfn> = [<<string>> | <<integer>> | <<ident>>]+
</pre>

Issue: Should we allow a fallback value?

The ''ident()'' function can be used as a value for any property or function argument
that accepts a <<custom-ident>>.

<div class=example>
In the following example,
each matched element gets a unique <dfn><<'view-timeline-name'>></dfn>
in the format of <code>"vtl-<em>number</em>"</code>.
The <code><em>number</em></code> is generated using ''sibling-index()''.

```css
.item {
/* vtl-1, vtl-2, vtl-3, … */
view-timeline-name: ident("vtl-" sibling-index());
}
```
</div>

While in many cases ''attr()'' with the <<attr-type>> set to <code>type(<<custom-ident>>)</code> will do,
''ident()'' can be used to construct a <<custom-ident>> using values that come from other elements.

<div class=example>
In the following example, the ''ident()'' function uses a custom property
which is defined on a parent.

```css
.card[id] {
/* E.g. card1, card2, card3, … */
--id: attr(id);

view-transition-name: var(--id);
view-transition-class: card;

h1 {
/* E.g. card1-title, card2-title, card3-title, … */
view-transition-name: ident(var(--id) "-title");
view-transition-class: card-title;
}
}
```
</div>

To generate a <<dashed-ident>>, put <code>"--"</code> as the first argument.

<div class=example>

```css
.card[id] {
/* E.g. card1, card2, card3, … */
--id: attr(id);

view-transition-name: var(--id);
view-transition-class: card;

h1 {
/* E.g. card1-title, card2-title, card3-title, … */
view-transition-name: ident(var(--id) "-title");
view-transition-class: card-title;
}
}
```
</div>

<!-- Big Text: random

████▌ ███▌ █ █▌ ████▌ ███▌ █ █
Expand Down

0 comments on commit ba9fa30

Please sign in to comment.