-
-
Notifications
You must be signed in to change notification settings - Fork 75
feat(design-tokens): Add a unit on a token value on demand #588
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
Conversation
Signed-off-by: Fred Boyle <fred.boyle@pantheon.io>
Hi @fredboyle, Thank you for contributing 🎉 A couple of questions first :1 why is the unit missing in the tokens file?If 2 is the unit always missing in the tokens file?Is this consistent? 3 is this a value or a multiplier?If they are a value I would expect the tokens to include A multiplier assumes a calc expression : {
"font-size": 1.25
} .foo {
font-size: design-token('font-size' foo rem); /* foo as a placeholder */
/* resolves to this : */
font-size: calc(1rem * 1.25);
/* equivalent to this : */
font-size: 1.25rem;
} Understanding this fully will allow us to pick the right API for this. 4 can you use
|
See responses inline below.
Design tokens should be unit-less to be true design tokens usable across multiple platforms.
Our design tokens are cross-platform and as such have no unit unless it is universal. Each platform using the design tokens can decide if a unit is needed and which unit to use.
Most of our values are multipliers to maintain relationships with each other and scale as needed universally.
Duh! I've been using other technologies too much and such a simple solution went overlooked by me. :) With this last option being functional already then this pull-request is redundant and not needed. Hopefully my other comments help with an understand of our use of design tokens though. |
@romainmenke One small catch-22 I just thought of to the simple solution is formatters such as Prettier like to add spaces between function parentheses and the following content. Not ideal so the |
@fredboyle I agree.
.unitless {
padding-bottom: design-token('space.unitless' to rem);
padding-bottom: design-token('space.unitless' to px);
} Then we do not need the new API with |
@romainmenke That would work indeed but should accept any unit. We ourselves also use |
True. Out of curiosity, how do you handle these cases when using design tokens with the generated CSS? As far as I know these would all become CSS variables without units right? :root {
--typography-size-small: 0.8;
} How do you assign a unit to them in those cases? |
Style Dictionary generated CSS custom properties are unit-less at this time for us. We have not yet implemented a transform to add the unit automatically. So at this time if we use a CSS custom property version of a design token in our CSS we simply use the |
@fredboyle We have just released |
Example:
JSON
CSS
Ouput