Skip to content

Chip

A capsule shaped, checkable filter tag mirroring ColorOS's COUIChip in its selection style (Widget.COUI.Chip.Choice). The unselected chip is a translucent gray capsule with a primary label; selecting it fills the capsule with the accent color and flips the label to white. The two states cross-fade on the COUI check spring, and pressing shrinks the chip while tinting the fill like COUIPressFeedbackHelper.

Import

kotlin
import io.github.suqi8.coui.kmp.basic.Chip
import io.github.suqi8.coui.kmp.basic.ChipDefaults

Basic Usage

kotlin
var selected by remember { mutableStateOf(false) }

Chip(
    selected = selected,
    onClick = { selected = !selected },
    label = "Recommended",
)

With a Leading Icon

The icon is laid out in a 16dp box and tinted with the current label color through LocalContentColor (COUIChip chipIconApplyTint).

kotlin
Chip(
    selected = selected,
    onClick = { selected = !selected },
    label = "Recommended",
    icon = {
        Icon(
            imageVector = COUIIcons.Basic.Check,
            contentDescription = null,
            modifier = Modifier.size(16.dp),
        )
    },
)

Single Selection Group

kotlin
var selectedIndex by remember { mutableIntStateOf(0) }

Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    listOf("All", "Photos", "Videos").forEachIndexed { index, label ->
        Chip(
            selected = selectedIndex == index,
            onClick = { selectedIndex = index },
            label = label,
        )
    }
}

The 8dp spacing matches COUIChipGroup's default horizontal/vertical spacing.

Component States

Disabled State

A disabled chip keeps its selected/unselected shape but switches to the disabled container and content colors, and no longer reacts to presses:

kotlin
Chip(
    selected = true,
    onClick = { /* Ignored while disabled */ },
    label = "Disabled",
    enabled = false,
)

Properties

Chip

PropertyTypeDescriptionDefault ValueRequired
selectedBooleanWhether the chip is selected-Yes
onClick() -> UnitCallback when the chip is clicked-Yes
labelStringText label (single line, ellipsized)-Yes
modifierModifierModifier applied to the chipModifierNo
enabledBooleanWhether the chip is enabledtrueNo
icon(@Composable () -> Unit)?Optional leading iconnullNo
cornerRadiusDpCorner radius of the capsuleChipDefaults.CornerRadiusNo
minWidthDpMinimum widthChipDefaults.MinWidthNo
minHeightDpMinimum heightChipDefaults.MinHeightNo
maxWidthDpMaximum widthChipDefaults.MaxWidthNo
colorsChipColorsColor configurationChipDefaults.chipColors()No
insideMarginPaddingValuesHorizontal padding inside the chipChipDefaults.InsideMarginNo
interactionSourceMutableInteractionSource?Interaction source of the chipnullNo
indicationIndication?Indication (press feedback is built in)nullNo

ChipDefaults

ConstantTypeDefault ValueCOUI Source
MinWidthDp52.dpcoui_chip_default_min_width
MinHeightDp32.dpcoui_chip_selection_style_height
MaxWidthDp300.dpcoui_chip_default_max_width
TextMaxWidthDp200.dpcoui_chip_default_max_text_width
CornerRadiusDp16.dpchipCornerRadius -1 → capsule (height / 2)
IconSizeDp16.dpcoui_chip_selection_style_chip_icon_size
IconSpacingDp4.dpcoui_chip_selection_style_chip_icon_end_padding
InsideMarginPaddingValuesPaddingValues(horizontal = 12.dp)coui_chip_selection_style_chip_horizontal_padding

Methods

Method NameTypeDescription
textStyle()TextStyleDefault label style (COUITheme.textStyles.body2, COUI couiTextBodyM 14sp)
chipColors()ChipColorsCreates the color configuration for the chip

chipColors() factory

ParameterTypeDefaultCOUI Attribute
containerColorColorCOUITheme.colorScheme.secondaryVariantuncheckedBackgroundColor
selectedContainerColorColorCOUITheme.colorScheme.primarycheckedBackgroundColor
disabledContainerColorColorCOUITheme.colorScheme.disabledSecondaryVariantuncheckedDisabledBackgroundColor
selectedDisabledContainerColorColorCOUITheme.colorScheme.disabledPrimaryButtoncheckedDisabledBackgroundColor
contentColorColorCOUITheme.colorScheme.onSurfaceuncheckedTextColor
selectedContentColorColorCOUITheme.colorScheme.onPrimarycheckedTextColor
disabledContentColorColorCOUITheme.colorScheme.disabledOnSecondaryVariantuncheckedDisabledTextColor
selectedDisabledContentColorColorCOUITheme.colorScheme.disabledOnPrimaryButtoncheckedDisabledTextColor

Behavior

  • Selecting/deselecting cross-fades the capsule, label and icon colors on a critically damped spring (COUIChipDrawable.TintAnimation, response 0.3s / bounce 0).
  • Pressing shrinks the chip towards 0.92 of its size and overlays the press tint (COUIPressFeedbackHelper + COUIMaskEffectDrawable); a quick tap still flashes the tint visibly.
  • The label is single line and ellipsized beyond TextMaxWidth; the whole chip is clamped between MinWidth and MaxWidth.

Changelog

Released under the Apache-2.0 License