Add AnnotatedString property to Text atoms

This commit is contained in:
Wolf-Martell Montwé 2023-05-10 14:39:36 +02:00
parent 149a069f6c
commit 1eff5379a5
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
14 changed files with 476 additions and 0 deletions

View file

@ -2,6 +2,10 @@ package app.k9mail.ui.catalog.items
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBody1
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBody2
import app.k9mail.core.ui.compose.designsystem.atom.text.TextButton
@ -18,6 +22,7 @@ import app.k9mail.core.ui.compose.designsystem.atom.text.TextSubtitle2
fun LazyGridScope.typographyItems() {
sectionHeaderItem(text = "Typography")
sectionSubtitleItem(text = "Normal")
item { TextHeadline1(text = "Headline1") }
item { TextHeadline2(text = "Headline2") }
item { TextHeadline3(text = "Headline3") }
@ -45,4 +50,25 @@ fun LazyGridScope.typographyItems() {
item { TextButton(text = "Button", color = Color.Magenta) }
item { TextCaption(text = "Caption", color = Color.Magenta) }
item { TextOverline(text = "Overline", color = Color.Magenta) }
sectionSubtitleItem(text = "Annotated")
item { TextHeadline1(text = annotatedString("Headline1")) }
item { TextHeadline2(text = annotatedString("Headline2")) }
item { TextHeadline3(text = annotatedString("Headline3")) }
item { TextHeadline4(text = annotatedString("Headline4")) }
item { TextHeadline5(text = annotatedString("Headline5")) }
item { TextHeadline6(text = annotatedString("Headline6")) }
item { TextSubtitle1(text = annotatedString("Subtitle1")) }
item { TextSubtitle2(text = annotatedString("Subtitle2")) }
item { TextBody1(text = annotatedString("Body1")) }
item { TextBody2(text = annotatedString("Body2")) }
item { TextButton(text = annotatedString("Button")) }
item { TextCaption(text = annotatedString("Caption")) }
item { TextOverline(text = annotatedString("Overline")) }
}
private fun annotatedString(name: String) = buildAnnotatedString {
append(name)
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextBody1(
)
}
@Composable
fun TextBody1(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.body1,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextBody1Preview() {
@ -29,3 +48,18 @@ internal fun TextBody1Preview() {
TextBody1(text = "TextBody1")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextBody1WithAnnotatedStringPreview() {
PreviewWithThemes {
TextBody1(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextBody2(
)
}
@Composable
fun TextBody2(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.body2,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextBody2Preview() {
@ -29,3 +48,18 @@ internal fun TextBody2Preview() {
TextBody2(text = "TextBody2")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextBody2WithAnnotatedStringPreview() {
PreviewWithThemes {
TextBody2(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,24 @@ fun TextButton(
)
}
@Composable
fun TextButton(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = AnnotatedString(
text = text.text.uppercase(),
spanStyles = text.spanStyles,
paragraphStyles = text.paragraphStyles,
),
style = MainTheme.typography.button,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextButtonPreview() {
@ -29,3 +52,18 @@ internal fun TextButtonPreview() {
TextButton(text = "TextButton")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextButtonWithAnnotatedStringPreview() {
PreviewWithThemes {
TextButton(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextCaption(
)
}
@Composable
fun TextCaption(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.caption,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextCaptionPreview() {
@ -29,3 +48,18 @@ internal fun TextCaptionPreview() {
TextCaption(text = "TextCaption")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextCaptionWithAnnotatedStringPreview() {
PreviewWithThemes {
TextCaption(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextHeadline1(
)
}
@Composable
fun TextHeadline1(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.h1,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline1Preview() {
@ -29,3 +48,18 @@ internal fun TextHeadline1Preview() {
TextHeadline1(text = "TextHeadline1")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline1WithAnnotatedStringPreview() {
PreviewWithThemes {
TextHeadline1(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextHeadline2(
)
}
@Composable
fun TextHeadline2(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.h2,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline2Preview() {
@ -29,3 +48,18 @@ internal fun TextHeadline2Preview() {
TextHeadline2(text = "TextHeadline2")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline2WithAnnotatedStringPreview() {
PreviewWithThemes {
TextHeadline2(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextHeadline3(
)
}
@Composable
fun TextHeadline3(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.h3,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline3Preview() {
@ -29,3 +48,18 @@ internal fun TextHeadline3Preview() {
TextHeadline3(text = "TextHeadline3")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline3WithAnnotatedStringPreview() {
PreviewWithThemes {
TextHeadline3(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextHeadline4(
)
}
@Composable
fun TextHeadline4(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.h4,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline4Preview() {
@ -29,3 +48,18 @@ internal fun TextHeadline4Preview() {
TextHeadline4(text = "TextHeadline4")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline4WithAnnotatedStringPreview() {
PreviewWithThemes {
TextHeadline4(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextHeadline5(
)
}
@Composable
fun TextHeadline5(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.h5,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline5Preview() {
@ -29,3 +48,18 @@ internal fun TextHeadline5Preview() {
TextHeadline5(text = "TextHeadline5")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline5WithAnnotatedStringPreview() {
PreviewWithThemes {
TextHeadline5(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextHeadline6(
)
}
@Composable
fun TextHeadline6(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.h6,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline6Preview() {
@ -29,3 +48,18 @@ internal fun TextHeadline6Preview() {
TextHeadline6(text = "TextHeadline6")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextHeadline6WithAnnotatedStringPreview() {
PreviewWithThemes {
TextHeadline6(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,24 @@ fun TextOverline(
)
}
@Composable
fun TextOverline(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = AnnotatedString(
text = text.text.uppercase(),
spanStyles = text.spanStyles,
paragraphStyles = text.paragraphStyles,
),
style = MainTheme.typography.overline,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextOverlinePreview() {
@ -29,3 +52,18 @@ internal fun TextOverlinePreview() {
TextOverline(text = "TextOverline")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextOverlineWithAnnotatedStringPreview() {
PreviewWithThemes {
TextOverline(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextSubtitle1(
)
}
@Composable
fun TextSubtitle1(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.subtitle1,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextSubtitle1Preview() {
@ -29,3 +48,18 @@ internal fun TextSubtitle1Preview() {
TextSubtitle1(text = "TextSubtitle1")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextSubtitle1WithAnnotatedStringPreview() {
PreviewWithThemes {
TextSubtitle1(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}

View file

@ -3,6 +3,11 @@ package app.k9mail.core.ui.compose.designsystem.atom.text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
@ -22,6 +27,20 @@ fun TextSubtitle2(
)
}
@Composable
fun TextSubtitle2(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
) {
MaterialText(
text = text,
style = MainTheme.typography.subtitle2,
modifier = modifier,
color = color,
)
}
@Preview(showBackground = true)
@Composable
internal fun TextSubtitle2Preview() {
@ -29,3 +48,18 @@ internal fun TextSubtitle2Preview() {
TextSubtitle2(text = "TextSubtitle2")
}
}
@Preview(showBackground = true)
@Composable
internal fun TextSubtitle2WithAnnotatedStringPreview() {
PreviewWithThemes {
TextSubtitle2(
text = buildAnnotatedString {
append("Normal")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Annotated")
}
},
)
}
}