Skip to content

Commit

Permalink
Add setting tile for theme
Browse files Browse the repository at this point in the history
  • Loading branch information
alorma committed May 26, 2024
1 parent 23175f3 commit 5d7b88b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
27 changes: 27 additions & 0 deletions composeApp/src/commonMain/kotlin/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -24,6 +26,7 @@ import com.alorma.compose.settings.ui.SettingsMenuLink
import com.alorma.compose.settings.ui.SettingsRadioButton
import com.alorma.compose.settings.ui.SettingsSlider
import com.alorma.compose.settings.ui.SettingsSwitch
import com.alorma.compose.settings.ui.SettingsTheme
import com.alorma.compose.settings.ui.SettingsTriStateCheckbox
import internal.MultiChoiceAlertDialog
import internal.SampleData
Expand Down Expand Up @@ -415,5 +418,29 @@ private fun SettingsGroupSectionSample(showIcon: Boolean) {
valueRange = 0f..20f,
steps = 20,
)

val colors = listOf(
MaterialTheme.colorScheme.surfaceContainerHighest,
MaterialTheme.colorScheme.primary,
MaterialTheme.colorScheme.secondary,
MaterialTheme.colorScheme.tertiary,
MaterialTheme.colorScheme.error,
)
SettingsTheme(
stateColors = colors,
title = { Text(text = "Material colors") },
subtitle = { Text(text = "A subset of colors") },
icon = iconSampleOrNull(showIcon),
action = {
IconButton(
onClick = {},
) {
Icon(
imageVector = Icons.Default.Settings,
contentDescription = null,
)
}
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.alorma.compose.settings.ui

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ListItemColors
import androidx.compose.material3.ListItemDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
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 SettingsTheme(
stateColors: List<Color>,
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = LocalSettingsGroupEnabled.current,
icon: @Composable (() -> Unit)? = null,
subtitle: @Composable (() -> Unit)? = null,
colors: ListItemColors = ListItemDefaults.colors(),
tonalElevation: Dp = ListItemDefaults.Elevation,
shadowElevation: Dp = ListItemDefaults.Elevation,
action: @Composable (() -> Unit)? = null,
onClick: (() -> Unit)? = null,
) {
SettingsTileScaffold(
modifier = Modifier.clickable(
enabled = enabled,
onClick = { onClick?.invoke() },
).then(modifier),
enabled = enabled,
title = title,
subtitle = subtitle,
icon = icon,
colors = colors,
tonalElevation = tonalElevation,
shadowElevation = shadowElevation,
action = action,
)
Row(
horizontalArrangement = Arrangement.SpaceEvenly,
) {
stateColors.forEach { color ->
Card(
modifier = Modifier
.height(80.dp)
.weight(1f)
.padding(8.dp),
colors = CardDefaults.cardColors(containerColor = color)
) {

}
}
}
}

0 comments on commit 5d7b88b

Please sign in to comment.