Skip to content

Commit 4fe336f

Browse files
fix: add lineHeight/letterSpacing expand overrides (#307)
1 parent 0dea2af commit 4fe336f

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

.changeset/dry-sheep-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tokens-studio/sd-transforms': patch
3+
---
4+
5+
Override lineHeight expandTypesMap from SD. Add letterSpacing override. This is needed for our lineHeight and letterSpacing transforms to apply.

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export const expandTypesMap = {
3333
// because no DTCG type that currently exists provides a good match.
3434
// for fontWeight: recognized fontWeight keys (e.g. "regular")
3535
// for lineHeight: lineHeights can be both dimension or number
36+
37+
// overrides https://github.com/amzn/style-dictionary/blob/main/lib/utils/expandObjectTokens.js#L54-L55
38+
// so that our lineHeight and letterSpacing transforms can still apply
39+
lineHeight: 'lineHeight',
40+
41+
// this one can be removed once we can rely on preExpand meta:
42+
// https://github.com/amzn/style-dictionary/pull/1269
43+
letterSpacing: 'letterSpacing',
3644
},
3745
composition: {
3846
boxShadow: 'shadow',

test/integration/expand-composition.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('expand composition tokens', () => {
9999
--sdTypographyFontWeight: 800;
100100
--sdTypographyLineHeight: 1.25;
101101
--sdTypographyFontSize: 26px;
102-
--sdTypographyLetterSpacing: 0rem;
102+
--sdTypographyLetterSpacing: 1.25em;
103103
--sdTypographyParagraphSpacing: 0rem;
104104
--sdTypographyParagraphIndent: 0rem;
105105
--sdTypographyTextDecoration: none;
@@ -138,7 +138,7 @@ describe('expand composition tokens', () => {
138138
--sdRefFontWeight: 800;
139139
--sdRefLineHeight: 1.25;
140140
--sdRefFontSize: 26px;
141-
--sdRefLetterSpacing: 0rem;
141+
--sdRefLetterSpacing: 1.25em;
142142
--sdRefParagraphSpacing: 0rem;
143143
--sdRefParagraphIndent: 0rem;
144144
--sdRefTextDecoration: none;
@@ -148,7 +148,7 @@ describe('expand composition tokens', () => {
148148
--sdDeepRefFontWeight: 800;
149149
--sdDeepRefLineHeight: 1.25;
150150
--sdDeepRefFontSize: 26px;
151-
--sdDeepRefLetterSpacing: 0rem;
151+
--sdDeepRefLetterSpacing: 1.25em;
152152
--sdDeepRefParagraphSpacing: 0rem;
153153
--sdDeepRefParagraphIndent: 0rem;
154154
--sdDeepRefTextDecoration: none;

test/integration/tokens/expand-composition.tokens.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"value": {
3434
"fontFamily": "Arial",
3535
"fontWeight": "{fontWeightRef}",
36-
"lineHeight": "1.25",
36+
"lineHeight": "125%",
3737
"fontSize": "26",
38-
"letterSpacing": "0",
38+
"letterSpacing": "125%",
3939
"paragraphSpacing": "0",
4040
"paragraphIndent": "0",
4141
"textDecoration": "none",

0 commit comments

Comments
 (0)