-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
figma font family transformer (#899)
- Loading branch information
1 parent
e032ac6
commit 26cae47
Showing
5 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type StyleDictionary from 'style-dictionary' | ||
import {isFontFamily} from '../filters' | ||
/** | ||
* takes a value and returns it if its a string or concats strings in an array quoting strings with spaces | ||
* @param value | ||
* @returns string | ||
*/ | ||
export const parseFontFamily = ( | ||
token: StyleDictionary.TransformedToken, | ||
fontFamilies: Record<string, string> = {}, | ||
): string => { | ||
// return value from fontFamilies | ||
if (token.name in fontFamilies) { | ||
return fontFamilies[token.name] | ||
} | ||
// return string | ||
if (typeof token.value === 'string') { | ||
return token.value | ||
} | ||
// invalid value | ||
throw new Error(`Invalid value ${token.value}, should be a string or array of strings`) | ||
} | ||
/** | ||
* @description converts fontFamily tokens value to string | ||
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts) | ||
* @matcher matches all tokens of $type `fontFamily` | ||
* @transformer returns a string | ||
*/ | ||
export const fontFamilyToFigma: StyleDictionary.Transform = { | ||
type: `value`, | ||
transitive: true, | ||
matcher: isFontFamily, | ||
transformer: (token: StyleDictionary.TransformedToken, platform: StyleDictionary.Platform): string => | ||
parseFontFamily(token, platform.options?.fontFamilies), | ||
} |
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