Created
June 15, 2022 09:32
-
-
Save EmmanuelGuther/f7300c98dd5ee22b82d42f98cc7f56c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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