Skip to content

Commit

Permalink
Merge pull request #20082 from wordpress-mobile/feature/19802-designs…
Browse files Browse the repository at this point in the history
…ystem-part3

Add custom theme for Design System
  • Loading branch information
aditi-bhatia authored Feb 5, 2024
2 parents 1b865d8 + b3147f9 commit dd1d1e9
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wordpress.android.designsystem

import android.content.res.Configuration
import android.os.Bundle
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import org.wordpress.android.ui.LocaleAwareActivity
Expand All @@ -10,8 +11,10 @@ import org.wordpress.android.util.extensions.setContent
class DesignSystemActivity : LocaleAwareActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DesignSystem(onBackPressedDispatcher::onBackPressed)
setContent {
DesignSystemTheme(isSystemInDarkTheme()) {
DesignSystem(onBackPressedDispatcher::onBackPressed)
}
}
}

Expand All @@ -21,11 +24,10 @@ class DesignSystemActivity : LocaleAwareActivity() {
showBackground = true,
name = "Dark Mode"
)

@Composable
fun PreviewDesignSystemActivity() {
DesignSystem(onBackPressedDispatcher::onBackPressed)
DesignSystemTheme(isSystemInDarkTheme()) {
DesignSystem(onBackPressedDispatcher::onBackPressed)
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.wordpress.android.designsystem

import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color

/**
* Object containing static common colors used throughout the project. Note that the colors here are not SEMANTIC,
* meaning they don't represent the usage of the color (e.g.: PrimaryButtonBackground) but instead they are raw
* colors used throughout this app's design (e.g.: Green50).
*/
object DesignSystemAppColor {
// Black & White
@Stable
val Black = Color(0xFF000000)

@Stable
val White = Color(0xFFFFFFFF)

// Grays
@Stable
val Gray = Color(0xFFF2F2F7)

@Stable
val Gray10 = Color(0xFFC2C2C6)

@Stable
val Gray20 = Color(0x99EBEBF5)

@Stable
val Gray30 = Color(0xFF9B9B9E)

@Stable
val Gray40 = Color(0x993C3C43)

@Stable
val Gray50 = Color(0x4D3C3C43)

@Stable
val Gray60 = Color(0xFF4E4E4F)

@Stable
val Gray70 = Color(0xFF3A3A3C)

@Stable
val Gray80 = Color(0xFF2C2C2E)

// Blues
@Stable
val Blue = Color(0xFF0675C4)

@Stable
val Blue10 = Color(0xFF399CE3)

@Stable
val Blue20 = Color(0xFF1689DB)

// Greens
@Stable
val Green = Color(0xFF008710)

@Stable
val Green10 = Color(0xFF2FB41F)

@Stable
val Green20 = Color(0xFF069E08)

// Reds
@Stable
val Red = Color(0xFFD63638)

@Stable
val Red10 = Color(0xFFE65054)

// Oranges
@Stable
val Orange = Color(0xFFD67709)

@Stable
val Orange10 = Color(0xFFE68B28)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.wordpress.android.designsystem

import androidx.annotation.StringRes
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
Expand Down Expand Up @@ -37,7 +39,10 @@ fun SelectOptionButton(
Button(
onClick = onClick,
modifier = modifier.widthIn(min = 250.dp),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary)
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.brand,
contentColor = MaterialTheme.colorScheme.primaryContainer
)
) {
Text(stringResource(labelResourceId))
}
Expand All @@ -46,7 +51,9 @@ fun SelectOptionButton(
@Preview
@Composable
fun StartDesignSystemPreview(){
DesignSystem {}
DesignSystemTheme(isSystemInDarkTheme()) {
DesignSystem {}
}
}

@Composable
Expand All @@ -60,18 +67,19 @@ fun DesignSystem(
title = stringResource(R.string.preference_design_system),
navigationIcon = NavigationIcons.BackIcon,
onNavigationIconClick = { onBackTapped() },
backgroundColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface,
backgroundColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.primary,
)
},
}
) { innerPadding ->
NavHost(
modifier = Modifier.background(MaterialTheme.colorScheme.primaryContainer),
navController = navController,
startDestination = DesignSystemScreen.Start.name
) {
composable(route = DesignSystemScreen.Start.name) {
DesignSystemStartScreen(
onNextButtonClicked = {
onButtonClicked = {
navController.navigate(it)
},
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.wordpress.android.R

@Composable
fun DesignSystemStartScreen(
onNextButtonClicked: (String) -> Unit,
onButtonClicked: (String) -> Unit,
modifier: Modifier = Modifier
) {
LazyColumn (
Expand All @@ -27,7 +27,7 @@ fun DesignSystemStartScreen(
DesignSystemDataSource.startScreenButtonOptions.forEach { item ->
SelectOptionButton(
labelResourceId = item.first,
onClick = { onNextButtonClicked(item.second) }
onClick = { onButtonClicked(item.second) }
)
}
}
Expand All @@ -38,7 +38,7 @@ fun DesignSystemStartScreen(
@Composable
fun StartDesignSystemStartScreenPreview(){
DesignSystemStartScreen(
onNextButtonClicked = {},
onButtonClicked = {},
modifier = Modifier
.fillMaxSize()
.padding(dimensionResource(R.dimen.button_container_shadow_height))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.wordpress.android.designsystem

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProvideTextStyle
import androidx.compose.material3.Surface
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color

private val localColors = staticCompositionLocalOf { extraPaletteLight }

@Composable
fun DesignSystemTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
DesignSystemThemeWithoutBackground(isDarkTheme) {
ContentInSurface(content)
}
}

@Composable
fun DesignSystemThemeWithoutBackground(
isDarkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val extraColors = if (isDarkTheme) {
extraPaletteDark
} else {
extraPaletteLight
}

CompositionLocalProvider (localColors provides extraColors) {
MaterialTheme(
colorScheme = if (isDarkTheme) paletteDarkScheme else paletteLightScheme,
content = content
)
}
}
private val paletteLightScheme = lightColorScheme(
primary = DesignSystemAppColor.Black,
primaryContainer = DesignSystemAppColor.White,
secondary = DesignSystemAppColor.Gray40,
secondaryContainer = DesignSystemAppColor.Gray,
tertiary = DesignSystemAppColor.Gray50,
tertiaryContainer = DesignSystemAppColor.Gray10,
error = DesignSystemAppColor.Red,
)

private val paletteDarkScheme = darkColorScheme(
primary = DesignSystemAppColor.White,
primaryContainer = DesignSystemAppColor.Black,
secondary = DesignSystemAppColor.Gray20,
secondaryContainer = DesignSystemAppColor.Gray70,
tertiary = DesignSystemAppColor.Gray10,
tertiaryContainer = DesignSystemAppColor.Gray80,
error = DesignSystemAppColor.Red10,
)

private val extraPaletteLight = ExtraColors(
quartenaryContainer = DesignSystemAppColor.Gray30,
brand = DesignSystemAppColor.Green,
brandContainer = DesignSystemAppColor.Green,
warning = DesignSystemAppColor.Orange,
wp = DesignSystemAppColor.Blue,
wpContainer = DesignSystemAppColor.Blue
)

private val extraPaletteDark = ExtraColors(
quartenaryContainer = DesignSystemAppColor.Gray60,
brand = DesignSystemAppColor.Green10,
brandContainer = DesignSystemAppColor.Green20,
warning = DesignSystemAppColor.Orange10,
wp = DesignSystemAppColor.Blue10,
wpContainer = DesignSystemAppColor.Blue20
)

data class ExtraColors(
val quartenaryContainer: Color,
val brand: Color,
val brandContainer: Color,
val warning: Color,
val wp: Color,
val wpContainer: Color,
)
@Suppress("UnusedReceiverParameter")
val ColorScheme.quartenary
@Composable
@ReadOnlyComposable
get() = localColors.current.quartenaryContainer

@Suppress("UnusedReceiverParameter")
val ColorScheme.brand
@Composable
@ReadOnlyComposable
get() = localColors.current.brand

@Suppress("UnusedReceiverParameter")
val ColorScheme.brandContainer
@Composable
@ReadOnlyComposable
get() = localColors.current.brandContainer

@Suppress("UnusedReceiverParameter")
val ColorScheme.warning
@Composable
@ReadOnlyComposable
get() = localColors.current.warning

@Suppress("UnusedReceiverParameter")
val ColorScheme.wp
@Composable
@ReadOnlyComposable
get() = localColors.current.wp

@Suppress("UnusedReceiverParameter")
val ColorScheme.wpContainer
@Composable
@ReadOnlyComposable
get() = localColors.current.wpContainer

@Composable
private fun ContentInSurface(
content: @Composable () -> Unit
) {
Surface(color = MaterialTheme.colorScheme.background) {
ProvideTextStyle(value = MaterialTheme.typography.bodyMedium) {
content()
}
}
}

0 comments on commit dd1d1e9

Please sign in to comment.