to-kotlin
This parser helps you generate design tokens in Kotlin.
Interface
interface parser {
name: 'to-kotlin';
output: {
type: 'file';
filePath: string;
};
options?:{
tokenNameTemplate?: string;
scopeName?: string;
androidMinVersion?: number;
}
}
Options
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
|
|
|
| The template the parser follows to name your tokens.
You can use the |
|
|
|
| The name of the parent class which contains all classes for all your token types. |
|
|
| 33 | The min Android version supported by your app. |
Basic usage
{
"colors": {
"$collection": {
"$modes": [
"light",
"dark"
]
},
"aliases": {
"border": {
"active": {
"$type": "color",
"$value": {
"dark": {
"$alias": "colors.core.label.blue-base",
"$mode": "dark"
},
"light": {
"$alias": "colors.core.label.blue-base",
"$mode": "light"
}
}
}
}
},
"core": {
"label": {
"blue-base": {
"$type": "color",
"$value": {
"dark": {
"model": "rgb",
"red": 96,
"green": 168,
"blue": 250,
"alpha": 1
},
"light": {
"model": "rgb",
"red": 17,
"green": 125,
"blue": 249,
"alpha": 1
}
}
},
"blue-lighter": {
"$type": "color",
"$value": {
"dark": {
"model": "rgb",
"red": 41,
"green": 52,
"blue": 67,
"alpha": 1
},
"light": {
"model": "rgb",
"red": 219,
"green": 236,
"blue": 254,
"alpha": 1
}
}
}
}
}
},
"dimensions": {
"$collection": {
"$modes": [
"desktop",
"mobile"
]
},
"base": {
"dimension-01": {
"$type": "dimension",
"$value": {
"mobile": {
"value": 2,
"unit": "px"
},
"desktop": {
"value": 4,
"unit": "px"
}
}
},
"dimension-02": {
"$type": "dimension",
"$value": {
"mobile": {
"value": 4,
"unit": "px"
},
"desktop": {
"value": 8,
"unit": "px"
}
}
}
}
}
}
.specifyrc.json
{
"version": "2",
"repository": "@organization/repository",
// Only use the personalAccessToken when working with the CLI
"personalAccessToken": "<your-personal-access-token>",
"rules": [
{
"name": "To Kotlin",
"parsers": [
{
"name": "to-kotlin",
"output": {
"type": "file",
"filePath": "public/tokens.kt"
}
}
]
}
]
}
output/tokens.kt
import android.content.res.Resources
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.*
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
object DesignTokens {
fun pxToDp(px: Double): Float {
return (px / Resources.getSystem().displayMetrics.density).toFloat()
}
fun pxToDp(px: Int): Float {
return px / Resources.getSystem().displayMetrics.density
}
fun pxToSp(px: Double): TextUnit {
return (px / Resources.getSystem().displayMetrics.scaledDensity).sp
}
fun pxToSp(px: Int): TextUnit {
return (px / Resources.getSystem().displayMetrics.scaledDensity).sp
}
object Color_ {
val colorsCoreLabelBlue_baseDark = Color(0.37647f, 0.65882f, 0.98039f, 1f)
val colorsCoreLabelBlue_baseLight = Color(0.06667f, 0.49020f, 0.97647f, 1f)
val colorsAliasesBorderActiveDark = Color(0.37647f, 0.65882f, 0.98039f, 1f)
val colorsAliasesBorderActiveLight = Color(0.06667f, 0.49020f, 0.97647f, 1f)
val colorsCoreLabelBlue_lighterDark = Color(0.16078f, 0.20392f, 0.26275f, 1f)
val colorsCoreLabelBlue_lighterLight = Color(0.85882f, 0.92549f, 0.99608f, 1f)
}
object Dimension {
val dimensionsBaseDimension_01Desktop = pxToDp(4)
val dimensionsBaseDimension_01Mobile = pxToDp(2)
val dimensionsBaseDimension_02Desktop = pxToDp(8)
val dimensionsBaseDimension_02Mobile = pxToDp(4)
}
}
Last updated