Skip to content

Commit

Permalink
fix: do not add always add fontStyle for fontWeights
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed Jul 29, 2024
1 parent 0494270 commit 227f3fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/giant-bears-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': patch
---

Fix alwaysAddFontStyle option to not apply to tokens of type fontWeight(s), only meant for typography tokens.
3 changes: 2 additions & 1 deletion src/preprocessors/add-font-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ function recurse(
} else if (tokenType === 'fontWeight') {
const tokenFontWeightsValue = tokenValue as SingleFontWeightsToken['value'];
const fontWeight = resolveFontWeight(`${tokenFontWeightsValue}`, refCopy, usesDtcg);
const { weight, style } = splitWeightStyle(fontWeight, alwaysAddFontStyle);
// alwaysAddFontStyle should only apply to typography tokens, so we pass `false` here
const { weight, style } = splitWeightStyle(fontWeight, false);

if (style) {
// since tokenFontWeightsValue is a primitive (string), we have to permutate the change directly
Expand Down
21 changes: 21 additions & 0 deletions test/spec/preprocessors/add-font-styles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@ describe('add font style', () => {
});
});

it(`does not affect fontWeight tokens with alwaysAddFontStyle option`, () => {
expect(
addFontStyles(
// @ts-expect-error fontWeight (singular vs plural) doesn't exist on the type
// but we assume it's already preprocessed and aligned here
{
foo: {
value: 'Bold',
type: 'fontWeight',
},
} as DeepKeyTokenMap<false>,
{ alwaysAddFontStyle: true },
),
).to.eql({
foo: {
value: 'Bold',
type: 'fontWeight',
},
});
});

it(`allows always adding a default fontStyle for DTCG formatted tokens`, () => {
expect(
addFontStyles(
Expand Down

0 comments on commit 227f3fa

Please sign in to comment.