Skip to content
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-values-5] Define ident() #11422

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions css-values-5/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@ Security</h4>
''--foo: attr(foo type(&lt;number&gt;)); background-image: src(string(var(--foo)))''
needs to be invalid as well.


<h4 id=attr-cycles>
Cycles</h4>

Expand Down Expand Up @@ -1856,6 +1857,83 @@ makes the containing [=declaration=] [=invalid at computed-value time=].
</pre>
</div>

<!-- 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 function lt="ident()"><<ident()>></dfn> = ident( <<ident-arg>>+ )
<dfn><<ident-arg>></dfn> = <<string>> | <<integer>> | <<ident>>
</pre>

Issue(w3c/csswg-drafts#11426): 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: ident(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
.element {
anchor-name: ident("--" attr(id));
}
```
</div>

<!-- Big Text: random

Expand Down