Skip to content

SuperCheckbox

SuperCheckbox is a checkbox component in Miuix that provides a title, summary, and checkbox control. It supports click interactions and is commonly used in multi-select settings and selection lists.

Import

kotlin
import top.yukonga.miuix.kmp.extra.SuperCheckbox
import top.yukonga.miuix.kmp.extra.CheckboxLocation

Basic Usage

SuperCheckbox component provides basic checkbox functionality:

kotlin
var isChecked by remember { mutableStateOf(false) }

SuperCheckbox(
    title = "Checkbox Option",
    checked = isChecked,
    onCheckedChange = { isChecked = it }
)

Checkbox with Summary

kotlin
var notificationsEnabled by remember { mutableStateOf(false) }

SuperCheckbox(
    title = "Notifications",
    summary = "Receive push notifications from the app",
    checked = notificationsEnabled,
    onCheckedChange = { notificationsEnabled = it }
)

Component States

Disabled State

kotlin
SuperCheckbox(
    title = "Disabled Checkbox",
    summary = "This checkbox is currently unavailable",
    checked = true,
    onCheckedChange = {},
    enabled = false
)

Checkbox Position

SuperCheckbox supports placing the checkbox on the left or right side:

Left Checkbox (Default)

kotlin
var leftChecked by remember { mutableStateOf(false) }

SuperCheckbox(
    title = "Left Checkbox",
    summary = "Checkbox is on the left side (default)",
    checked = leftChecked,
    onCheckedChange = { leftChecked = it },
    checkboxLocation = CheckboxLocation.Left // Default value
)

Right Checkbox

kotlin
var rightChecked by remember { mutableStateOf(false) }

SuperCheckbox(
    title = "Right Checkbox",
    summary = "Checkbox is on the right side",
    checked = rightChecked,
    onCheckedChange = { rightChecked = it },
    checkboxLocation = CheckboxLocation.Right
)

Properties

SuperCheckbox Properties

Property NameTypeDescriptionDefault ValueRequired
titleStringTitle of the checkbox item-Yes
checkedBooleanCheckbox checked state-Yes
onCheckedChange((Boolean) -> Unit)?Callback when checkbox state changes-Yes
modifierModifierModifier applied to componentModifierNo
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary descriptionnullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
checkboxColorsCheckboxColorsCheckbox control color configurationCheckboxDefaults.checkboxColors()No
rightActions@Composable RowScope.() -> UnitCustom content before checkbox{}No
checkboxLocationCheckboxLocationCheckbox positionCheckboxLocation.LeftNo
onClick(() -> Unit)?Additional callback on item clicknullNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo
enabledBooleanWhether component is interactivetrueNo

Advanced Usage

With Right Actions

kotlin
var backupEnabled by remember { mutableStateOf(false) }

SuperCheckbox(
    title = "Auto Backup",
    summary = "Periodically backup your data",
    checked = backupEnabled,
    onCheckedChange = { backupEnabled = it },
    rightActions = {
        Text(
            text = if (backupEnabled) "Enabled" else "Disabled",
            color = MiuixTheme.colorScheme.onSurfaceVariantActions,
            modifier = Modifier.padding(end = 6.dp)
        )
    }
)

Nested Checkboxes

kotlin
var allSelected by remember { mutableStateOf(false) }
var option1 by remember { mutableStateOf(false) }
var option2 by remember { mutableStateOf(false) }
var option3 by remember { mutableStateOf(false) }

Column {
    SuperCheckbox(
        title = "Select All",
        checked = allSelected,
        onCheckedChange = { newState ->
            allSelected = newState
            option1 = newState
            option2 = newState
            option3 = newState
        }
    )
    SuperCheckbox(
        title = "Option 1",
        checked = option1,
        onCheckedChange = { 
            option1 = it 
            allSelected = option1 && option2 && option3
        },
        modifier = Modifier.padding(start = 24.dp)
    )
    SuperCheckbox(
        title = "Option 2",
        checked = option2,
        onCheckedChange = { 
            option2 = it 
            allSelected = option1 && option2 && option3
        },
        modifier = Modifier.padding(start = 24.dp)
    )
    SuperCheckbox(
        title = "Option 3",
        checked = option3,
        onCheckedChange = { 
            option3 = it 
            allSelected = option1 && option2 && option3
        },
        modifier = Modifier.padding(start = 24.dp)
    )
}

Custom Colors

kotlin
var customChecked by remember { mutableStateOf(false) }

SuperCheckbox(
    title = "Custom Colors",
    titleColor = BasicComponentDefaults.titleColor(
        color = MiuixTheme.colorScheme.primary
    ),
    summary = "Checkbox with custom colors",
    summaryColor = BasicComponentDefaults.summaryColor(
        color = MiuixTheme.colorScheme.secondary
    ),
    checked = customChecked,
    onCheckedChange = { customChecked = it },
    checkboxColors = CheckboxDefaults.checkboxColors(
        checkedForegroundColor = Color.Red,
        checkedBackgroundColor = MiuixTheme.colorScheme.secondary
    )
)

Using with Dialog

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

Scaffold {
    SuperArrow(
        title = "Privacy Settings",
        onClick = { showDialog.value = true },
        holdDownState = showDialog.value
    )
    
    SuperDialog(
        title = "Privacy Settings",
        show = showDialog,
        onDismissRequest = { showDialog.value = false } // Close dialog
    ) {
        Card {
            SuperCheckbox(
                title = "Privacy Policy",
                summary = "Agree to the privacy policy terms",
                checked = privacyOption,
                onCheckedChange = { privacyOption = it }
            )
            
            SuperCheckbox(
                title = "Analytics Data",
                summary = "Allow collection of anonymous usage data to improve services",
                checked = analyticsOption,
                onCheckedChange = { analyticsOption = it }
            )
        }
        
        Row(
            horizontalArrangement = Arrangement.SpaceBetween,
            modifier = Modifier.padding(top = 12.dp)
        ) {
            TextButton(
                text = "Cancel",
                onClick = { showDialog.value = false }, // Close dialog
                modifier = Modifier.weight(1f)
            )
            Spacer(Modifier.width(16.dp))
            TextButton(
                text = "Confirm",
                onClick = { showDialog.value = false }, // Close dialog
                modifier = Modifier.weight(1f),
                colors = ButtonDefaults.textButtonColorsPrimary() // Use theme colors
            )
        }
    }
}

Released under the Apache-2.0 License