Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created June 15, 2022 09:32
Show Gist options
  • Save EmmanuelGuther/f7300c98dd5ee22b82d42f98cc7f56c3 to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/f7300c98dd5ee22b82d42f98cc7f56c3 to your computer and use it in GitHub Desktop.
@Composable
fun CategoriesHorizontalList(modifier: Modifier = Modifier, data: List<String>) {
val selectedHourState = remember { mutableStateOf(0) }
Card(
elevation = elevationDefault, shape = boxShapeDefault, modifier = Modifier.padding(8.dp)
) {
LazyRow(
modifier = modifier.background(MaterialTheme.colors.primary.copy(alpha = 0.9f)),
horizontalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 8.dp)
) {
items(data) {
val selected = (selectedHourState.value == data.indexOf(it))
Box(
modifier = Modifier
.padding(8.dp)
.clip(shape = boxShapeDefault)
.background(if (selected) MaterialTheme.colors.primary else Color.White)
.clickable {
selectedHourState.value = data.indexOf(it)
},
) {
Text(
modifier = modifier.padding(8.dp),
text = it,
style = MaterialTheme.typography.overline,
color = if (selected) Color.White else Color.Black
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment