Skip to content

Commit

Permalink
디자인시스템 color / typography 기반 잡기 (#32)
Browse files Browse the repository at this point in the history
* feat : declare DobeDobeColors

* feat : declare DobeDobeTypography

* feat : apply colors and typography to Theme

* refactor : lint

* refactor : line break
  • Loading branch information
nohjunh authored Jan 30, 2025
1 parent 70fe4be commit 1c0b3ed
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package com.chipichipi.dobedobe.core.designsystem.theme

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color

val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
@Immutable
class DobeDobeColors(isDarkTheme: Boolean = false) {
val gray50 = Color(0xFFF9FAFB)
val gray100 = Color(0xFFF3F4F6)
val gray200 = Color(0xFFE5E7EB)
val gray300 = Color(0xFFF0F5FC)
val gray400 = Color(0xFF9CA3AF)
val gray500 = Color(0xFF7A828C)
val gray600 = Color(0xFF5F6875)
val gray700 = Color(0xFF48505C)
val gray800 = Color(0xFF333945)
val gray900 = Color(0xFF262C36)

val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
val green1 = Color(0xFFD0BCFF)
val green2 = Color(0xFFD0BCFF)
val green3 = Color(0xFFD0BCFF)

val white = Color.White
val black = Color.Black

val red = Color(0xFFD0BCFF)
}

internal val LocalDobeDobeColors = staticCompositionLocalOf { DobeDobeColors() }
Original file line number Diff line number Diff line change
@@ -1,65 +1,45 @@
package com.chipichipi.dobedobe.core.designsystem.theme

import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext

private val DarkColorScheme =
darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80,
)

private val LightColorScheme =
lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40,
)

// TODO : change Light/Dark color
private val LightAndroidBackgroundTheme = BackgroundTheme(color = Color.White)
private val DarkAndroidBackgroundTheme = BackgroundTheme(color = Color.White)

object DobeDobeTheme {
val typography: DobeDobeTypography
@ReadOnlyComposable
@Composable
get() = LocalDobeDobeTypography.current

val colors: DobeDobeColors
@ReadOnlyComposable
@Composable
get() = LocalDobeDobeColors.current
}

@Composable
fun DobeDobeTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = true,
content: @Composable () -> Unit,
) {
val colorScheme =
when {
dynamicColor && supportsDynamicTheming() -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}

darkTheme -> DarkColorScheme
else -> LightColorScheme
}

val backgroundTheme = if (darkTheme) DarkAndroidBackgroundTheme else LightAndroidBackgroundTheme
val typography = remember { DobeDobeTypography() }
val colors = remember { DobeDobeColors(darkTheme) }

CompositionLocalProvider(
LocalBackgroundTheme provides backgroundTheme,
LocalDobeDobeTypography provides typography,
LocalDobeDobeColors provides colors,
) {
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content,
)
}
}

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
private fun supportsDynamicTheming() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
Original file line number Diff line number Diff line change
@@ -1,36 +1,100 @@
package com.chipichipi.dobedobe.core.designsystem.theme

import androidx.compose.material3.Typography
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp

// Set of Material typography styles to start with
val Typography =
Typography(
bodyLarge =
TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp,
),
/* Other default text styles to override
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
*/
@Immutable
data class DobeDobeTypography internal constructor(
val title1: TextStyle,
val title2: TextStyle,
val heading1: TextStyle,
val heading2: TextStyle,
val body1: TextStyle,
val body2: TextStyle,
val body3: TextStyle,
val caption1: TextStyle,
val caption2: TextStyle,
) {
constructor(
systemFontFamily: FontFamily = FontFamily.Default,
title1: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Bold,
fontSize = 28.sp,
lineHeight = 42.sp,
letterSpacing = -(0.504).sp,
),
title2: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
lineHeight = 36.sp,
letterSpacing = -(0.432).sp,
),
heading1: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.SemiBold,
fontSize = 22.sp,
lineHeight = 33.sp,
letterSpacing = -(0.396).sp,
),
heading2: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.SemiBold,
fontSize = 17.sp,
lineHeight = 25.5.sp,
letterSpacing = -(0.306).sp,
),
body1: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = -(0.288).sp,
),
body2: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 15.sp,
lineHeight = 22.5.sp,
letterSpacing = -(0.27).sp,
),
body3: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
lineHeight = 21.sp,
letterSpacing = -(0.252).sp,
),
caption1: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
lineHeight = 18.sp,
letterSpacing = -(0.216).sp,
),
caption2: TextStyle = TextStyle(
fontFamily = systemFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 10.sp,
lineHeight = 15.sp,
letterSpacing = -(0.18).sp,
),
) : this(
title1 = title1,
title2 = title2,
heading1 = heading1,
heading2 = heading2,
body1 = body1,
body2 = body2,
body3 = body3,
caption1 = caption1,
caption2 = caption2,
)
}

internal val LocalDobeDobeTypography = staticCompositionLocalOf { DobeDobeTypography() }

0 comments on commit 1c0b3ed

Please sign in to comment.