Cards
Cardsanimated

Rating Distribution

Star-labelled bars show how reviews distribute across rating levels.

4.6
5
4
3
2
1

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
@Composable
fun RatingDistributionCard() {
  val rows = listOf(5 to 0.7f, 4 to 0.5f, 3 to 0.25f, 2 to 0.1f, 1 to 0.05f)
  Card(
    shape = RoundedCornerShape(18.dp),
    modifier = Modifier.width(260.dp),
  ) {
    Column(Modifier.padding(18.dp)) {
      Row(verticalAlignment = Alignment.CenterVertically) {
        Text(
          text = "4.6",
          style = MaterialTheme.typography.headlineMedium,
          fontWeight = FontWeight.Bold,
        )
        Spacer(Modifier.width(8.dp))
        Icon(
          imageVector = Icons.Default.Star,
          contentDescription = null,
          tint = Color(0xFFF59E0B),
        )
      }
      Spacer(Modifier.height(10.dp))
      rows.forEach { (stars, frac) ->
        val a = remember { Animatable(0f) }
        LaunchedEffect(Unit) {
          a.animateTo(frac, tween(700, easing = FastOutSlowInEasing))
        }
        Row(
          verticalAlignment = Alignment.CenterVertically,
          modifier = Modifier.padding(vertical = 2.dp),
        ) {
          Text(
            text = "$stars",
            style = MaterialTheme.typography.labelSmall,
            modifier = Modifier.width(12.dp),
          )
          Spacer(Modifier.width(6.dp))
          Box(
            Modifier
              .weight(1f)
              .height(8.dp)
              .clip(RoundedCornerShape(50))
              .background(MaterialTheme.colorScheme.surfaceVariant),
          ) {
            Box(
              Modifier
                .fillMaxWidth(a.value)
                .fillMaxHeight()
                .clip(RoundedCornerShape(50))
                .background(Color(0xFFF59E0B)),
            )
          }
        }
      }
    }
  }
}