1- import { fileHeader } from 'style-dictionary/utils'
21import { pascalCase , snakeCase } from 'change-case'
2+ import type { Format } from 'style-dictionary/types'
3+ import { fileHeader } from 'style-dictionary/utils'
34
45const letterSpacingToFloat = ( letterSpacing , fontSize ) =>
56 1 + letterSpacing / fontSize
@@ -9,39 +10,42 @@ const printDescription = (description) =>
910 ? ` <!-- ${ description } -->\n`
1011 : ''
1112
12- export default ( { dictionary, platform, options = { } , file } ) => {
13- const fontStyles = dictionary . allTokens
14- . filter ( ( compositeToken ) => compositeToken . type === 'custom-fontStyle' )
15- // create style
16- . map ( ( compositeToken ) => {
17- return (
18- ` <style name="${ pascalCase (
19- compositeToken . name . replace ( 'font_android_' , '' )
20- ) } ">\n` +
21- printDescription ( compositeToken . description ) +
22- ` <item name="android:fontFamily">@font/${ snakeCase (
23- compositeToken . original . value . fontFamily
24- ) } </item>\n` +
25- ` <item name="android:textSize">@dimen/${ snakeCase (
26- compositeToken . name . replace ( 'font_android_' , '' )
27- ) } </item>\n` +
28- // for android:lineHeight requires API level 28 and current api is 26
29- ` <item name="lineHeight">${ compositeToken . original . value . lineHeight } sp</item>\n` +
30- // Commenting the changes, we need to fix the conversion
31- // ` <item name="android:letterSpacing">${letterSpacingToFloat(
32- // compositeToken.original.value.letterSpacing,
33- // compositeToken.original.value.fontSize
34- // )}</item>\n` +
35- ` <item name="fontStyle">${ compositeToken . original . value . fontStyle } </item>\n` +
36- ` <item name="fontWeight">${ compositeToken . original . value . fontWeight } </item>\n` +
37- ' </style>\n'
38- )
39- } )
40- return `
13+ export default {
14+ name : 'android/formatFontStyle' ,
15+ format : ( { dictionary, platform, options = { } , file } ) => {
16+ const fontStyles = dictionary . allTokens
17+ . filter ( ( compositeToken ) => compositeToken . type === 'custom-fontStyle' )
18+ // create style
19+ . map ( ( compositeToken ) => {
20+ return (
21+ ` <style name="${ pascalCase (
22+ compositeToken . name . replace ( 'font_android_' , '' )
23+ ) } ">\n` +
24+ printDescription ( compositeToken . description ) +
25+ ` <item name="android:fontFamily">@font/${ snakeCase (
26+ compositeToken . original . value . fontFamily
27+ ) } </item>\n` +
28+ ` <item name="android:textSize">@dimen/${ snakeCase (
29+ compositeToken . name . replace ( 'font_android_' , '' )
30+ ) } </item>\n` +
31+ // for android:lineHeight requires API level 28 and current api is 26
32+ ` <item name="lineHeight">${ compositeToken . original . value . lineHeight } sp</item>\n` +
33+ // Commenting the changes, we need to fix the conversion
34+ // ` <item name="android:letterSpacing">${letterSpacingToFloat(
35+ // compositeToken.original.value.letterSpacing,
36+ // compositeToken.original.value.fontSize
37+ // )}</item>\n` +
38+ ` <item name="fontStyle">${ compositeToken . original . value . fontStyle } </item>\n` +
39+ ` <item name="fontWeight">${ compositeToken . original . value . fontWeight } </item>\n` +
40+ ' </style>\n'
41+ )
42+ } )
43+ return `
4144<?xml version="1.0" encoding="utf-8"?>
4245${ fileHeader ( { file, commentStyle : 'xml' } ) }
4346<resources>
4447 ${ fontStyles . join ( '\n' ) }
4548</resources>
4649`
47- }
50+ }
51+ } as Format
0 commit comments