Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Last active March 17, 2024 00:41
Show Gist options
  • Save fvilarino/4f7a15f9df6381f3226d279323652571 to your computer and use it in GitHub Desktop.
Save fvilarino/4f7a15f9df6381f3226d279323652571 to your computer and use it in GitHub Desktop.
Chip Selector - Basic Chip
@Composable
fun Chip(
// 1
label: String,
// 2
isSelected: Boolean,
// 3
onClick: () -> Unit,
// 4
modifier: Modifier = Modifier
) {
// 5
val backgroundColor = if (isSelected) {
MaterialTheme.colorScheme.primaryContainer
} else {
MaterialTheme.colorScheme.secondaryContainer
}
// 6
val textColor = if (isSelected) {
MaterialTheme.colorScheme.onPrimaryContainer
} else {
MaterialTheme.colorScheme.onSecondaryContainer
}
// 7
Box(
modifier = modifier
.clip(shape = RoundedCornerShape(percent = 100))
.background(backgroundColor)
.clickable(onClick = onClick)
) {
// 8
Text(
text = label,
color = textColor,
fontWeight = FontWeight.Bold,
modifier = Modifier
.padding(horizontal = 24.dp, vertical = 16.dp)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment