commonMain.com.softartdev.theme.material3.ThemeDialog.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of theme-material3-desktop Show documentation
Show all versions of theme-material3-desktop Show documentation
Kotlin Multiplatform library for easy switching Dark/Light Material themes on Compose.
The newest version!
package com.softartdev.theme.material3
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import com.softartdev.theme.pref.ThemeEnum
import io.github.softartdev.theme_prefs.generated.resources.Res
import io.github.softartdev.theme_prefs.generated.resources.cancel
import io.github.softartdev.theme_prefs.generated.resources.choose_theme
import io.github.softartdev.theme_prefs.generated.resources.ok
import org.jetbrains.compose.resources.stringResource
@Composable
fun ThemeDialog(
darkThemeState: MutableState = mutableStateOf(ThemeEnum.SystemDefault),
writePref: (ThemeEnum) -> Unit = {},
dismissDialog: () -> Unit = {}
) {
val previousState = remember { darkThemeState.value }
AlertDialog(
onDismissRequest = dismissDialog,
title = { Text(stringResource(Res.string.choose_theme)) },
text = { RadioDialogContent(darkThemeState) },
confirmButton = {
Button(onClick = {
writePref(darkThemeState.value)
dismissDialog()
}) { Text(stringResource(Res.string.ok)) }
},
dismissButton = {
Button(onClick = {
darkThemeState.value = previousState
dismissDialog()
}) { Text(stringResource(Res.string.cancel)) }
},
)
}