Composables
Docs Login
Tally

Filter Chip

Jetpack Compose Component

Download
package com.composables.tally.components

import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.composables.compose.ripple.rememberRippleIndication
import com.composables.tally.theme.Space
import com.composables.tally.theme.Theme

@Composable
fun FilterChip(
    label: String,
    count: Int,
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
) {
    val container = if (selected) Theme.colors.primary else Theme.colors.surfaceVariant
    val content = if (selected) Theme.colors.onPrimary else Theme.colors.onSurfaceVariant
    Row(
        modifier
            .heightIn(min = 44.dp)
            .clip(Theme.shapes.fullyRounded)
            .background(container)
            .selectable(
                selected = selected,
                onClick = onClick,
                role = Role.Tab,
                interactionSource = remember { MutableInteractionSource() },
                indication = rememberRippleIndication(color = content),
            )
            .padding(horizontal = Space * 4),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(Space * 2),
    ) {
        Text(label, style = Theme.typography.label, color = content)
        Text(
            count.toString(),
            style = Theme.typography.label,
            color = if (selected) content.copy(alpha = 0.7f) else Theme.colors.onBackgroundMuted,
        )
    }
}

More components from Tally

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements

One Android lesson, every Wednesday

Building Android apps?

What Alex learned building Android apps for 14 years, so you don't have to. Reads in under a minute.

Join 3,500+ Android developers. Unsubscribe any time.

You're subscribed

The next lesson lands in on Wednesday.