-
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.
converting line height to pixel value
- Loading branch information
1 parent
108d613
commit c920fd9
Showing
6 changed files
with
68 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/primitives': patch | ||
--- | ||
|
||
Convert lineHeight from float to pixel value for figma |
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,34 @@ | ||
import type StyleDictionary from 'style-dictionary' | ||
import {isNumber} 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 convertNumberWithFontSize = (token: StyleDictionary.TransformedToken, unitless?: boolean) => { | ||
// short circut if value is not a number | ||
if ( | ||
typeof token.value !== 'number' || | ||
!token.$extensions?.['org.primer.data']?.fontSize || | ||
typeof token.$extensions?.['org.primer.data']?.fontSize !== 'number' | ||
) { | ||
return token.value | ||
} | ||
// convert value | ||
const convertedValue = token.$extensions?.['org.primer.data']?.fontSize * token.value | ||
// return converted value | ||
return unitless ? convertedValue : `${convertedValue}px` | ||
} | ||
/** | ||
* @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 convertWithFontSizeToPixel: StyleDictionary.Transform = { | ||
type: `value`, | ||
transitive: true, | ||
matcher: isNumber, | ||
transformer: (token: StyleDictionary.TransformedToken, platform: StyleDictionary.Platform): string => | ||
convertNumberWithFontSize(token, platform.options?.unitless ?? false), | ||
} |
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