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

> * Presumably `$extends` can only be used on groups and must be a reference to another group, right? Extending tokens doesn't make sense to me (how would that be different to an alias token?)
> * If group B extends group A, should B also inherit properties from A like `$description`, `$type`, etc.?
> 
> Thoughts?

Yes to both those questions for me. Indeed, alias is the extends equivalent for a single token, or vice versa, extends is the alias equivalent for a token group. And yes, I think it makes sense to inherit the other properties, saves a lot of duplicate work I think.

@TravisSpomer with regards to your extension question, I would say we should follow something along the lines of what [deepmerge](https://www.npmjs.com/package/deepmerge) does, which if I recall correctly is something along the lines of this:

```js
const obj1 = {
  group: {
    nested: { 
      nestedValA: 'foo',
      nestedValB: 'qux',
    },
    val: 'bar',
  },
};


const obj2 = {
  group: {
    nested: { 
      nestedValB: 'something',
      nestedValC: 'else',
    },
  },
};

// obj2 extends obj1 or aka obj2 deepmerges with obj1
// so it becomes
const obj3 = {
  ...obj1,
  ...obj2,
  group: {
    ...obj1.group,
    ...obj2.group,
    nested: {
      ...obj1.group.nested,
      ...obj2.group.nested,
    },
  },
}

// which is equivalent to
const obj3 = {
  group: {
    nested: { 
      nestedValA: 'foo', // obj1
      nestedValB: 'something', // obj2 override
      nestedValC: 'else', // obj2 override
    },
    val: 'bar', // obj 1
  },
};
```

I want to add however something to @c1rrus 's comment:

> // makes this group behave as though it contained 2 tokens

This is the right wording I think, I think it's up to design token tools, not the spec itself, to decide what to do with this $extends metadata:
- Leave it as metadata
- Hard-copy the `super-group`'s (for a lack of a better term) properties/tokens into the group that extends it

The reason why I'd leave it as meta-data is for example because I don't want to bloat my CSS Custom Properties with tokens that are just duplicates of tokens in the super-group from which it extends, but I do want to have the metadata in order to help consumers of my design tokens to understand where they need to look to find the token they need. Let me know if that makes sense or if I should elaborate on this further with examples.


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


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

Received on Tuesday, 29 March 2022 13:27:53 UTC