Skip to content

ButtonPreference

ButtonPreference is a preference row with a small inline button at the end, mirroring ColorOS's COUIButtonPreference. The button follows the COUI small button style (couiSmallButtonColorStyleWidget.COUI.Button.Small): a 52×28dp minimum capsule filled with the theme accent and a 14sp medium label. The button click is independent from the row click.

Import

kotlin
import io.github.suqi8.coui.kmp.preference.ButtonPreference
import io.github.suqi8.coui.kmp.preference.ButtonPreferenceDefaults

Basic Usage

kotlin
ButtonPreference(
    title = "Account",
    summary = "Sign in to sync your data",
    buttonText = "Sign in",
    onButtonClick = { /* handle button click */ }
)

With a Clickable Row

The row click (onClick) is separate from the button click (onButtonClick):

kotlin
ButtonPreference(
    title = "Storage",
    summary = "12.3 GB used",
    buttonText = "Clean",
    onButtonClick = { /* clean */ },
    onClick = { /* open storage details */ }
)

Component States

Disabled State

Disabling the preference disables both the row and the inline button:

kotlin
ButtonPreference(
    title = "Disabled Row",
    summary = "Button and row are disabled",
    buttonText = "Action",
    onButtonClick = {},
    enabled = false
)

Hold Down State

ButtonPreference supports controlling the hold-down state of the row through the holdDownState parameter, typically used for visual feedback when displaying popup dialogs:

kotlin
var showDialog by remember { mutableStateOf(false) }

Scaffold {
    ButtonPreference(
        title = "Account",
        summary = "Manage account details",
        buttonText = "Sign in",
        onButtonClick = { /* sign in */ },
        onClick = { showDialog = true },
        holdDownState = showDialog
    )
    OverlayDialog(
        title = "Account Details",
        show = showDialog,
        onDismissRequest = { showDialog = false }
    ) {
        // Dialog content
    }
}

Properties

ButtonPreference Properties

Property NameTypeDescriptionDefault ValueRequired
titleStringPreference title-Yes
buttonTextStringLabel of the inline button-Yes
onButtonClick() -> UnitCallback when the inline button is clicked-Yes
modifierModifierComponent modifierModifierNo
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Preference summarynullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
startAction@Composable (() -> Unit)?Custom start side contentnullNo
endActions@Composable RowScope.() -> UnitCustom end side content (before the button){}No
bottomAction@Composable (() -> Unit)?Custom bottom side contentnullNo
buttonColorsButtonColorsInline button color configurationButtonPreferenceDefaults.buttonColors()No
buttonMinWidthDpMinimum width of the inline buttonButtonPreferenceDefaults.ButtonMinWidthNo
buttonMinHeightDpMinimum height of the inline buttonButtonPreferenceDefaults.ButtonMinHeightNo
buttonCornerRadiusDpCorner radius of the inline buttonButtonPreferenceDefaults.ButtonCornerRadiusNo
buttonInsideMarginPaddingValuesPadding inside the inline buttonButtonPreferenceDefaults.ButtonInsideMarginNo
insideMarginPaddingValuesComponent internal content paddingBasicComponentDefaults.InsideMarginNo
cardListPositionCardListPositionRow position inside its card group; rounded outer edges gain extra paddingCardListPosition.NoneNo
onClick(() -> Unit)?Callback when the row (not the button) is clickednullNo
holdDownStateBooleanWhether the component is held downfalseNo
enabledBooleanComponent interactive statetrueNo

ButtonPreferenceDefaults Object

ConstantTypeDefault ValueDescription
ButtonMinWidthDp52.dpCOUI coui_btn_small_width_min
ButtonMinHeightDp28.dpCOUI coui_btn_small_height_min
ButtonCornerRadiusDp14.dpCapsule radius (COUI drawableRadius -1 = height / 2)
ButtonInsideMarginPaddingValuesPaddingValues(horizontal = 12.dp, vertical = 4.dp)Widget.COUI.Button.Small padding

buttonColors() factory

ParameterTypeDefault
colorColorCOUITheme.colorScheme.primary
disabledColorColorCOUITheme.colorScheme.disabledPrimaryButton
contentColorColorCOUITheme.colorScheme.onPrimary
disabledContentColorColorCOUITheme.colorScheme.disabledOnPrimaryButton

Advanced Usage

Custom Button Colors

kotlin
ButtonPreference(
    title = "Remove Device",
    buttonText = "Remove",
    onButtonClick = { /* remove */ },
    buttonColors = ButtonPreferenceDefaults.buttonColors(
        color = COUITheme.colorScheme.error,
        contentColor = COUITheme.colorScheme.onError
    )
)

With End Actions

Content passed to endActions is placed before the inline button:

kotlin
ButtonPreference(
    title = "Membership",
    summary = "Current plan",
    buttonText = "Upgrade",
    onButtonClick = { /* upgrade */ },
    endActions = {
        Text(
            text = "Free",
            color = COUITheme.colorScheme.onSurfaceVariantActions
        )
    }
)

With Start Icon

kotlin
ButtonPreference(
    title = "Bluetooth Device",
    summary = "Paired",
    buttonText = "Connect",
    onButtonClick = { /* connect */ },
    startAction = {
        Icon(
            imageVector = COUIIcons.Sort,
            contentDescription = null,
            tint = COUITheme.colorScheme.onBackground,
            modifier = Modifier.padding(end = 12.dp)
        )
    }
)

Changelog

Released under the Apache-2.0 License