KPText
A customized text composable that wraps androidx.compose.material.Text with modified default values for letterSpacing and style. This composable ensures a more consistent typography design by overriding specific defaults, such as removing font padding.
Parameters
The text content to display, provided as a String
.
The color of the text. Default is Color.Unspecified, which defers to the style parameter.
The size of the text, specified as a TextUnit. Default is TextUnit.Unspecified, which defers to the style parameter.
The style of the text (e.g., italic). Default is null
, which defers to the style parameter.
The weight of the text (e.g., bold). Default is null
, which defers to the style parameter.
The font family for the text. Default is null
, which defers to the style parameter.
The amount of space to add between each letter. Default is KPTextDefaults.letterSpacing.
Decorations such as underline or strikethrough. Default is null
.
Alignment of the text within its container (e.g., start, center). Default is null
.
The height of each line of text, specified as a TextUnit. Default is TextUnit.Unspecified.
Behavior for handling text overflow (e.g., ellipsis, clip). Default is TextOverflow.Clip.
Whether the text should wrap when it reaches the container's bounds. Default is true
.
The maximum number of lines for the text. Default is Int.MAX_VALUE.
The minimum number of lines for the text. Default is 1
.
Callback invoked with the TextLayoutResult after the text is laid out. Default is an empty lambda.
TextStyle configuration for the text, such as color, font, and line height. This overrides platformStyle
to remove the default font padding. Default is LocalTextStyle.current.
Example usage:
KPText(
text = "Hello, KP Design!",
)
See also
A customized text composable that wraps androidx.compose.material.Text, allowing for rich text formatting using AnnotatedString. This composable adjusts default values for letterSpacing and style, ensuring consistent typography and removing default font padding.
Parameters
The text content to display, provided as an AnnotatedString. It allows rich text formatting, such as styled spans or inline content.
The color of the text. Default is Color.Unspecified, which defers to the style parameter.
The size of the text, specified as a TextUnit. Default is TextUnit.Unspecified, which defers to the style parameter.
The style of the text (e.g., italic). Default is null
, which defers to the style parameter.
The weight of the text (e.g., bold). Default is null
, which defers to the style parameter.
The font family for the text. Default is null
, which defers to the style parameter.
The amount of space to add between each letter. Default is KPTextDefaults.letterSpacing.
Decorations such as underline or strikethrough. Default is null
.
Alignment of the text within its container (e.g., start, center). Default is null
.
The height of each line of text, specified as a TextUnit. Default is TextUnit.Unspecified.
Behavior for handling text overflow (e.g., ellipsis, clip). Default is TextOverflow.Clip.
Whether the text should wrap when it reaches the container's bounds. Default is true
.
The maximum number of lines for the text. Default is Int.MAX_VALUE.
The minimum number of lines for the text. Default is 1
.
A map of InlineTextContent identified by keys within the AnnotatedString. This allows embedding custom composables inline with the text. Default is an empty map.
Callback invoked with the TextLayoutResult after the text is laid out. Default is an empty lambda.
TextStyle configuration for the text, such as color, font, and line height. This overrides platformStyle
to remove the default font padding. Default is LocalTextStyle.current.
Example usage:
val annotatedString = buildAnnotatedString {
append("Hello, ")
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("KP Design!")
}
}
KPText(
text = annotatedString,
)