Skip to content
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

fix: do not add always add fontStyle for fontWeights #300

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading