|
| 1 | +package com.into.websoso.designsystem.theme |
| 2 | + |
| 3 | +import androidx.compose.runtime.Composable |
| 4 | +import androidx.compose.runtime.Stable |
| 5 | +import androidx.compose.runtime.getValue |
| 6 | +import androidx.compose.runtime.mutableStateOf |
| 7 | +import androidx.compose.runtime.setValue |
| 8 | +import androidx.compose.ui.platform.LocalDensity |
| 9 | +import androidx.compose.ui.text.TextStyle |
| 10 | +import androidx.compose.ui.text.font.Font |
| 11 | +import androidx.compose.ui.text.font.FontFamily |
| 12 | +import androidx.compose.ui.text.font.FontWeight |
| 13 | +import androidx.compose.ui.unit.Dp |
| 14 | +import androidx.compose.ui.unit.dp |
| 15 | +import com.into.websoso.R |
| 16 | + |
| 17 | +val PretendardBold = FontFamily(Font(R.font.pretendard_bold, FontWeight.Bold)) |
| 18 | +val PretendardSemiBold = FontFamily(Font(R.font.pretendard_semibold, FontWeight.SemiBold)) |
| 19 | +val PretendardMedium = FontFamily(Font(R.font.pretendard_medium, FontWeight.Medium)) |
| 20 | +val PretendardRegular = FontFamily(Font(R.font.pretendard_regular, FontWeight.Normal)) |
| 21 | + |
| 22 | +@Stable |
| 23 | +class WebsosoTypography internal constructor( |
| 24 | + headline: TextStyle, |
| 25 | + title1: TextStyle, |
| 26 | + title2: TextStyle, |
| 27 | + body1: TextStyle, |
| 28 | + body2: TextStyle, |
| 29 | + body3: TextStyle, |
| 30 | + caption: TextStyle, |
| 31 | + button: TextStyle, |
| 32 | + label: TextStyle, |
| 33 | +) { |
| 34 | + var headline: TextStyle by mutableStateOf(headline) |
| 35 | + private set |
| 36 | + var title1: TextStyle by mutableStateOf(title1) |
| 37 | + private set |
| 38 | + var title2: TextStyle by mutableStateOf(title2) |
| 39 | + private set |
| 40 | + var body1: TextStyle by mutableStateOf(body1) |
| 41 | + private set |
| 42 | + var body2: TextStyle by mutableStateOf(body2) |
| 43 | + private set |
| 44 | + var body3: TextStyle by mutableStateOf(body3) |
| 45 | + private set |
| 46 | + var caption: TextStyle by mutableStateOf(caption) |
| 47 | + private set |
| 48 | + var button: TextStyle by mutableStateOf(button) |
| 49 | + private set |
| 50 | + var label: TextStyle by mutableStateOf(label) |
| 51 | + private set |
| 52 | + |
| 53 | + fun copy( |
| 54 | + headline: TextStyle = this.headline, |
| 55 | + title1: TextStyle = this.title1, |
| 56 | + title2: TextStyle = this.title2, |
| 57 | + body1: TextStyle = this.body1, |
| 58 | + body2: TextStyle = this.body2, |
| 59 | + body3: TextStyle = this.body3, |
| 60 | + caption: TextStyle = this.caption, |
| 61 | + button: TextStyle = this.button, |
| 62 | + label: TextStyle = this.label, |
| 63 | + ): WebsosoTypography = WebsosoTypography( |
| 64 | + headline, |
| 65 | + title1, |
| 66 | + title2, |
| 67 | + body1, |
| 68 | + body2, |
| 69 | + body3, |
| 70 | + caption, |
| 71 | + button, |
| 72 | + label, |
| 73 | + ) |
| 74 | + |
| 75 | + fun update(other: WebsosoTypography) { |
| 76 | + headline = other.headline |
| 77 | + title1 = other.title1 |
| 78 | + title2 = other.title2 |
| 79 | + body1 = other.body1 |
| 80 | + body2 = other.body2 |
| 81 | + body3 = other.body3 |
| 82 | + caption = other.caption |
| 83 | + button = other.button |
| 84 | + label = other.label |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +@Composable |
| 89 | +fun websosoTypography(): WebsosoTypography { |
| 90 | + val density = LocalDensity.current |
| 91 | + |
| 92 | + fun textStyle( |
| 93 | + fontFamily: FontFamily, |
| 94 | + fontWeight: FontWeight, |
| 95 | + fontSizeDp: Dp, |
| 96 | + lineHeightDp: Dp, |
| 97 | + ): TextStyle { |
| 98 | + return TextStyle( |
| 99 | + fontFamily = fontFamily, |
| 100 | + fontWeight = fontWeight, |
| 101 | + fontSize = with(density) { fontSizeDp.toSp() }, |
| 102 | + lineHeight = with(density) { lineHeightDp.toSp() }, |
| 103 | + ) |
| 104 | + } |
| 105 | + |
| 106 | + return WebsosoTypography( |
| 107 | + headline = textStyle(PretendardBold, FontWeight.Bold, 24.dp, 32.dp), |
| 108 | + title1 = textStyle(PretendardSemiBold, FontWeight.SemiBold, 20.dp, 28.dp), |
| 109 | + title2 = textStyle(PretendardMedium, FontWeight.Medium, 18.dp, 25.dp), |
| 110 | + body1 = textStyle(PretendardRegular, FontWeight.Normal, 16.dp, 24.dp), |
| 111 | + body2 = textStyle(PretendardRegular, FontWeight.Normal, 14.dp, 21.dp), |
| 112 | + body3 = textStyle(PretendardRegular, FontWeight.Normal, 12.dp, 18.dp), |
| 113 | + caption = textStyle(PretendardRegular, FontWeight.Normal, 10.dp, 15.dp), |
| 114 | + button = textStyle(PretendardBold, FontWeight.Bold, 14.dp, 20.dp), |
| 115 | + label = textStyle(PretendardSemiBold, FontWeight.SemiBold, 13.dp, 19.dp), |
| 116 | + ) |
| 117 | +} |
0 commit comments