Skip to content

Button - Frameworks

Buttons initiate events or actions within a page, informing users of what to expect next.

AndroidreleasedElementsreleasediOSreleasedReactreleasedReact 19releasedVuereleased

Android

Syntax

There are 2 options - button with pre-defined content and custom content. This showcases the pre-defined option with a text and an optional leading or trailing icon.

kotlin
@Composable
fun WarpButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    style: WarpButtonStyle = WarpButtonStyle.Primary,
    maxLines: Int = 1,
    loading: Boolean = false,
    @DrawableRes leadingIcon: Int? = null,
    leadingIconContentDescr: String? = null,
    @DrawableRes trailingIcon: Int? = null,
    trailingIconContentDescr: String? = null,
    small: Boolean = false,
    iconModifier: Modifier = Modifier
)

@Composable
fun WarpButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    style: WarpButtonStyle = WarpButtonStyle.Primary,
    maxLines: Int = 1,
    loading: Boolean = false,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    small: Boolean = false
)

To add custom content follow this syntax:

kotlin
@Composable
fun WarpButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    style: WarpButtonStyle = WarpButtonStyle.Primary,
    loading: Boolean = false,
    small: Boolean = false,
    content: @Composable RowScope.() -> Unit
)

Visual options

The button supports a variety of styles, including a small version for each of these:

kotlin
WarpButtonStyle {
    Primary,
    Secondary,
    Quiet,
    Negative,
    NegativeQuiet,
    Utility,
    UtilityQuiet,
    UtilityOverlay,
}

Primary

The primary button is a call to action. As a general rule, there should only be one of them on the screen. This guides the user towards the happy path. This is the default style.

kotlin
WarpButton(
    onClick = { }, 
    style = WarpButtonStyle.Primary, 
    text = "Save"
)

Secondary

Secondary buttons are without background, and are often used for secondary actions. Also available as quiet style.

kotlin
WarpButton(
    onClick = { }, 
    style = WarpButtonStyle.Secondary, 
    text = "Save"
)
WarpButton(
    onClick = { }, 
    style = WarpButtonStyle.Quiet, 
    text = "Save"
)

Negative

Used for destructive actions, like deletion. Shouldn't be used on the same screen as a primary button.

kotlin
WarpButton(
    onClick = { }, 
    style = WarpButtonStyle.Negative, 
    text = "Cancel"
)

Loading/In progress

Used for visual feedback that the action the user triggered is loading.

kotlin
var loading by remember { mutableStateOf(false) }
var buttonText by remember { mutableStateOf("Save") }
val onClickAction = { }

WarpButton(
    onClick = onClickAction, 
    style = WarpButtonStyle.Primary, 
    text = buttonText,
    loading = loading
)

Disabled

kotlin
var enabled by remember { mutableStateOf(false) }

WarpButton(
    onClick = { }, 
    style = WarpButtonStyle.Secondary, 
    text = "Edit",
    enabled = enabled
)

Icon

An optional leading or trailing icon can be displayed at the start of the button text. There are 2 options - by supplying a drawable id or by using the WarpIcon component. WarpIcon handles content description for each brand automatically.

kotlin
WarpButton(
    onClick = { },
    style = WarpButtonStyle.Secondary,
    text = "With icon",
    leadingIcon = R.drawable.ic_duck,
    leadingIconContentDescr = "Duck icon"
)

WarpButton(
    onClick = { },
    style = WarpButtonStyle.Secondary,
    text = "With icon",
    trailingIcon = R.drawable.clock,
    trailingIconContentDescr = R.string.clock
)

WarpButton(
    onClick = { },
    style = WarpButtonStyle.Secondary,
    text = "With Warp icon",
    leadingIcon = { WarpIcon(icon = icons.clock, size = dimensions.icon.small) }
)

Legacy support

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

xml
<com.schibsted.nmp.warp.components.WarpButtonView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:warpButtonStyle="primary"
    app:buttonLeadingIcon="@drawable/duck"
    app:buttonleadingIconContentDescr="@string/duck"
    app:buttonTrailingIcon="@drawable/clock"
    app:buttonTrailingIconContentDescr="@string/clock"
    app:buttonText="Send"
    app:loading="false"
    app:small="false"
    app:enabled="true"/>

Parameters

Required props

NameTypeDefaultDescription
textStringThe text to be displayed on the button
onClick() -> UnitLambda to be invoked when clicked

Optional Props

NameTypeDefaultDescription
styleWarpButtonStyle.Primary WarpButtonStyle.Secondary WarpButtonStyle.Quiet WarpButtonStyle.Negative WarpButtonStyle.NegativeQuiet WarpButtonStyle.Utility WarpButtonStyle.UtilityQuiet WarpButtonStyle.UtilityOverlayWarpButtonStyle.PrimaryControls the appearance of the button
enabledBooleantrueSets the button in disabled mode
modifierModifierModifierSets the modifier for the button
maxLinesInteger1Limits the lines of the text on the button
loadingBooleanfalseSet the button to look like it is in progress, can be combined with other button types. Can be combined with any button type
leadingIconInt or @Composable () -> UnitnullThe id of the icon drawable resource or the WarpIcon component to be displayed in the button before the text
leadingIconContentDescrStringnullThe content description of the icon
trailingIconInt or @Composable () -> UnitnullThe id of the icon drawable resource or the WarpIcon component to be displayed in the button after the text
trailingIconContentDescrStringnullThe content description of the icon
smallBooleanfalseSet to show a smaller slimmed version of the button
iconModifierModifierModifierSets the modifier for the icon

Questions?

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