Re: [community-group] Tokens group $extends property proposal (#116)

Another usecase this could cover for is giving the spec an equivalent of OpenAPI/JSONSchema’s [allOf property](https://json-schema.org/understanding-json-schema/reference/combining) for tokens:

```json
{
  "typography": {
    "$type": "typography",
    "base": {
      "$value": {
        "fontFamily": ["Inter"],
        "fontWeight": "400",
        "fontStyle": "normal",
        "fontSize": "16px",
        "letterSpacing": "0.0625em",
        "lineHeight": "1.4",
      }
    },
    "body": {
      "$extends": "{typography.base}",
      "$value": {
        "fontSize": "14px",
      }
    },
    "heading1": {
      "$extends": "{typography.base}",
      "$value": {
        "fontSize": "18px",
      }
    }
  }
}
```

This could prevent a ton of errors if you wanted to automatically inherit properties from a “base token” and only provide minimal overrides where needed.

Even if the larger questions are unanswered about how groups do/don’t get merged (I’m personally struggling to see how `$extend` would work on groups with tokens of different `$types` without throwing validation errors), I think having `$extends` on the token level could yield many benefits without adding complexity to the spec.

### Alternate proposal: 

Many people in this thread have identified the overlap between `$extends` as-proposed and `$alias`, and how the two could possibly be combined. We could simply just steal JSONSchema’s solution outright, and combine both `$extends` and `$alias` into an array structure:

```json
{
  "typography": {
    "styleC": {
      "$allOf": ["{typography.styleA}", "{typography.styleB}"],
      "$value": {
        "fontSize": "18px"
      }
    }
  }
}
```

Here, the idea would be that multiple composite tokens could be combined and merged in order, and optionally overridden. `$value` would be optional if `$allOf` were provided. Also not stuck on the name `$allOf` at all; just trying to outline slightly-different approach without getting hung up on naming.

As an aside, JSONSchema also has `oneOf` and `anyOf` but I don’t think those would be good fits for the DTCG spec, personally

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


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

Received on Monday, 25 March 2024 04:30:39 UTC