Compose Unstyled 2.0 is out! Check the official announcement blog ->

Styled text that inherits local typography and content color by default.

Use text for labels, titles, body copy, and inline content that should stay consistent with the surrounding theme.

View on GitHub
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.composables.ui.components.Text
import com.composeunstyled.ProvideTextStyle

@Composable
fun TextExample() {
    Text("Hello world")
}

Installation

implementation("com.composables:ui:0.1.0")

Examples

Styled

View on GitHub
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.composables.ui.components.Text

@Composable
fun StyledTextExample() {
    Text(
        text = "Styled headline",
        fontSize = 24.sp,
        lineHeight = 32.sp,
        fontWeight = FontWeight.SemiBold,
    )
}

Themed

View on GitHub
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.composables.ui.components.Text
import com.composeunstyled.ProvideTextStyle

@Composable
fun ThemedTextExample() {
    ProvideTextStyle(
        TextStyle(
            fontSize = 18.sp,
            lineHeight = 28.sp,
            fontWeight = FontWeight.Medium,
        ),
    ) {
        Column {
            Text("This text is themed")
            Text("And so is this one")
        }
    }
}

API Reference

Text

A styled text primitive that inherits local typography and content color.

@Composable
fun Text(
    text: String,
    modifier: Modifier = Modifier,
    style: TextStyle = LocalTextStyle.current,
    textAlign: TextAlign = TextAlign.Unspecified,
    lineHeight: TextUnit = TextUnit.Unspecified,
    fontSize: TextUnit = style.fontSize,
    letterSpacing: TextUnit = style.letterSpacing,
    fontWeight: FontWeight? = style.fontWeight,
    color: Color = if (style.color.isSpecified) style.color else LocalContentColor.current,
    fontFamily: FontFamily? = style.fontFamily,
    singleLine: Boolean = false,
    minLines: Int = 1,
    maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
    overflow: TextOverflow = TextOverflow.Clip,
)
Parameter Type Description
text String String content displayed by the text component.
modifier Modifier Modifier applied to the text.
style TextStyle Base text style used when drawing the text.
textAlign TextAlign Alignment used for the text within its bounds.
lineHeight TextUnit Line height used for the text.
fontSize TextUnit Font size used for the text.
letterSpacing TextUnit Letter spacing used for the text.
fontWeight FontWeight? Font weight used for the text.
color Color Color used to draw the text.
fontFamily FontFamily? Font family used for the text.
singleLine Boolean Whether the text is forced onto a single line.
minLines Int Minimum number of lines reserved for the text.
maxLines Int Maximum number of lines allowed for the text.
overflow TextOverflow How overflowing text should be handled.