Skip to content

RadioButtonPreference

RadioButtonPreference is a radio button component in Miuix that provides a title, summary, and radio button control. It supports click interactions and is commonly used in single-select settings and selection lists. When an item is selected, its title and summary are tinted with the theme color.

Import

kotlin
import top.yukonga.miuix.kmp.preference.RadioButtonPreference

Basic Usage

RadioButtonPreference is typically used within a mutually exclusive group, with each option placed in its own card:

kotlin
val options = listOf("Option A", "Option B", "Option C")
var selectedIndex by remember { mutableIntStateOf(0) }

options.forEachIndexed { index, option ->
    Card(
        modifier = Modifier.padding(bottom = 12.dp)
    ) {
        RadioButtonPreference(
            title = option,
            selected = selectedIndex == index,
            onClick = { selectedIndex = index }
        )
    }
}

RadioButton with Summary

kotlin
var selectedIndex by remember { mutableIntStateOf(0) }

RadioButtonPreference(
    title = "Option A",
    summary = "Description for option A",
    selected = selectedIndex == 0,
    onClick = { selectedIndex = 0 }
)

Component States

Disabled State

kotlin
RadioButtonPreference(
    title = "Disabled RadioButton",
    summary = "This radio button is currently unavailable",
    selected = true,
    onClick = {},
    enabled = false
)

Properties

RadioButtonPreference Properties

Property NameTypeDescriptionDefault ValueRequired
titleStringTitle of the radio button item-Yes
selectedBooleanRadio button selected state-Yes
onClick(() -> Unit)?Callback when radio button is clicked-Yes
modifierModifierModifier applied to componentModifierNo
summaryString?Summary descriptionnullNo
colorsRadioButtonPreferenceColorsTitle and summary color configurationRadioButtonPreferenceDefaults.radioButtonPreferenceColors()No
radioButtonColorsRadioButtonColorsRadioButton control color configurationRadioButtonDefaults.radioButtonColors()No
startAction@Composable (() -> Unit)?Custom start contentnullNo
endActions@Composable (RowScope.() -> Unit)?Custom end contentnullNo
radioButtonLocationRadioButtonLocationRadio button position (Start or End)RadioButtonLocation.StartNo
bottomAction@Composable (() -> Unit)?Custom bottom contentnullNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo
holdDownStateBooleanWhether the component is held downfalseNo
enabledBooleanWhether component is interactivetrueNo

RadioButtonPreferenceDefaults Object

The RadioButtonPreferenceDefaults object provides default color configurations for the RadioButtonPreference component.

Methods

Method NameTypeDescription
radioButtonPreferenceColors()RadioButtonPreferenceColorsCreates default color config for title and summary

RadioButtonPreferenceColors Class

Property NameTypeDescription
titleColorBasicComponentColorsTitle text color
selectedTitleColorBasicComponentColorsTitle text color when selected
summaryColorBasicComponentColorsSummary text color
selectedSummaryColorBasicComponentColorsSummary text color when selected

Advanced Usage

Custom Colors

kotlin
var selected by remember { mutableStateOf(false) }

RadioButtonPreference(
    title = "Custom Colors",
    summary = "RadioButton with custom colors",
    colors = RadioButtonPreferenceDefaults.radioButtonPreferenceColors(
        titleColor = BasicComponentDefaults.titleColor(
            color = MiuixTheme.colorScheme.primary
        ),
        summaryColor = BasicComponentDefaults.summaryColor(
            color = MiuixTheme.colorScheme.secondary
        )
    ),
    selected = selected,
    onClick = { selected = !selected },
    radioButtonColors = RadioButtonDefaults.radioButtonColors(
        selectedColor = Color.Red
    )
)

Using with Dialog

kotlin
var showDialog by remember { mutableStateOf(false) }
var selectedTheme by remember { mutableIntStateOf(0) }
val themes = listOf("Light", "Dark", "System")

Scaffold {
    ArrowPreference(
        title = "Theme Settings",
        onClick = { showDialog = true },
        holdDownState = showDialog
    )

    OverlayDialog(
        title = "Theme Settings",
        show = showDialog,
        onDismissRequest = { showDialog = false }
    ) {
        Card {
            themes.forEachIndexed { index, theme ->
                RadioButtonPreference(
                    title = theme,
                    selected = selectedTheme == index,
                    onClick = { selectedTheme = index }
                )
            }
        }

        Row(
            horizontalArrangement = Arrangement.SpaceBetween,
            modifier = Modifier.padding(top = 12.dp)
        ) {
            TextButton(
                text = "Cancel",
                onClick = { showDialog = false },
                modifier = Modifier.weight(1f)
            )
            Spacer(Modifier.width(16.dp))
            TextButton(
                text = "Confirm",
                onClick = { showDialog = false },
                modifier = Modifier.weight(1f),
                colors = ButtonDefaults.textButtonColorsPrimary()
            )
        }
    }
}

Changelog

Released under the Apache-2.0 License