Icons
Iconsanimated

Menu ↔ Close

A hamburger menu whose three lines morph into a close (X) — the canonical nav toggle.

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 MenuToClose(open: Boolean, onClick: () -> Unit) {
    val p by animateFloatAsState(if (open) 1f else 0f, spring(stiffness = 300f), label = "menu")
    val color = LocalContentColor.current
    Canvas(Modifier.size(40.dp).clickable(onClick = onClick)) {
        val w = size.width; val cx = w / 2; val cy = size.height / 2
        val len = w * 0.55f; val gap = 7.dp.toPx()
        val stroke = 3.dp.toPx()
        fun line(offsetY: Float, angle: Float) {
            rotate(angle * p, pivot = Offset(cx, cy)) {
                drawLine(
                    color, Offset(cx - len / 2, cy + offsetY * (1 - p)),
                    Offset(cx + len / 2, cy + offsetY * (1 - p)),
                    strokeWidth = stroke, cap = StrokeCap.Round,
                )
            }
        }
        line(-gap, 45f)                 // top  -> "\"
        if (p < 0.5f) line(0f, 0f)      // middle fades out
        line(gap, -45f)                 // bottom -> "/"
    }
}