Skip to content

SuperRadioButton

SuperRadioButton 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.

Import

kotlin
import top.yukonga.miuix.kmp.extra.SuperRadioButton

Basic Usage

SuperRadioButton is typically used within a mutually exclusive group:

kotlin
var selectedIndex by remember { mutableIntStateOf(0) }

Card {
    SuperRadioButton(
        title = "Option A",
        selected = selectedIndex == 0,
        onClick = { selectedIndex = 0 }
    )
    SuperRadioButton(
        title = "Option B",
        selected = selectedIndex == 1,
        onClick = { selectedIndex = 1 }
    )
    SuperRadioButton(
        title = "Option C",
        selected = selectedIndex == 2,
        onClick = { selectedIndex = 2 }
    )
}

RadioButton with Summary

kotlin
var selectedIndex by remember { mutableIntStateOf(0) }

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

Component States

Disabled State

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

Properties

SuperRadioButton 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
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary descriptionnullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
radioButtonColorsRadioButtonColorsRadioButton control color configurationRadioButtonDefaults.radioButtonColors()No
endActions@Composable RowScope.() -> UnitCustom end content{}No
bottomAction@Composable (() -> Unit)?Custom bottom contentnullNo
holdDownStateBooleanWhether the component is held downfalseNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo
enabledBooleanWhether component is interactivetrueNo

Advanced Usage

Custom Colors

kotlin
var selected by remember { mutableStateOf(false) }

SuperRadioButton(
    title = "Custom Colors",
    titleColor = BasicComponentDefaults.titleColor(
        color = MiuixTheme.colorScheme.primary
    ),
    summary = "RadioButton with custom colors",
    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 {
    SuperArrow(
        title = "Theme Settings",
        onClick = { showDialog = true },
        holdDownState = showDialog
    )

    SuperDialog(
        title = "Theme Settings",
        show = showDialog,
        onDismissRequest = { showDialog = false }
    ) {
        Card {
            themes.forEachIndexed { index, theme ->
                SuperRadioButton(
                    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