Icons
Iconsanimated

Rate

A rating star that fills from the bottom and throws a quick sparkle when selected.

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 RateStar(selected: Boolean, onClick: () -> Unit) {
    val fill by animateFloatAsState(if (selected) 1f else 0f, spring(stiffness = 300f), label = "fill")
    val color = Color(0xFFF59E0B)
    Canvas(Modifier.size(40.dp).clickable(onClick = onClick)) {
        val star = starPath(center, size.minDimension * 0.42f)
        drawPath(star, color, style = Stroke(2.5.dp.toPx(), join = StrokeJoin.Round))
        clipPath(star) { drawRect(color, Offset(0f, size.height * (1f - fill)), Size(size.width, size.height)) }
    }
}