-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototype composite type in translation tools to ensure it is useful #126
Comments
Sorry for the delayed response. You raise some valid concerns and I think our spec does perhaps need to be more explicit about expected fallback behaviours for tools that can't or don't want to process composite tokens as a single unit. For tools that export to code, I had always imagined that an acceptable fallback would be to break up a composite type into individual variables. Using your earlier example: {
"type styles": {
"heading-level-1": {
"$type": "typography",
"$value": {
"fontFamily": "Roboto",
"fontSize": "42px",
"fontWeight": "700",
"letterSpacing": "0.1px",
"lineHeight": "1.2"
}
}
}
} ...and imagining this was being exported to, say, CSS custom properties, then I think this would be an acceptable output: --type-styles-heading-level-1-font-family: Roboto;
--type-styles-heading-level-1-font-size: 42px;
--type-styles-heading-level-1-font-weight: 700;
--type-styles-heading-level-1-letter-spacing: 0.1px;
--type-styles-heading-level-1-line-height: 1.2; In a way, I guess this is saying that (semantically) a composite token is a typed group (in my mind, they're a bit like interfaces in Typescript - i.e. objects that must have a specific "shape"). As you say, tools that know how to do something special with the group can do that, and other tools are welcome to just use the invidiual sub-values. So a different CSS export tool (or perhaps just a different configuration?) could produce something like this from the same token: .type-styles-heading-level-1 {
font-family: Roboto;
font-size: 42px;
font-weight: 700;
letter-spacing: 0.1px;
line-height: 1.2;
} Either of those (and maybe other things to) would be reasonable ways to export that token to CSS. However, I think your proposed typed group syntax is a little problematic. Since tokens without an explicit As I've outlined above, I don't think the current composite type approach prevents tools from "exploding" them into individual tokens / vars / whatever if that's needed for their use-case. The spec explcitly specifies what type each sub-value must be, so a tool can "know" that the |
Inheriting This is related to : #149
That is the core of the issue :) In my opinion it is best to design a data format that is resilient and has desirable forwards and backwards compatible properties. Adding in escape hatches for end users is critical to the long term success of a format.
If I understand it correctly the current spec text doesn't cover the intended behaviour.
The intention might have been for all tools and implementations to always have support for all specified composite types in a generic way:
These things are important to specify. |
When comparing composite types with regular types the added value of composite types wasn't immediately clear to me.
If I read the draft correctly they are strictly defined groups.
The reason to strictly define which sub values are allowed is to make it possible for other tools to interpret the group as a whole.
So in a way they are a tool to make it easier to consume a collection of values.
becomes :
Only needing to type
<something>
is much quicker and shorter than needing to reference each value separately.In theory this is awesome!
My concern with this is two fold :
Not always implementable
Grouping properties and values makes the assumption that multiple consumers can process this.
Even in CSS this is non-trivial and requires something like mixins.
In a CSS stack setup without mixins a user needs to reference each value individually :
This is more elaborate than if design tokens didn't have composite tokens :
And brings me to my second point :
this must be implemented (contrary to specification wording)
https://design-tokens.github.io/community-group/format/#groups-versus-composite-tokens
This is not true.
There is no way for a tool to fallback to "unspecialised functionality".
If my tool doesn't handle the
typography
type there is no way to correctly consume any value contained in this token.In CSS for example it becomes impossible to correctly reference
fontFamily
using a tool that doesn't supporttypography
.Roboto
vs"Roboto"
type styles.heading-level-1.$value.fontFamily
?)I think at least this specialised behaviour needs to become a requirement.
Which also brings me back to my first point, that it can not always be implemented...
One alternative is to see composite types as typed groups without altering how values/groups work or how they are written :
Any tool that supports
typography
in a special way can do its own thing.Any tool that doesn't will still be able to correctly handle the sub values as these follow regular group/value rules.
To sum up, I think this portion of the specification needs to be prototyped in translation tools to make sure it can be implemented or needs to be changed so that it can truly be optional.
The text was updated successfully, but these errors were encountered: