Skip to content

Commit

Permalink
UI: Add support for custom Text color (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz authored Sep 28, 2024
1 parent d9d8f4b commit 70b8596
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ fun Text(
text: String,
modifier: Modifier = Modifier,
style: TextStyle = LocalTextStyle.current,
color: Color? = null,
textAlign: TextAlign = TextAlign.Start,
maxLines: Int = Int.MAX_VALUE,
) {
CompositionLocalProvider(
LocalTextColor provides KrailTheme.colors.onBackground,
LocalTextStyle provides KrailTheme.typography.body,
LocalTextColor provides KrailTheme.colors.onBackground, // default color for text
LocalTextStyle provides KrailTheme.typography.body, // default style for text
) {
BasicText(
text = text,
style = style.merge(
color = LocalTextColor.current,
color = color?: LocalTextColor.current,
textAlign = textAlign,

),
maxLines = maxLines,
modifier = modifier,
Expand All @@ -53,3 +53,13 @@ private fun TextPreview() {
}
}
}

@ComponentPreviewLightDark
@Composable
private fun TextWithColorPreview() {
KrailTheme {
Column(modifier = Modifier.background(color = KrailTheme.colors.background)) {
Text(text = "Typography", color = KrailTheme.colors.error)
}
}
}

0 comments on commit 70b8596

Please sign in to comment.