Last active
July 27, 2023 13:45
-
-
Save zurche/f3015ec8993a68ab249543e5695a1f9c to your computer and use it in GitHub Desktop.
This file contains 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 MonthlyCapPreview(monthlyPreview: List<Pair<String, Float>>) { | |
Column(horizontalAlignment = Alignment.CenterHorizontally) { | |
val maxMonthValue = monthlyPreview.maxBy { it.second }.second | |
Row( | |
modifier = Modifier.fillMaxHeight(.8f), | |
verticalAlignment = Alignment.Bottom | |
) { | |
for (pairPreview in monthlyPreview) { | |
val columnHeightWeight = pairPreview.second / maxMonthValue | |
Card( | |
modifier = Modifier | |
.weight(1f) | |
.fillMaxHeight(columnHeightWeight) | |
.padding(5.dp), | |
colors = CardDefaults.cardColors( | |
containerColor = setHighlightColor( | |
pairPreview, | |
maxMonthValue | |
) | |
), | |
shape = RoundedCornerShape(30) //<--- Adding some "extra roundiness" | |
) { } | |
} | |
} | |
Row( | |
verticalAlignment = Alignment.CenterVertically | |
) { | |
for (pairPreview in monthlyPreview) { | |
Text( | |
modifier = Modifier.weight(1f), | |
text = pairPreview.first, | |
textAlign = TextAlign.Center, | |
fontWeight = FontWeight.SemiBold, | |
color = setHighlightColor(pairPreview, maxMonthValue) | |
) | |
} | |
} | |
} | |
} | |
@Composable | |
private fun setHighlightColor( //<--- Helper function to determine colour of Text and Bar | |
pairPreview: Pair<String, Float>, | |
maxMonthValue: Float | |
) = if (pairPreview.second == maxMonthValue) Color.White else Color.White.copy( | |
alpha = 0.4f | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment