[community-group] Add a `$private` property for tokens (#110)

c1rrus has just created a new issue for https://github.com/design-tokens/community-group:

== Add a `$private` property for tokens ==
Should our spec add an optional `$private` property, along similar lines to [the one proposed for StyleDictionary](https://github.com/amzn/style-dictionary/pull/704) by @silversonicaxel? It would instruct tools not to display or export a token by default (though tools may provide an option for users to override that and still see / export private tokens if they wish). Its value is a boolean. `true` makes the token private, `false` makes it (explicitly) public. If there is no `$private` property, the token is public.

As per the thread on the StyleDictionary issue, I think this could be convenient way for teams to exclude (or flag) tokens that they don't consider part of their public API from code, design tools, styelguides, etc. 

For example, the following DTCG token file:

```jsonc
{
  "red": {
    "$type": "color",
    "$value": "#ff0000"
  },
  "green": {
    "$type": "color",
    "$value": "#00ff00",
    "$private": true
  },
  "blue": {
    "$type": "color",
    "$value": "#0000ff",
    "$private": false
  }
}
```

...might cause a SASS export tool to output code like this:

```scss
$red: #ff0000;
$blue: #0000ff;
```
(Note how the "green" token is omitted because it is private)

Furthermore, if a token is an alias to a private token, then the dereferenced value must be output. E.g.:

```json
{
  "red": {
    "$type": "color",
    "$value": "#ff0000"
  },
  "blue": {
    "$type": "color",
    "$value": "#00ff00",
    "$private": true
  },

  "danger-color": {
    "$value": "{red}"
  },
  "link-color": {
    "$value": "{blue}"
  }
}
```

...might be exported to SASS like so:

```
$red: #ff0000;
$danger-color: $red;
$link-color: #0000ff;
```
(Note how `$link-color` has the dereferenced value, because the "blue" token is private)

Finally, I'd suggest that this property should be inheritable from groups, just like `$type` is. Thiis would make it easier to make all tokens within a group private. For example:

```json
{
  "color": {
    "$type": "color",
    "$private": true,

    "black": {
      "$value": "#000000"
    },
    "white": {
      "$value": "#ffffff"
    }
  }
}
```

is equivalent to:


```json
{
  "color": {
    "$type": "color",

    "black": {
      "$value": "#000000",
      "$private": true
    },
    "white": {
      "$value": "#ffffff",
      "$private": true
    }
  }
}
```

What do you think?

Please view or discuss this issue at https://github.com/design-tokens/community-group/issues/110 using your GitHub account


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

Received on Thursday, 3 February 2022 21:51:09 UTC