build Compose Theme
Returns a Composable function that can be used to style your application.
You can then use the ComposeTheme object within your wrapped content to get the values mapped to respective DesignTokens.
Here is an example that defines and uses custom colors:
// define your color tokens
val content = DesignToken<Color>("content")
val background = DesignToken<Color>("background")
// use the tokens in your theme
val AppTheme = buildComposeTheme {
colors = mapOf(
content to Color(0xFF212121),
background to Color(0xFFFAFAFA),
)
}
// use the ComposeTheme object to use the tokens in runtime
@Composable
fun App() {
AppTheme {
Box(Modifier.background(ComposeTheme.colors[background]).fillMaxSize()) {
BasicText("The is a styled example", style = TextStyle(color = ComposeTheme.colors[content]))
}
}
}Content copied to clipboard