Composables
Docs Login
Vela

Tool Chip

Jetpack Compose Component

Download
package com.composables.vela.components

import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
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.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import com.composables.compose.ripple.rememberRippleIndication
import com.composables.vela.theme.Icons
import com.composables.vela.theme.Space
import com.composables.vela.theme.Theme
import com.composables.vela.theme.X
import com.composeunstyled.UnstyledButton

@Composable
fun ToolChip(
    label: String,
    icon: ImageVector,
    onRemove: () -> Unit,
    modifier: Modifier = Modifier,
) {
    UnstyledButton(
        onClick = onRemove,
        modifier = modifier.clip(Theme.shapes.fullyRounded).background(Theme.colors.surfaceVariant),
        contentPadding =
            PaddingValues(
                start = Space * 2.5f,
                end = Space * 2,
                top = Space * 1.5f,
                bottom = Space * 1.5f,
            ),
        indication = rememberRippleIndication(color = Theme.colors.onSurfaceVariant),
        interactionSource = remember { MutableInteractionSource() },
    ) {
        Row(
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.spacedBy(Space * 1.5f),
        ) {
            Icon(
                icon,
                contentDescription = null,
                modifier = Modifier.size(16.dp),
                tint = Theme.colors.primary,
            )
            Text(label, style = Theme.typography.label, color = Theme.colors.onSurfaceVariant)
            Icon(
                Icons.X,
                contentDescription = "Turn off $label",
                modifier = Modifier.size(12.dp),
                tint = Theme.colors.onBackgroundMuted,
            )
        }
    }
}

More components from Vela

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.