commonMain.com.alorma.compose.settings.ui.SettingsSwitch.kt Maven / Gradle / Ivy
package com.alorma.compose.settings.ui
import androidx.compose.foundation.selection.toggleable
import androidx.compose.material3.ListItemColors
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchColors
import androidx.compose.material3.SwitchDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.Dp
import com.alorma.compose.settings.ui.base.internal.LocalSettingsGroupEnabled
import com.alorma.compose.settings.ui.base.internal.SettingsTileScaffold
@Composable
fun SettingsSwitch(
state: Boolean,
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = LocalSettingsGroupEnabled.current,
icon: @Composable (() -> Unit)? = null,
subtitle: @Composable (() -> Unit)? = null,
switchColors: SwitchColors = SwitchDefaults.colors(),
colors: ListItemColors = ListItemDefaults.colors(),
tonalElevation: Dp = ListItemDefaults.Elevation,
shadowElevation: Dp = ListItemDefaults.Elevation,
onCheckedChange: (Boolean) -> Unit,
) {
val update: (Boolean) -> Unit = { boolean -> onCheckedChange(boolean) }
SettingsTileScaffold(
modifier = Modifier.toggleable(
enabled = enabled,
value = state,
role = Role.Switch,
onValueChange = { update(!state) },
).then(modifier),
enabled = enabled,
title = title,
subtitle = subtitle,
icon = icon,
colors = colors,
tonalElevation = tonalElevation,
shadowElevation = shadowElevation,
) {
Switch(
enabled = enabled,
checked = state,
onCheckedChange = update,
colors = switchColors,
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy