Skip to content

SuperSwitch

SuperSwitch is a switch component in Miuix that provides a title, summary, and a switch control on the right. It supports click interaction and is commonly used in settings items and preference toggles.

Import

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

Basic Usage

The SuperSwitch component provides basic switch functionality:

kotlin
var isChecked by remember { mutableStateOf(false) }

SuperSwitch(
    title = "Switch Option",
    checked = isChecked,
    onCheckedChange = { isChecked = it }
)

Switch with Summary

kotlin
var wifiEnabled by remember { mutableStateOf(false) }

SuperSwitch(
    title = "WiFi",
    summary = "Turn on to connect to wireless networks",
    checked = wifiEnabled,
    onCheckedChange = { wifiEnabled = it }
)

Component States

Disabled State

kotlin
SuperSwitch(
    title = "Disabled Switch",
    summary = "This switch is currently unavailable",
    checked = true,
    onCheckedChange = {},
    enabled = false
)

Properties

SuperSwitch Properties

Property NameTypeDescriptionDefault ValueRequired
checkedBooleanSwitch checked state-Yes
onCheckedChange((Boolean) -> Unit)?Switch state change callback-Yes
titleStringSwitch item title-Yes
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Switch item summarynullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
leftAction@Composable (() -> Unit)?Custom left contentnullNo
rightActions@Composable RowScope.() -> UnitCustom right content (before switch){}No
switchColorsSwitchColorsSwitch control color configurationSwitchDefaults.switchColors()No
modifierModifierComponent modifierModifierNo
insideMarginPaddingValuesComponent internal content paddingBasicComponentDefaults.InsideMarginNo
onClick(() -> Unit)?Additional callback on switch item clicknullNo
holdDownStateBooleanWhether the component is held downfalseNo
enabledBooleanComponent interactive statetrueNo

Advanced Usage

With Left Icon

kotlin
var enabled by remember { mutableStateOf(false) }

SuperSwitch(
    title = "Test",
    summary = "Enable to allow testing",
    checked = enabled,
    onCheckedChange = { enabled = it },
    leftAction = {
        Icon(
            imageVector = MiuixIcons.Useful.Order,
            contentDescription = "Command Icon",
            tint = MiuixTheme.colorScheme.onBackground,
            modifier = Modifier.padding(end = 12.dp)
        )
    }
)

With Right Additional Content

kotlin
var locationEnabled by remember { mutableStateOf(false) }

SuperSwitch(
    title = "Location Services",
    summary = "Allow apps to access location information",
    checked = locationEnabled,
    onCheckedChange = { locationEnabled = it },
    rightActions = {
        Text(
            text = if (locationEnabled) "Enabled" else "Disabled",
            color = MiuixTheme.colorScheme.onSurfaceVariantActions,
            modifier = Modifier.padding(end = 6.dp)
        )
    }
)

With Animated Content Visibility

kotlin
var parentEnabled by remember { mutableStateOf(false) }
var childEnabled by remember { mutableStateOf(false) }

Column {
    SuperSwitch(
        title = "Main Setting",
        summary = "Turn on to show more options",
        checked = parentEnabled,
        onCheckedChange = { parentEnabled = it }
    )
    AnimatedVisibility(
        visible = parentEnabled
    ) {
        SuperSwitch(
            title = "Sub Setting",
            summary = "Only available when main setting is enabled",
            checked = childEnabled,
            onCheckedChange = { childEnabled = it }
        )
    }
}

Custom Colors

kotlin
var customEnabled by remember { mutableStateOf(false) }

SuperSwitch(
    title = "Custom Colors",
    titleColor = BasicComponentDefaults.titleColor(
        color = MiuixTheme.colorScheme.primary
    ),
    summary = "Switch with custom colors",
    summaryColor = BasicComponentDefaults.summaryColor(
        color = MiuixTheme.colorScheme.secondary
    ),
    checked = customEnabled,
    onCheckedChange = { customEnabled = it },
    switchColors = SwitchDefaults.switchColors(
        checkedThumbColor = MiuixTheme.colorScheme.primary,
        checkedTrackColor = MiuixTheme.colorScheme.primary.copy(alpha = 0.2f)
    )
)

Use with Dialog

kotlin
var showDialog = remember { mutableStateOf(false) }
var option by remember { mutableStateOf(false) }

Scaffold {
    SuperArrow(
        title = "Advanced Settings",
        onClick = { showDialog.value = true },
        holdDownState = showDialog.value
    )
    SuperDialog(
        title = "Advanced Settings",
        show = showDialog,
        onDismissRequest = { showDialog.value = false }
    ) {
        Card {
            SuperSwitch(
                title = "Experimental Features",
                summary = "Enable features under development",
                checked = option,
                onCheckedChange = { option = it }
            )
        }
        Row(
            horizontalArrangement = Arrangement.SpaceBetween,
            modifier = Modifier.padding(top = 12.dp)
        ) {
            TextButton(
                text = "Cancel",
                onClick = { showDialog.value = false },
                modifier = Modifier.weight(1f)
            )
            Spacer(Modifier.width(16.dp))
            TextButton(
                text = "Confirm",
                onClick = { showDialog.value = false },
                modifier = Modifier.weight(1f),
                colors = ButtonDefaults.textButtonColorsPrimary()
            )
        }
    }
}

Released under the Apache-2.0 License