Skip to content

Radio - Frameworks

Radios allow users to select a single option from a list.

AndroidreleasediOSreleasedReactreleasedVuereleased

Android

Syntax

kotlin
fun WarpRadio(
    modifier: Modifier = Modifier,
    label: String,
    selected: Boolean = false,
    isError: Boolean = false,
    enabled: Boolean = true,
    extraText: String? = null,
    slot: @Composable (() -> Unit)? = null,
    onClick: (() -> Unit)? = null,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
)

fun WarpRadioGroup(
    modifier: Modifier = Modifier,
    orientation: Orientation = Orientation.Vertical,
    title: String? = null,
    options: List<String>,
    selectedOption: String? = null,
    helpText: String? = null,
    enabled: Boolean = true,
    isError: Boolean = false,
    onOptionSelected: (String) -> Unit
)

There is support for standalone radio component as well as a radio group.

kotlin
var selected by remember { mutableStateOf(false) }

WarpRadio(
    label = "Radio with extraText",
    selected = selected,
    enabled = true,
    extraText = "(Extra)",
    onClick = { selected = !selected }
    )


val radioOptions = listOf("Option 1", "Option 2", "Option 3", "Option 4", "Option 5")
val (selectedOption, onOptionSelected) = remember { mutableStateOf(radioOptions[0]) }

WarpRadioGroup(
    title = title,
    options = radioOptions,
    orientation = orientation,
    selectedOption = selectedOption,
    enabled = enabled,
    isError = isError,
    onOptionSelected = onOptionSelected,
    helpText = "Required"
    )

There is support for optional title and help text when using the radio group. Supported orientations are Orientation.Vertical and Orientation.Horizontal. Vertical is the default.

Legacy support

To support layouts still written in xml the Radio can be used as a custom view. Adding a composable slot must be done programmatically. Horizontal or vertical group is not supported.

kotlin
var slot: @Composable (() -> Unit)? = null
    set(value) {
        field = value
        disposeComposition()
    }

fun setOnClickListener(onClick: OnClickListener?)
xml
<com.schibsted.nmp.warp.components.legacy.WarpRadioView
    android:id="@+id/radio"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/space2"
    app:radioSelected="false"
    app:radioIsError="false"
    app:radioExtraText="Extra"
    app:radioEnabled="true"
    app:radioLabel="Radio button" />

Parameters Radio

Required props

NameTypeDefaultDescription
labelStringThe text to be displayed next to the radio

Optional Props

NameTypeDefaultDescription
modifierModifierModifierSets the modifier for the radio
selectedbooleanfalseWhether the radio is selected or not
isErrorbooleanfalseShows the radio in error state if true
enabledbooleantrueWhether the radio is enabled or not
extraTextString?nullThe optional text to be displayed next to the label
slot@Composable (() -> Uni)?nullThe composable that will be displayed next to the label or extraText if provided
onClick() -> UnitnullThe lambda to be invoked when clicked.
interactionSourceMutableInteractionSourceMutableInteractionSourceMutableInteractionSource represents a stream of Interactions corresponding to events emitted by a component

Parameters Radio Group

Required props

NameTypeDefaultDescription
optionsListThe list of texts to be displayed next to the radio buttons
onOptionSelected(String) -> UnitThe lambda to be invoked when clicked on a radio.

Optional Props

NameTypeDefaultDescription
modifierModifierModifierSets the modifier for the radio group
orientationOrientation.Vertical Orientation.HorizontalOrientation.VerticalSets the orientation for the radio group. Class is found in the androidx.compose.foundation.gestures package
titleStringnullThe title to be displayed on top of the radio group
selectedOptionStringnullThe selected option in the radio group
helpTextStringnullThe text displayed below the radio group
enabledbooleantrueWhether the radio group is enabled or not
isErrorbooleanfalseShows the radio group in error state if true

Questions?

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