[csswg-drafts] [High-level] Making it less painful to communicate design tokens across parties (#10948)

LeaVerou has just created a new issue for https://github.com/w3c/csswg-drafts:

== [High-level] Making it less painful to communicate design tokens across parties ==
This is a high level issue to discuss potential directions and track relevant proposals in one place.

## Background

Any UI component [^1] that needs to render UI, needs to use certain design tokens: colors, fonts, sizes, etc. Currently, there is no way to read these from the host page. Instead, it needs to define its own, and (at best) provide its own CSS variable as styling hooks. Authors then can write **dozens of CSS declarations** to make this component look like it belongs in their page, live with a component that looks completely out of place (rarely acceptable). If they want to swap the component with a different one, they need to start over, and figure out the CSS properties the new component uses.

[^1]: component in the general sense — this could be a web component (and a lot of this is about WCs) but even just a reusable stylesheet suffers from the same issues.

In practice, they gravitate towards monolithic component libraries for which they only need to write the glue code once, since the components cooperate in using the same design tokens. But no single library will ever have all the components 

Here’s a concrete example. Suppose you’re making a component for e.g. a calendar widget. 
- When you want to highlight the current date with an accent color, you want it to be the accent color the page uses already, not some random accent color the WC author decided was good. 
- When you want a lighter version of the accent color for e.g. a date range or a hover highlight, you want that to be an existing tint the page uses. 
- When you want to display an error message, you want the red palette the page uses, not `#ff0000` or some random red shade the WC author likes.
- When you want to display some grayed out help text, you want it to be a neutral shade already present on the page and the smaller font size already used on the page.
- When you want to add a badge that says "today" on the current date, you want to pull in the sans serif font the page already uses and one of the font sizes that already exist on the page. 
- When you want to draw borders between dates, you want to use existing colors and border widths. 

The problem space may seem huge, but a little goes a long way. The biggest pain point is colors, as that is what is most noticable when it’s different, hardest to figure out from inheritance, and hardest to come up with simple defaults. With fonts you can often get by utilizing inheritance, and you mainly need access to the actual design tokens when you need a specific type of font (e.g. in a badge you need a sans serif font, or a code area you need a monospace font) and for sizes the difference tends to be less noticeable.

## High level solutions

The main solutions fall into two categories (which are not mutually exclusive):
1. Standardize certain "core" design tokens
2. Making it less painful to pass multiple design tokens around 
3. Ways to derive tokens from other tokens

These are not mutually exclusive, they are actually _composable_: 1 reduces the tokens that need to be passed around, and 2 could improve things for the ones that still do need to pass around, and 3 makes it possible to generate derivative tokens from 1 and 2

### Standardized "core" design tokens

This involves standardizing certain design tokens that are frequently needed and/or can be used to derive others and providing. This may involve both designing new values, as well as making existing values writable or dynamic.

Relevant proposals:

- https://github.com/w3c/csswg-drafts/issues/9999
- https://github.com/w3c/csswg-drafts/issues/10452
- https://github.com/w3c/csswg-drafts/issues/9660
- https://github.com/w3c/csswg-drafts/issues/5900

### Introducing high bandwidth ways to pass CSS variables around

This involves ways to make the current workflow more high bandwidth: integration effort would still be needed, but if reduced to a few declarations rather than the dozens required today, it might be more palatable.
Ways to derive tokens from other tokens 

Relevant proposals:

- https://github.com/w3c/csswg-drafts/issues/9992
- https://github.com/w3c/csswg-drafts/issues/10034

### Ways to derive tokens from other tokens

E.g. tints from an accent color, or single lengths from a scale) would also belong to this category

- https://github.com/w3c/csswg-drafts/issues/10034

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10948 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 25 September 2024 21:43:01 UTC