Cards
Cardsanimated

Smart Device Toggle

Smart-home device tile with an animated state pill and live status text.

Living Room Plug

On · 38W

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 SmartToggleCard() {
  var on by remember { mutableStateOf(true) }
  val bg by animateColorAsState(
    if (on) Color(0xFF34C759)
    else Color(0xFFBDBDBD), label = "bg"
  )
  ElevatedCard(Modifier.fillMaxWidth()) {
    Row(
      Modifier.padding(20.dp),
      verticalAlignment = Alignment.CenterVertically
    ) {
      Box(
        Modifier.size(40.dp).background(
          bg.copy(alpha = 0.2f), CircleShape
        ),
        contentAlignment = Alignment.Center
      ) {
        Box(
          Modifier.size(18.dp).background(bg, CircleShape)
        )
      }
      Spacer(Modifier.width(14.dp))
      Column(Modifier.weight(1f)) {
        Text(
          "Living Room Plug",
          style = MaterialTheme.typography.titleMedium
        )
        Text(
          if (on) "On · 38W" else "Off",
          style = MaterialTheme.typography.labelMedium,
          color = MaterialTheme.colorScheme
            .onSurfaceVariant
        )
      }
      Switch(checked = on, onCheckedChange = { on = it })
    }
  }
}