design-tokens / community-group

This is the official DTCG repository for the design tokens specification.
https://tr.designtokens.org
Other
1.56k stars 63 forks source link

Token name can be an empty string #195

Open romainmenke opened 1 year ago

romainmenke commented 1 year ago

The current specification does not require token names to be strings with a non-zero length.

https://tr.designtokens.org/format/#name-and-value

{
  "": { "$value": "3rem" },
  "other": { "$value": "{}" }
}

This parses just fine :

const json = `{
  "": { "$value": "3rem" },
  "other": { "$value": "{}" }
}`;

console.log(JSON.parse(json));
// { '': { '$value': '3rem' }, other: { '$value': '{}' } }

Is this intended?

ilikescience commented 1 year ago

Interesting! It's funny that JSON allows for this.

My feeling is that token names have to be non-zero. I can't imagine a use case for a token called "" ... but open to possibilities if we can think of them.

romainmenke commented 1 year ago

My feeling is that token names have to be non-zero.

I agree.


This is allowed in today's specification text, but is really awkward.

{
  "": {
    "": {
      "": {
        "": { "$value": "3rem" }
      }
    }
  }
}

Token ... has value 3rem

srouse commented 1 year ago

I found this useful for stepped tokens where the middle value represents what people think of as the color:

{
  “color”: {
    “primary”: {
    …
        “04”: { "$value": “#aa0000” },
        “05”: { "$value": “#bb0000” },
    "": { "$value": “#bb0000” },
        “06”: { "$value": “#cc0000” },
    …
    }
  }
}

Which can be transformed into:

…
color-primary-04: #aa0000;
color-primary-05: #bb0000;
color-primary: #bb0000;
color-primary-06: #cc0000;
…
romainmenke commented 1 year ago

@srouse That looks like a bug in your translation tool :/

I don't understand why it would convert this to color-primary. It should be color-primary- when following the naming logic for the other tokens. Now you have a naming conflict between a specific token and a token group.


It does illustrate why it is important for the specification to be explicit about allowing this or not. It is an edge case that should not be overlooked by implementers.

kevinmpowell commented 1 year ago

Related to #200