Re: [community-group] Contextual token values (#204)

I agree it would be great to have a mechanism in the format for this kind of thing, but I wonder whether the spec needs to pre-define contexts at all.

What if we let people provide any number of alternative values for a given token, each with a user-defined identifier. For example:

```json
{
  "mighty-morphing-token": {
    "$type": "dimension",
    "$value": "16px",
    "$altValues": {
      "high-info-density": "12px",
      "low-info-density": "20px",
      "random-thing": "17px"
    }
  }
}
```

From a tooling perspective, the only requirement would be to let the user to provide one (or more?) of their chosen keys and then resolve token values to the corresponding `$altValue` if it exists. Where non exists, `$value` is used as a fallback.

So the above token's value would be `16px` by default, but if the user has asked the tool to prefer `"low-info-density"` values, ot would resolve to `20px` instead.

### Example 1: Translation tool

A translation tool like Style Dictionary could let the user pass in desired alt value keys via a command-line option or config file.

Let's imagine we have such a tool, usage could look something like this:

```sh
$ dtcg2css input.tokens.json > output.css
```

Might use default values and produce something like:

```css
:root {
  --mighty-morphing-token: 16px;
}
```

But running it like this:

```sh
$ dtcg2css --alt-value=random-thing input.tokens.json > output-random.css
```

...would produce:

```css
:root {
  --mighty-morphing-token: 17px;
}
```

### Example 2: UI design tool

A design tool like Figma might present a list of all alt value keys in a `.tokens` file to the user and let them pick which one(s) to apply.

Wherever they've used those tokens in their designs, the design would update to show the currently applied settings.

I'm imagining the experience to be similar to how you can [switch "token sets" on and off in the Tokens Studio Figma plug-in](https://docs.tokens.studio/themes/token-sets). 

-- 
GitHub Notification of comment by c1rrus
Please view or discuss this issue at https://github.com/design-tokens/community-group/issues/204#issuecomment-1424575421 using your GitHub account


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

Received on Thursday, 9 February 2023 17:42:42 UTC