-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scope the typography shorthand to CSS (#20)
* BREAKING: scope the typography shorthand to CSS * feat: add typography shorthand for Jetpack Compose --------- Co-authored-by: Joren Broekema <[email protected]>
- Loading branch information
1 parent
e66ac7f
commit d4d2bc2
Showing
7 changed files
with
61 additions
and
8 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,6 @@ | ||
--- | ||
'@tokens-studio/sd-transforms': minor | ||
--- | ||
|
||
**BREAKING**: Renames typography transform to clarify it's transformed to CSS-based format. | ||
Previously `transformTypography`, now `transformTypographyForCSS`. |
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 @@ | ||
--- | ||
'@tokens-studio/sd-transforms': patch | ||
--- | ||
|
||
Adds a transformer for typography tokens on Jetpack Compose |
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,32 @@ | ||
/** | ||
* Helper: Transforms typography object to typography shorthand for Jetpack Compose | ||
* | ||
* @param {Record<string, string>} token | ||
*/ | ||
export function transformTypographyForCompose(token) { | ||
/** | ||
* Mapping between https://docs.tokens.studio/available-tokens/typography-tokens | ||
* and https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle | ||
* Unsupported property: | ||
* - paragraphSpacing | ||
*/ | ||
const textStylePropertiesMapping = { | ||
fontFamily: 'fontFamily', | ||
fontWeight: 'fontWeight', | ||
lineHeight: 'lineHeight', | ||
fontSize: 'fontSize', | ||
letterSpacing: 'letterSpacing', | ||
paragraphIndent: 'textIndent', | ||
}; | ||
|
||
/** | ||
* Constructs a `TextStyle`, e.g. | ||
* TextStyle( | ||
* fontSize = 16.dp | ||
* ) | ||
*/ | ||
return `${Object.entries(token.value).reduce( | ||
(acc, [propName, val]) => `${acc}${textStylePropertiesMapping[propName] ? `${val}\n` : ''}`, | ||
'TextStyle(\n', | ||
)})`; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
/** | ||
* Helper: Transforms typography object to typography shorthand | ||
* Helper: Transforms typography object to typography shorthand for CSS | ||
* This currently works fine if every value uses an alias, but if any one of these use a raw value, it will not be transformed. | ||
* If you'd like to output all typography values, you'd rather need to return the typography properties itself | ||
* | ||
* @param {Record<string, string>} value | ||
*/ | ||
export function transformTypography(value) { | ||
export function transformTypographyForCSS(value) { | ||
const { fontWeight, fontSize, lineHeight, fontFamily } = value; | ||
return `${fontWeight} ${fontSize}/${lineHeight} ${fontFamily}`; | ||
} |
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