-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(font tokens): add font family fallbacks (#8389)
**Related Issue:** #7175 ## Summary Add font family fallbacks to tokens and update the transformer to know how to interpret those for Styles
- Loading branch information
1 parent
afbcb09
commit b2fd255
Showing
6 changed files
with
149 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...s/support/token-transformer/styleDictionary/transformer/value/valueFontFamilyFallbacks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Core as StyleDictionary } from "style-dictionary"; | ||
import { Matcher } from "style-dictionary/types/Matcher.js"; | ||
import { TransformedToken } from "style-dictionary/types/TransformedToken.js"; | ||
import { TokenTypes } from "@tokens-studio/types"; | ||
|
||
import { CalledTransformerFunction, TransformerConfig } from "../utils.js"; | ||
|
||
export const matcher: Matcher = (token: TransformedToken) => { | ||
return token.type === TokenTypes.FONT_FAMILIES && Array.isArray(token.value); | ||
}; | ||
|
||
type FontFamilyFallbackToken = TransformedToken & { value: string[] }; | ||
|
||
export const transformValuesFontFamilyWithFallbacks: CalledTransformerFunction<string> = ( | ||
token: FontFamilyFallbackToken | ||
) => { | ||
return token.value.join(" "); | ||
}; | ||
|
||
export const registerValueFontFamilyWithFallbacks = (sd: StyleDictionary): void => { | ||
const transformerConfig: TransformerConfig = { | ||
name: valueFontFamilyFallbacks, | ||
transformer: transformValuesFontFamilyWithFallbacks, | ||
type: "value", | ||
matcher, | ||
transitive: true, | ||
}; | ||
|
||
sd.registerTransform(transformerConfig); | ||
}; | ||
|
||
export const valueFontFamilyFallbacks = "value/calcite/font-family"; |