Page MenuHomePhabricator

Support Codex design tokens in Gadgets
Open, Needs TriagePublicFeature

Description

User-authored CSS, including CSS in Gadgets, cannot use Less (per T56864#6153179). This means that the Codex design tokens cannot be used there, because MediaWiki currently only makes these available as Less variables.

Implementation options include:

  1. Magically transform user-authored CSS to substitute uses of a token with that token's value
    1. Less-style placeholders: transform color: @color-progressive; to color: #36c;
    2. CSS variable-style placeholders: transform color: var( --color-progressive ); to color: #36c
  2. Use real CSS variables
    1. Create a ResourceLoader module that contains all Codex design tokens as CSS variables (i.e. its contents look like :root { --color-progressive: #36c; --color-destructive: #d33; etc }). Its size would be 17 KB (4.8 KB after gzip).
    2. Detect which variables each gadget uses (by scanning its CSS for occurrences of var( --something )) and magically output the variables it needs alongside it. For example, if the Gadget's CSS contains var( --color-progressive ), we would add :root { --color-progressive: #36c; }
NOTE: The solutions for T355244 (TemplateStyles) and this one (Gadgets) may overlap significantly, depending on how they're implemented.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

As some notes regarding motivations that may influence how something like this is done, I know that 3rd parties who theme a skin which uses LESS (e.g. Vector using MediaWiki:Vector.css) spend a lot of time working on that theme because tokens are available only on the skin side rather than in the MediaWiki:Vector.css context, so they must override ALL the colors (as a typical example) rather than a single variable or three.

Also musing about the work related to supporting themes in core and/or dark mode in core which I guess are in the T122924: Merge Extension:Theme into core and T26070: [GOAL] Provide a dark / night mode skin or theme/T336302: [WE2.1] Exploration: Dark Mode directions, as well as T320322: Support CSS variables in TemplateStyles for TemplateStyles. Just some other things to keep in mind/potentially review with relevant teams.

There's also T296689: [EPIC] Address themeability needs for Codex components, which contemplates (among many other things) using CSS variables as the primary way of delivering Codex tokens, which would make this task moot (since this contemplates using CSS variables just for Gadget support, while still using Less variables for everything else). The overlap between Codex theming and dark mode, and how CSS variables could be used, just came up in a Design Systems team / Web team meeting today, but it's a complex topic so we decided we should set aside some time in the future to talk about it more thoroughly.

On that note, there is a new color-mix function in CSS:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix

So this, and in general, Color Module 5, make things like darkening available. Additionally, CSS nesting is right around the corner (only missing in Firefox, but already behind a flag).

This means that you really don't need Less for additional features like Dark mode. Gadget developers won't need it either. Speaking from experience on pl.wiki, we typically don't support old browsers in non-default gadgets (maybe only if someone asks nicely ;)).

Izno changed the subtype of this task from "Task" to "Feature Request".Jul 24 2023, 5:44 PM

Random thought: in addition to Gadgets, this should also cover TemplateStyles (and ideally also user styles, but that might be harder).

EDIT: That is already covered by T355244. The solutions for that task (TemplateStyles) and this one (Gadgets) may overlap significantly, depending on how they're implemented. They're definitely related.

Jdlrobson renamed this task from Make Codex design tokens available in Gadgets to Support Codex design tokens available in Gadgets and template styles.Mar 21 2024, 8:58 PM
Jdlrobson renamed this task from Support Codex design tokens available in Gadgets and template styles to Support Codex design tokens in Gadgets and template styles.
CCiufo-WMF renamed this task from Support Codex design tokens in Gadgets and template styles to Support Codex design tokens in Gadgets.Mar 21 2024, 9:56 PM
CCiufo-WMF updated the task description. (Show Details)