Skip to content

Text - Frameworks

Pre-defined styles provide a font and size.

AndroidreleasediOSreleased

Android

Syntax

kotlin
@Composable
fun WarpText(
    text: String | AnnotatedString,
    modifier: Modifier = Modifier,
    color: Color = colors.text.default,
    style: WarpTextStyle = WarpTextStyle.Body,
    maxLines: Int = Int.MAX_VALUE,
    minLines: Int = 1,
    textAlign: TextAlign? = null,
    overflow: TextOverflow = TextOverflow.Ellipsis,
    softWrap: Boolean = true,
    textDecoration: TextDecoration? = null,
    onTextLayout: (result: TextLayoutResult) -> Unit = {}
)

The default style for the text is WarpTextStyle.Body and the default text color is WarpTheme.colors.text.default.

kotlin
WarpText(
    text = "Warp!"
)

WarpText(
    text = "Warp with style",
    modifier = Modifier.padding(vertical = 8.dp),
    style = WarpTextStyle.Display,
    color = WarpTheme.colors.text.positive
)

To make WarpText clickable use the modifier function:

kotlin
WarpText(
    text = "Click this link",
    modifier = Modifier.clickable { clickFunction.invoke() },
    style = WarpTextStyle.Caption,
    color = WarpTheme.colors.text.link
)

There are a variety of styles supported for the text component:

kotlin
WarpTextStyle {
    Display,
    Title1,
    Title2,
    Title3,
    Title4,
    Title5,
    Title6,
    Preamble,
    Body,
    BodyStrong,
    Caption,
    CaptionStrong,
    Detail,
    DetailStrong
}

Legacy support

To support layouts still written in xml the WarpText can be used as a custom view.

kotlin
fun setOnClickListener(onCLick: OnClickListener?)
xml
<com.schibsted.nmp.warp.components.legacy.WarpTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:text="Warp speed"
    app:warpTextStyle="title1"
    app:color="@color/warp_text_link"
     />

Parameters

Required props

NameTypeDefaultDescription
textString | AnnotatedStringThe text to be displayed

Optional Props

NameTypeDefaultDescription
modifierModifierModifierSets the modifier for the text
colorColorWarpTheme.colors.text.defaultThe color of the text
styleWarpTextStyle.Display WarpTextStyle.Title1 WarpTextStyle.Title2 WarpTextStyle.Title3 WarpTextStyle.Title4 WarpTextStyle.Title5 WarpTextStyle.Title6 WarpTextStyle.Preamble WarpTextStyle.Body WarpTextStyle.BodyStrong WarpTextStyle.Caption WarpTextStyle.CaptionStrong WarpTextStyle.Detail WarpTextStyle.DetailStrongWarpTextStyle.BodySets the appearance of the text - font and size
maxLinesIntInt.MAX_VALUEMax lines of text
minLinesInt1Min lines of text
textAlignTextAlignnullTextAlign controls how text aligns in the space it appears
overflowTextOverflowTextOverflow.EllipsisHow overflowing text should be handled
softWrapBooleantrueIf text should wrap or not
textDecorationTextDecorationnullDefines a horizontal line to be drawn on the text. Useful for displaying links
onTextLayout(TextLayoutResult) -> Unit{}Callback providing paragraph info, text size, baselines, and more

Questions?

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system