Page MenuHomePhabricator

Tokens: Ensure that component tokens preserve references to CSS variables on output
Closed, ResolvedPublic5 Estimated Story PointsBUG REPORT

Description

Note: This is the underlying cause of T363778.

The color-link-red component token references the application token color-destructive as its value. However, in our current style dictionary configuration, this reference is not preserved on output.

When the tokens are built, we get this output:

---color-link-red: #d73333;

The problem is, this does not change when our color mode switches, so the red links are stuck in their light mode color. What we really want is output that looks like this:

--color-link-red: var(--color-destructive, #d73333 );

Style Dictionary includes an option called outputReferences which lets you do this, but it's not compatible with the way we want to handle option tokens (we specifically want to withhold those from the client).

We need to figure out a way to preserve references from component tokens -> application tokens, while continuing to exclude the option tokens. This will probably involve the creation of a custom formatter (or maybe a transformer, like in this abandoned patch) that mimics the behavior of the outputReferences option, but only for references to non-option tokens (i.e. tokens that are going to be in the output).

Acceptance criteria

  • Change the CSS output files such that:
    • If token A refers to token B, and token B is going to be in the output (is not excluded), then the value of A should no longer include the value of B (--a: #123;), but should instead include a reference to B (--a: var( --b );). For example, the output should contain --border-color-input--hover: var( --border-color-progressive );, not --border-color-input--hover: #36c;.
      • It's OK for the reference to B to include a the value of B as a fallback, but that's not required. We could output --a: var( --b ); or --a: var( --b, #123 );, both are acceptable.
    • If token A refers to token B, and token B is not going to be in the output (is excluded, because it's an option token), then the value of A should still include the value of B (--a: #123;), not a reference to B (we can't refer to B because it won't be in the output). For example, the output should contain --border-color-divider: #a2a9b1;, not --border-color-divider: var( --color-gray400 ); (because there is no --color-gray400 variable in the output)
    • This process should be followed for each token reference separately, so we should get --border-base: 1px solid var( --border-color-base );

(The other items were moved to T366541)

Event Timeline

Change #1035078 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] tokens: Make CSS variable output include references

https://gerrit.wikimedia.org/r/1035078

Change #1035079 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] tokens: Use variable references in Sass, full CSS, and Less outputs

https://gerrit.wikimedia.org/r/1035079

Change #1035080 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] tokens: Remove CSS variables for border- tokens

https://gerrit.wikimedia.org/r/1035080

CCiufo-WMF set the point value for this task to 5.May 28 2024, 6:17 PM

We've done the first part of the acceptance criteria listed above.

The latter two items are "optional" and not needed right now. @Catrope do you want to split this off into a separate task for the future so that this can be closed? I'm okay with picking it up next sprint.

Change #1035078 merged by jenkins-bot:

[design/codex@main] tokens: Make CSS variable output include references

https://gerrit.wikimedia.org/r/1035078

Change #1035079 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] tokens: Use transform instead of custom formatter for Less with CSS vars

https://gerrit.wikimedia.org/r/1035079

Change #1035080 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] tokens: Remove CSS variables for border- tokens

https://gerrit.wikimedia.org/r/1035080

Change #1039598 had a related patch set uploaded (by Catrope; author: Catrope):

[design/codex@main] tokens: Use variable references in Sass, Less and full CSS outputs

https://gerrit.wikimedia.org/r/1039598

Change #1041776 had a related patch set uploaded (by Catrope; author: Catrope):

[mediawiki/core@master] Update Codex from v1.6.1 to v1.7.0

https://gerrit.wikimedia.org/r/1041776

Change #1041776 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v1.6.1 to v1.7.0

https://gerrit.wikimedia.org/r/1041776

This is now fixed in MW core with the Codex 1.7.0 release. See this diff for detail on which CSS variables now refer to each other.