diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..a7c44570 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +max_line_length = 150 + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/YdsTheme.kt b/compose/src/main/java/com/yourssu/design/system/compose/YdsTheme.kt index 2f58692b..fa1afc7c 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/YdsTheme.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/YdsTheme.kt @@ -1,26 +1,21 @@ package com.yourssu.design.system.compose import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material.Shapes import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.ReadOnlyComposable +import com.yourssu.design.system.compose.base.ProvideTextStyle +import com.yourssu.design.system.compose.foundation.LocalContentColor import com.yourssu.design.system.compose.foundation.LocalYdsColorScheme import com.yourssu.design.system.compose.foundation.LocalYdsTypography -import com.yourssu.design.system.compose.rule.Border -import com.yourssu.design.system.compose.rule.LocalYdsBorder import com.yourssu.design.system.compose.foundation.YdsColorScheme import com.yourssu.design.system.compose.foundation.YdsTypography import com.yourssu.design.system.compose.foundation.darkColorScheme -import com.yourssu.design.system.compose.foundation.getYDSTypography import com.yourssu.design.system.compose.foundation.lightColorScheme -import com.yourssu.design.system.compose.rule.LocalYdsRounding @Composable fun YdsTheme( - typography: YdsTypography = getYDSTypography(), - rounding: Shapes = YdsTheme.rounding, - border: Border = YdsTheme.border, + typography: YdsTypography = YdsTheme.typography, content: @Composable () -> Unit ) { val colors = if (isSystemInDarkTheme()) { @@ -31,10 +26,12 @@ fun YdsTheme( CompositionLocalProvider( LocalYdsColorScheme provides colors, LocalYdsTypography provides typography, - LocalYdsRounding provides rounding, - LocalYdsBorder provides border, - content = content - ) + LocalContentColor provides colors.textPrimary, + ) { + ProvideTextStyle(value = typography.body1) { + content() + } + } } object YdsTheme { @@ -47,14 +44,4 @@ object YdsTheme { @Composable @ReadOnlyComposable get() = LocalYdsTypography.current - - val rounding: Shapes - @Composable - @ReadOnlyComposable - get() = LocalYdsRounding.current - - val border: Border - @Composable - @ReadOnlyComposable - get() = LocalYdsBorder.current } \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/Badge.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/Badge.kt index 512b313a..91a79c26 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/Badge.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/Badge.kt @@ -1,19 +1,29 @@ package com.yourssu.design.system.compose.atom import androidx.annotation.DrawableRes -import androidx.compose.foundation.layout.* -import androidx.compose.material.Surface -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.requiredHeight +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.R import com.yourssu.design.system.compose.YdsTheme -import com.yourssu.design.system.compose.foundation.IconSize -import com.yourssu.design.system.compose.foundation.ItemColor -import com.yourssu.design.system.compose.foundation.YdsIcon +import com.yourssu.design.system.compose.base.Icon +import com.yourssu.design.system.compose.base.IconSize +import com.yourssu.design.system.compose.base.Surface +import com.yourssu.design.system.compose.base.YdsText +import com.yourssu.design.system.compose.rule.ItemColor @Composable fun Badge( @@ -26,8 +36,8 @@ fun Badge( modifier = modifier .requiredHeight(24.dp) .wrapContentWidth(), - shape = YdsTheme.rounding.small, - color = itemColor.getSemanticColor(), + rounding = 2.dp, + color = itemColor.semanticColor, contentColor = YdsTheme.colors.monoItemText ) { Row( @@ -36,13 +46,13 @@ fun Badge( verticalAlignment = Alignment.CenterVertically ) { icon?.let { iconId -> - YdsIcon( + Icon( id = iconId, iconSize = IconSize.ExtraSmall ) Spacer(Modifier.width(4.dp)) } - Text(text = text, style = YdsTheme.typography.caption1) + YdsText(text = text, style = YdsTheme.typography.caption1) } } } diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/BottomSheet.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/BottomSheet.kt index 038666f7..43df96e3 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/BottomSheet.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/BottomSheet.kt @@ -12,8 +12,8 @@ import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.YdsTheme -import com.yourssu.design.system.compose.foundation.Duration -import com.yourssu.design.system.compose.foundation.YdsInAndOutEasing +import com.yourssu.design.system.compose.rule.Duration +import com.yourssu.design.system.compose.rule.YdsInAndOutEasing import kotlinx.coroutines.launch @OptIn(ExperimentalMaterialApi::class) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/BoxButton.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/BoxButton.kt index 66a4d384..33ad6ade 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/BoxButton.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/BoxButton.kt @@ -2,21 +2,28 @@ package com.yourssu.design.system.compose.atom import androidx.annotation.DrawableRes import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.shape.CornerBasedShape -import androidx.compose.material.ButtonDefaults.elevation -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.R import com.yourssu.design.system.compose.YdsTheme -import com.yourssu.design.system.compose.base.NoRippleButton -import com.yourssu.design.system.compose.foundation.IconSize -import com.yourssu.design.system.compose.foundation.YdsIcon -import com.yourssu.design.system.compose.states.ButtonSizeState +import com.yourssu.design.system.compose.base.Icon +import com.yourssu.design.system.compose.base.IconSize +import com.yourssu.design.system.compose.base.YdsBaseButton +import com.yourssu.design.system.compose.base.YdsText import com.yourssu.design.system.compose.states.ButtonColorState +import com.yourssu.design.system.compose.states.ButtonSizeState enum class BoxButtonType { Filled, @@ -107,17 +114,17 @@ fun BoxButton( isWarned: Boolean = false, sizeType: BoxButtonSize = BoxButtonSize.Large, buttonType: BoxButtonType = BoxButtonType.Filled, - rounding: CornerBasedShape = YdsTheme.rounding.large, + rounding: Dp = 8.dp, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() } ) { - val roundingShape = when (sizeType) { - BoxButtonSize.ExtraLarge -> YdsTheme.rounding.large + val roundingDp = when (sizeType) { + BoxButtonSize.ExtraLarge -> 8.dp BoxButtonSize.Large -> rounding - BoxButtonSize.Medium, BoxButtonSize.Small -> YdsTheme.rounding.medium + BoxButtonSize.Medium, BoxButtonSize.Small -> 4.dp } val (typo, iconSize, height, horizontalPadding) = boxButtonSizeStateBySize(size = sizeType) - NoRippleButton( + YdsBaseButton( onClick = onClick, colors = boxButtonColorByType(isWarned = isWarned, type = buttonType), modifier = Modifier @@ -125,22 +132,21 @@ fun BoxButton( .height(height), enabled = !isDisabled, showBorder = (buttonType == BoxButtonType.Line), - elevation = elevation(0.dp, 0.dp, 0.dp), interactionSource = interactionSource, - shape = roundingShape, + rounding = roundingDp, contentPadding = PaddingValues( horizontal = horizontalPadding ) ) { leftIcon?.let { icon -> - YdsIcon( + Icon( id = icon, iconSize = iconSize ) Spacer(modifier = Modifier.width(4.dp)) } - Text( + YdsText( text = text, style = typo ) @@ -148,7 +154,7 @@ fun BoxButton( // leftIcon이 null일 때만 leftIcon ?: rightIcon?.let { icon -> Spacer(modifier = Modifier.width(4.dp)) - YdsIcon( + Icon( id = icon, iconSize = iconSize ) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/CheckBox.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/CheckBox.kt index f6a9cce5..027a9d81 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/CheckBox.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/CheckBox.kt @@ -1,9 +1,17 @@ package com.yourssu.design.system.compose.atom import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -11,9 +19,10 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.R import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.base.IconSize +import com.yourssu.design.system.compose.base.YdsText +import com.yourssu.design.system.compose.base.Icon import com.yourssu.design.system.compose.base.noRippleClickable -import com.yourssu.design.system.compose.foundation.IconSize -import com.yourssu.design.system.compose.foundation.YdsIcon import com.yourssu.design.system.compose.states.ButtonSizeState enum class CheckBoxSize { @@ -83,7 +92,7 @@ fun CheckBox( .then(clickableModifier), verticalAlignment = Alignment.CenterVertically ) { - YdsIcon( + Icon( id = icon, iconSize = iconSize, tint = contentColor @@ -91,7 +100,7 @@ fun CheckBox( Spacer(Modifier.width(betweenSpace)) - Text( + YdsText( text = text, style = typo, color = contentColor diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/Divider.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/Divider.kt index a639ba50..ad2657bb 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/Divider.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/Divider.kt @@ -1,14 +1,25 @@ package com.yourssu.design.system.compose.atom import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* -import androidx.compose.material.Text +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.IntrinsicSize +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.base.YdsText import com.yourssu.design.system.compose.rule.YdsBorder enum class Direction { @@ -16,15 +27,39 @@ enum class Direction { } enum class Thickness(val value: Dp) { - Thin(YdsBorder.thin), - Thick(YdsBorder.thick) + Thin(YdsBorder.Thin.dp), + Thick(YdsBorder.Thick.dp) +} + +@Composable +fun RowScope.Divider( + thickness: Thickness, + modifier: Modifier = Modifier, +) { + Divider( + direction = Direction.Vertical, + thickness = thickness, + modifier = modifier, + ) +} + +@Composable +fun ColumnScope.Divider( + thickness: Thickness, + modifier: Modifier = Modifier, +) { + Divider( + direction = Direction.Horizontal, + thickness = thickness, + modifier = modifier, + ) } @Composable fun Divider( direction: Direction, thickness: Thickness, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { Box( modifier = Modifier @@ -33,48 +68,43 @@ fun Divider( color = when (thickness) { Thickness.Thin -> YdsTheme.colors.borderNormal Thickness.Thick -> YdsTheme.colors.borderThin - } + }, ) .then( when (direction) { Direction.Horizontal -> Modifier .fillMaxWidth() .height(thickness.value) + Direction.Vertical -> Modifier .fillMaxHeight() .width(thickness.value) - } - ) + }, + ), ) } -@Preview(showBackground = true) +@Preview(showBackground = true, backgroundColor = 0xFFFFFF) @Composable fun DividerPreview() { YdsTheme { Column(modifier = Modifier.height(IntrinsicSize.Min)) { - Text(text = "one") - Text(text = "two") - Divider( - direction = Direction.Horizontal, - thickness = Thickness.Thick - ) - Text(text = "three") + YdsText(text = "one") + YdsText(text = "two") + Divider(thickness = Thickness.Thick) + YdsText(text = "three") Spacer(Modifier.height(8.dp)) Row(modifier = Modifier.height(IntrinsicSize.Min)) { - Text( + YdsText( text = "abcd", - modifier = Modifier.padding(end = 8.dp) - ) - Divider( - direction = Direction.Vertical, - thickness = Thickness.Thin + modifier = Modifier.padding(end = 8.dp), ) - Text( + Divider(thickness = Thickness.Thin) + YdsText( text = "efgh", - modifier = Modifier.padding(start = 8.dp) + modifier = Modifier.padding(start = 8.dp), ) } } diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/ListItem.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/ListItem.kt index 683edbb6..afdab3ff 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/ListItem.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/ListItem.kt @@ -4,9 +4,16 @@ import androidx.annotation.DrawableRes import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsPressedAsState -import androidx.compose.foundation.layout.* -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -14,7 +21,8 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.R import com.yourssu.design.system.compose.YdsTheme -import com.yourssu.design.system.compose.foundation.YdsIcon +import com.yourssu.design.system.compose.base.YdsText +import com.yourssu.design.system.compose.base.Icon import com.yourssu.design.system.compose.base.noRippleClickable @Composable @@ -50,11 +58,11 @@ fun ListItem( Spacer(Modifier.width(20.dp)) leftIcon?.let { icon -> - YdsIcon(id = icon, tint = YdsTheme.colors.buttonNormal) + Icon(id = icon, tint = YdsTheme.colors.buttonNormal) Spacer(Modifier.width(8.dp)) } - Text( + YdsText( text = text, modifier = Modifier.weight(1.0f), style = YdsTheme.typography.body1, @@ -63,7 +71,7 @@ fun ListItem( rightIcon?.let { icon -> Spacer(Modifier.width(8.dp)) - YdsIcon(id = icon, tint = YdsTheme.colors.buttonNormal) + Icon(id = icon, tint = YdsTheme.colors.buttonNormal) } Spacer(Modifier.width(20.dp)) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/ListToggleItem.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/ListToggleItem.kt index b0aaa2ff..81072ea3 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/ListToggleItem.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/ListToggleItem.kt @@ -1,14 +1,24 @@ package com.yourssu.design.system.compose.atom import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.base.YdsText @Composable fun ListToggleItem( @@ -28,7 +38,7 @@ fun ListToggleItem( ) { Spacer(Modifier.width(20.dp)) - Text( + YdsText( text = text, modifier = Modifier.weight(1f), style = YdsTheme.typography.body1 diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/Picker.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/Picker.kt index 58972ed0..422b03ec 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/Picker.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/Picker.kt @@ -1,12 +1,19 @@ package com.yourssu.design.system.compose.atom import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalDensity @@ -14,6 +21,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.base.YdsText @Composable fun Picker( @@ -28,9 +36,8 @@ fun Picker( onSecondItemChange: ((index: Int) -> Unit)? = null, onThirdItemChange: ((index: Int) -> Unit)? = null, ) { - val itemHeightDp: Dp = with(LocalDensity.current) { - YdsTheme.typography.body1.lineHeight.toDp() - } + val itemHeightDp: Dp = YdsTheme.typography.body1.lineHeight + val totalItemHeightDp = itemHeightDp + 4.dp * 2 // 위 아래 패딩 4dp val itemLists = listOf(firstItemList, secondItemList, thirdItemList) @@ -140,7 +147,7 @@ private fun PickerItem( vertical = 4.dp ) ) { - Text( + YdsText( text = text, style = YdsTheme.typography.body1, color = if (showed) { diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/PlainButton.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/PlainButton.kt index fd1c2fe9..b201479e 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/PlainButton.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/PlainButton.kt @@ -2,19 +2,24 @@ package com.yourssu.design.system.compose.atom import androidx.annotation.DrawableRes import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.ButtonDefaults.elevation -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.R import com.yourssu.design.system.compose.YdsTheme -import com.yourssu.design.system.compose.base.NoRippleButton -import com.yourssu.design.system.compose.foundation.IconSize -import com.yourssu.design.system.compose.foundation.YdsIcon +import com.yourssu.design.system.compose.base.IconSize +import com.yourssu.design.system.compose.base.YdsText +import com.yourssu.design.system.compose.base.YdsBaseButton +import com.yourssu.design.system.compose.base.Icon import com.yourssu.design.system.compose.states.ButtonColorState import com.yourssu.design.system.compose.states.ButtonSizeState @@ -67,12 +72,11 @@ fun PlainButton( val typo = sizeState.typo val iconSize = sizeState.iconSize - NoRippleButton( + YdsBaseButton( onClick = onClick, modifier = modifier, enabled = !isDisabled, colors = plainButtonColor(isWarned = isWarned, isPointed = isPointed), - elevation = elevation(0.dp, 0.dp, 0.dp), interactionSource = interactionSource, contentPadding = PaddingValues(0.dp) ) { @@ -80,23 +84,21 @@ fun PlainButton( // sizeType이 Large일 때는 아이콘만 val iconRes = leftIcon ?: rightIcon - require(iconRes != null) { - "Large 버튼은 아이콘이 지정되어야 합니다." - } - YdsIcon( + require(iconRes != null) { "Large 버튼은 아이콘이 지정되어야 합니다." } + Icon( id = iconRes, iconSize = iconSize ) } else { leftIcon?.let { icon -> - YdsIcon( + Icon( id = icon, iconSize = iconSize ) Spacer(modifier = Modifier.width(2.dp)) } - Text( + YdsText( text = text, style = typo ) @@ -104,7 +106,7 @@ fun PlainButton( if (leftIcon == null) { rightIcon?.let { icon -> Spacer(modifier = Modifier.width(2.dp)) - YdsIcon( + Icon( id = icon, iconSize = iconSize ) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/ProfileImageView.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/ProfileImageView.kt index 3e7a9b11..aba9d138 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/ProfileImageView.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/ProfileImageView.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.R import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.rule.YdsBorder class SquircleShape : Shape { override fun createOutline( @@ -108,7 +109,7 @@ fun ProfileImageView( .size(size.value) .clip(SquircleShape()) .border( - width = YdsTheme.border.normal, + width = YdsBorder.Normal.dp, color = YdsTheme.colors.borderNormal, shape = SquircleShape() ) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/atom/Toggle.kt b/compose/src/main/java/com/yourssu/design/system/compose/atom/Toggle.kt index 74fab40e..236f9dec 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/atom/Toggle.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/atom/Toggle.kt @@ -1,14 +1,23 @@ package com.yourssu.design.system.compose.atom import androidx.compose.animation.animateColor -import androidx.compose.animation.core.* +import androidx.compose.animation.core.animateDp +import androidx.compose.animation.core.tween +import androidx.compose.animation.core.updateTransition import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.offset +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -16,7 +25,8 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.yourssu.design.system.compose.YdsTheme import com.yourssu.design.system.compose.base.noRippleClickable -import com.yourssu.design.system.compose.foundation.YdsInAndOutEasing +import com.yourssu.design.system.compose.rule.YdsInAndOutEasing +import com.yourssu.design.system.compose.rule.YdsBorder @Composable fun Toggle( @@ -66,7 +76,7 @@ fun Toggle( else YdsTheme.colors.buttonBright ) .border( - width = YdsTheme.border.thin, + width = YdsBorder.Thin.dp, color = YdsTheme.colors.borderNormal, shape = CircleShape ) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/base/Icon.kt b/compose/src/main/java/com/yourssu/design/system/compose/base/Icon.kt new file mode 100644 index 00000000..7a4ab499 --- /dev/null +++ b/compose/src/main/java/com/yourssu/design/system/compose/base/Icon.kt @@ -0,0 +1,76 @@ +package com.yourssu.design.system.compose.base + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.paint +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.graphics.toolingGraphicsLayer +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.yourssu.design.system.compose.foundation.LocalContentColor + +sealed class IconSize(val value: Dp) { + object ExtraSmall : IconSize(16.dp) + object Small : IconSize(20.dp) + object Medium : IconSize(24.dp) + object Large : IconSize(48.dp) +} + +@Composable +fun Icon( + @DrawableRes id: Int, + modifier: Modifier = Modifier, + iconSize: IconSize = IconSize.Medium, + tint: Color = LocalContentColor.current, +) { + Icon( + imageVector = ImageVector.vectorResource(id = id), + modifier = modifier, + iconSize = iconSize, + tint = tint + ) +} + +@Composable +fun Icon( + imageVector: ImageVector, + modifier: Modifier = Modifier, + iconSize: IconSize = IconSize.Medium, + tint: Color = LocalContentColor.current, +) { + Icon( + painter = rememberVectorPainter(imageVector), + modifier = modifier, + iconSize = iconSize, + tint = tint + ) +} + +@Composable +fun Icon( + painter: Painter, + modifier: Modifier = Modifier, + iconSize: IconSize = IconSize.Medium, + tint: Color = LocalContentColor.current, +) { + val colorFilter = ColorFilter.tint(tint) + Box( + modifier + .toolingGraphicsLayer() + .size(iconSize.value) + .paint( + painter = painter, + colorFilter = colorFilter, + contentScale = ContentScale.Fit + ) + ) +} diff --git a/compose/src/main/java/com/yourssu/design/system/compose/base/NoRippleButton.kt b/compose/src/main/java/com/yourssu/design/system/compose/base/NoRippleButton.kt deleted file mode 100644 index c522453f..00000000 --- a/compose/src/main/java/com/yourssu/design/system/compose/base/NoRippleButton.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.yourssu.design.system.compose.base - -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.* -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.unit.dp -import com.yourssu.design.system.compose.YdsTheme -import com.yourssu.design.system.compose.states.ButtonColorState - -@Composable -fun NoRippleButton( - onClick: () -> Unit, - colors: ButtonColorState, - modifier: Modifier = Modifier, - enabled: Boolean = true, - showBorder: Boolean = false, - interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, - elevation: ButtonElevation? = ButtonDefaults.elevation(), - shape: Shape = MaterialTheme.shapes.small, - contentPadding: PaddingValues = ButtonDefaults.ContentPadding, - content: @Composable RowScope.() -> Unit -) { - val contentColor by colors.contentColor(enabled, interactionSource) - Surface( - modifier = modifier - .noRippleClickable(interactionSource, onClick = onClick), - shape = shape, - color = colors.backgroundColor(enabled, interactionSource).value, - contentColor = contentColor, - border = if (showBorder) BorderStroke( - YdsTheme.border.normal, - contentColor - ) else null, - elevation = elevation?.elevation(enabled, interactionSource)?.value ?: 0.dp, - ) { - CompositionLocalProvider(LocalContentAlpha provides contentColor.alpha) { - ProvideTextStyle(value = MaterialTheme.typography.button) { - Row( - modifier = Modifier - .defaultMinSize( - minWidth = ButtonDefaults.MinWidth, - minHeight = ButtonDefaults.MinHeight - ) - .padding(contentPadding), - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically, - content = content - ) - } - } - } -} \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/base/Surface.kt b/compose/src/main/java/com/yourssu/design/system/compose/base/Surface.kt new file mode 100644 index 00000000..6f5c559d --- /dev/null +++ b/compose/src/main/java/com/yourssu/design/system/compose/base/Surface.kt @@ -0,0 +1,103 @@ +package com.yourssu.design.system.compose.base + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.semantics.isContainer +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.Dp +import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.foundation.LocalContentColor + +@Composable +fun Surface( + modifier: Modifier = Modifier, + rounding: Dp? = null, + shape: Shape = rounding?.let { RoundedCornerShape(it) } ?: RectangleShape, + color: Color = YdsTheme.colors.bgNormal, + contentColor: Color = LocalContentColor.current, + border: BorderStroke? = null, + content: @Composable () -> Unit, +) { + CompositionLocalProvider( + LocalContentColor provides contentColor, + ) { + Box( + modifier = modifier + .surface( + shape = shape, + backgroundColor = color, + border = border, + ) + .semantics { isContainer = true } + .pointerInput(Unit) {}, + propagateMinConstraints = true, + ) { + content() + } + } +} + + +/** + * todo: 설명 작성하기 + * + * Clickable Surface + */ +@Composable +fun Surface( + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + rounding: Dp? = null, + shape: Shape = rounding?.let { RoundedCornerShape(it) } ?: RectangleShape, + color: Color = YdsTheme.colors.bgNormal, + contentColor: Color = LocalContentColor.current, + border: BorderStroke? = null, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + content: @Composable () -> Unit, +) { + CompositionLocalProvider( + LocalContentColor provides contentColor, + ) { + Box( + modifier = modifier + .surface( + shape = shape, + backgroundColor = color, + border = border, + ) + .clickable( + interactionSource = interactionSource, + indication = null, + enabled = enabled, + onClick = onClick, + ), + propagateMinConstraints = true, + ) { + content() + } + } +} + +private fun Modifier.surface( + shape: Shape, + backgroundColor: Color, + border: BorderStroke?, +): Modifier = this + .then(if (border != null) Modifier.border(border, shape) else Modifier) + .background(color = backgroundColor, shape = shape) + .clip(shape) diff --git a/compose/src/main/java/com/yourssu/design/system/compose/base/YdsBaseButton.kt b/compose/src/main/java/com/yourssu/design/system/compose/base/YdsBaseButton.kt new file mode 100644 index 00000000..859a928b --- /dev/null +++ b/compose/src/main/java/com/yourssu/design/system/compose/base/YdsBaseButton.kt @@ -0,0 +1,84 @@ +package com.yourssu.design.system.compose.base + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsPressedAsState +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.defaultMinSize +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.yourssu.design.system.compose.YdsTheme +import com.yourssu.design.system.compose.rule.YdsBorder +import com.yourssu.design.system.compose.states.ButtonColorState + +/** + * (전) NoRippleButton + * + * BoxButton, PlainButton의 베이스가 되는, Ripple 효과가 없는 Composable 함수 입니다. + * + * @see com.yourssu.design.system.compose.atom.BoxButton + * @see com.yourssu.design.system.compose.atom.PlainButton + */ +@Composable +internal fun YdsBaseButton( + onClick: () -> Unit, + colors: ButtonColorState, + modifier: Modifier = Modifier, + enabled: Boolean = true, + showBorder: Boolean = false, + rounding: Dp = 8.dp, + contentPadding: PaddingValues = YdsButtonDefaults.ContentPadding, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + content: @Composable RowScope.() -> Unit +) { + val localPressed by interactionSource.collectIsPressedAsState() + val buttonColors = colors.apply { pressed = localPressed } + val contentColor by buttonColors.contentColor(enabled) + + Surface( + onClick = onClick, + modifier = modifier, + rounding = rounding, + color = buttonColors.backgroundColor(enabled).value, + contentColor = contentColor, + border = if (showBorder) BorderStroke(YdsBorder.Normal.dp, contentColor) else null, + interactionSource = interactionSource, + ) { + ProvideTextStyle(value = YdsTheme.typography.button2) { + Row( + modifier = Modifier + .defaultMinSize( + minWidth = YdsButtonDefaults.MinWidth, + minHeight = YdsButtonDefaults.MinHeight + ) + .padding(contentPadding), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically, + content = content + ) + } + } +} + +object YdsButtonDefaults { + private val ButtonHorizontalPadding = 16.dp + private val ButtonVerticalPadding = 12.dp + + val ContentPadding = PaddingValues( + horizontal = ButtonHorizontalPadding, + vertical = ButtonVerticalPadding + ) + + // YDS에 명시되어 있지 않아서 Material에서 가져옴 + val MinWidth = 64.dp + val MinHeight = 36.dp +} diff --git a/compose/src/main/java/com/yourssu/design/system/compose/base/YdsText.kt b/compose/src/main/java/com/yourssu/design/system/compose/base/YdsText.kt new file mode 100644 index 00000000..50599d81 --- /dev/null +++ b/compose/src/main/java/com/yourssu/design/system/compose/base/YdsText.kt @@ -0,0 +1,41 @@ +package com.yourssu.design.system.compose.base + +import androidx.compose.foundation.text.BasicText +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.compositionLocalOf +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.takeOrElse +import com.yourssu.design.system.compose.foundation.LocalContentColor +import com.yourssu.design.system.compose.foundation.YdsTextStyle + +@Composable +fun YdsText( + text: String, + modifier: Modifier = Modifier, + color: Color = Color.Unspecified, + style: YdsTextStyle = LocalTextStyle.current +) { + val textColor = color.takeOrElse { + style.color.takeOrElse { + LocalContentColor.current + } + } + + val mergedStyle = style.copy(color = textColor).toTextStyle() + + BasicText( + text = text, + modifier = modifier, + style = mergedStyle, + ) +} + +val LocalTextStyle = compositionLocalOf { YdsTextStyle.Default } + +@Composable +fun ProvideTextStyle(value: YdsTextStyle, content: @Composable () -> Unit) { + val mergedStyle = LocalTextStyle.current.merge(value) + CompositionLocalProvider(LocalTextStyle provides mergedStyle, content = content) +} diff --git a/compose/src/main/java/com/yourssu/design/system/compose/foundation/Icon.kt b/compose/src/main/java/com/yourssu/design/system/compose/foundation/Icon.kt deleted file mode 100644 index 5572adae..00000000 --- a/compose/src/main/java/com/yourssu/design/system/compose/foundation/Icon.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.yourssu.design.system.compose.foundation - -import androidx.annotation.DrawableRes -import androidx.compose.foundation.layout.size -import androidx.compose.material.Icon -import androidx.compose.material.LocalContentColor -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.res.vectorResource -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp - -sealed class IconSize(val value: Dp) { - object ExtraSmall : IconSize(16.dp) - object Small : IconSize(20.dp) - object Medium : IconSize(24.dp) - object Large : IconSize(48.dp) -} - -@Composable -fun YdsIcon( - @DrawableRes id: Int, - modifier: Modifier = Modifier, - iconSize: IconSize = IconSize.Medium, - tint: Color = LocalContentColor.current -) { - Icon( - imageVector = ImageVector.vectorResource(id = id), - contentDescription = "$id", - modifier = Modifier - .size(iconSize.value) - .then(modifier), - tint = tint - ) -} \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/foundation/ItemColor.kt b/compose/src/main/java/com/yourssu/design/system/compose/foundation/ItemColor.kt deleted file mode 100644 index 0870a4c9..00000000 --- a/compose/src/main/java/com/yourssu/design/system/compose/foundation/ItemColor.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.yourssu.design.system.compose.foundation - -import androidx.compose.runtime.Composable -import com.yourssu.design.system.compose.YdsTheme - -// 백엔드와의 동일한 컬러값 통신을 위해서 사용 -enum class ItemColor { - Mono, - Green, - Emerald, - Aqua, - Blue, - Indigo, - Violet, - Purple, - Pink; - - @Composable - fun getSemanticColor() = when (this) { - Mono -> YdsTheme.colors.monoItemBG - Green -> YdsTheme.colors.greenItemBG - Emerald -> YdsTheme.colors.emeraldItemBG - Aqua -> YdsTheme.colors.aquaItemBG - Blue -> YdsTheme.colors.blueItemBG - Indigo -> YdsTheme.colors.indigoItemBG - Violet -> YdsTheme.colors.violetItemBG - Purple -> YdsTheme.colors.purpleItemBG - Pink -> YdsTheme.colors.pinkItemBG - } -} \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/foundation/SemanticColors.kt b/compose/src/main/java/com/yourssu/design/system/compose/foundation/SemanticColors.kt index bbcd5ff9..b8c561ff 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/foundation/SemanticColors.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/foundation/SemanticColors.kt @@ -1,8 +1,12 @@ package com.yourssu.design.system.compose.foundation +import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color +import com.yourssu.design.system.compose.YdsTheme @Immutable data class YdsColorScheme( @@ -10,8 +14,8 @@ data class YdsColorScheme( val bgNormal: Color = White000, val bgElevated: Color = White000, val bgRecomment: Color = Gray050, - val bgSelected: Color = Gray100, - val bgPressed: Color = Gray100, + val bgSelected: Color = Gray900A5, + val bgPressed: Color = Gray900A5, val bgNormalDark: Color = RealBlack, val bgElevatedDark: Color = RealBlack, val bgDimDark: Color = Gray900A30, @@ -190,4 +194,18 @@ val darkColorScheme = YdsColorScheme( // 나머지 Item Color는 동일 ) -internal val LocalYdsColorScheme = staticCompositionLocalOf { lightColorScheme } \ No newline at end of file +@Composable +@ReadOnlyComposable +fun pressedColorFor(color: Color) = YdsTheme.colors.pressedColorFor(color) + +private fun YdsColorScheme.pressedColorFor(color: Color): Color { + return when (color) { + buttonNormal -> buttonNormalPressed + buttonPoint -> buttonPointPressed + buttonWarned -> buttonWarnedPressed + else -> color + } +} + +internal val LocalYdsColorScheme = staticCompositionLocalOf { lightColorScheme } +internal val LocalContentColor = compositionLocalOf { lightColorScheme.textPrimary } diff --git a/compose/src/main/java/com/yourssu/design/system/compose/foundation/Typography.kt b/compose/src/main/java/com/yourssu/design/system/compose/foundation/Typography.kt index 71e886fc..43ab790b 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/foundation/Typography.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/foundation/Typography.kt @@ -2,161 +2,159 @@ package com.yourssu.design.system.compose.foundation import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable +import androidx.compose.runtime.Stable import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.takeOrElse import com.yourssu.design.system.compose.R val fonts = FontFamily( Font(R.font.spoqa_han_sans_neo_regular, FontWeight.Normal), Font(R.font.spoqa_han_sans_neo_medium, FontWeight.Medium), - Font(R.font.spoqa_han_sans_neo_bold, FontWeight.Bold) + Font(R.font.spoqa_han_sans_neo_bold, FontWeight.Bold), ) +/** + * 폰트 사이즈를 Dp로 표현하기 위해 사용합니다. + * + * Text에 적용될 때는 `toTextStyle()`로 변환하여 사용됩니다. + * + * @see com.yourssu.design.system.compose.base.YdsText + */ @Immutable -data class YdsTypography( - val title1: TextStyle = TextStyle.Default, - val title2: TextStyle = TextStyle.Default, - val title3: TextStyle = TextStyle.Default, - val subTitle1: TextStyle = TextStyle.Default, - val subTitle2: TextStyle = TextStyle.Default, - val subTitle3: TextStyle = TextStyle.Default, - val body1: TextStyle = TextStyle.Default, - val body2: TextStyle = TextStyle.Default, - val button0: TextStyle = TextStyle.Default, - val button1: TextStyle = TextStyle.Default, - val button2: TextStyle = TextStyle.Default, - val button3: TextStyle = TextStyle.Default, - val button4: TextStyle = TextStyle.Default, - val caption0: TextStyle = TextStyle.Default, - val caption1: TextStyle = TextStyle.Default, - val caption2: TextStyle = TextStyle.Default, - val display1: TextStyle = TextStyle.Default, - val display2: TextStyle = TextStyle.Default, -) - -internal val LocalYdsTypography = staticCompositionLocalOf { YdsTypography() } +data class YdsTextStyle( + val fontFamily: FontFamily = fonts, + val fontWeight: FontWeight = FontWeight.Medium, + val fontSize: Dp = Dp.Unspecified, + val lineHeight: Dp = Dp.Unspecified, + val color: Color = Color.Unspecified, +) { + @Composable + fun toTextStyle() = TextStyle( + fontFamily = fontFamily, + fontWeight = fontWeight, + fontSize = with(LocalDensity.current) { fontSize.toSp() }, + lineHeight = with(LocalDensity.current) { lineHeight.toSp() }, + color = color, + ) -@Composable -fun getYDSTypography() = - YdsTypography( - title1 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 28.dp(), - lineHeight = 36.4f.dp() - ), - title2 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 24.dp(), - lineHeight = 31.2f.dp() - ), - title3 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 20.dp(), - lineHeight = 26.dp() - ), - subTitle1 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 20.dp(), - lineHeight = 26.dp() - ), - subTitle2 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 16.dp(), - lineHeight = 20.8f.dp() - ), - subTitle3 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 14.dp(), - lineHeight = 18.2f.dp() - ), - body1 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 15.dp(), - lineHeight = 22.5f.dp() - ), - body2 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 14.dp(), - lineHeight = 21f.dp() - ), - button0 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 16.dp(), - lineHeight = 22.4f.dp() - ), - button1 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 16.dp(), - lineHeight = 22.4f.dp() - ), - button2 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 14.dp(), - lineHeight = 18.2f.dp() - ), - button3 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 14.dp(), - lineHeight = 18.2f.dp() - ), - button4 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 12.dp(), - lineHeight = 16.8f.dp() - ), - caption0 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 12.dp(), - lineHeight = 15.6f.dp() - ), - caption1 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 12.dp(), - lineHeight = 15.6f.dp() - ), - caption2 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 11.dp(), - lineHeight = 14.3f.dp() - ), - display1 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 40.dp(), - lineHeight = 52.dp() - ), - display2 = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 32.dp(), - lineHeight = 41.6f.dp() + fun merge(other: YdsTextStyle?): YdsTextStyle { + if (other == null || other == Default) return this + return YdsTextStyle( + fontFamily = other.fontFamily, + fontWeight = other.fontWeight, + fontSize = this.fontSize.takeOrElse { other.fontSize }, + lineHeight = this.lineHeight.takeOrElse { other.lineHeight }, + color = this.color.takeOrElse { other.color } ) - ) + } + companion object { + @Stable + val Default = YdsTextStyle() + } +} -@Composable -fun Float.dp() = with(LocalDensity.current) { Dp(this@dp).toSp() } +@Immutable +data class YdsTypography( + val title1: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Bold, + fontSize = 28.dp, + lineHeight = 36.4f.dp, + ), + val title2: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Bold, + fontSize = 24.dp, + lineHeight = 31.2f.dp, + ), + val title3: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Bold, + fontSize = 20.dp, + lineHeight = 26.dp, + ), + val subTitle1: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 20.dp, + lineHeight = 26.dp, + ), + val subTitle2: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 16.dp, + lineHeight = 20.8f.dp, + ), + val subTitle3: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 14.dp, + lineHeight = 18.2f.dp, + ), + val body1: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Normal, + fontSize = 15.dp, + lineHeight = 22.5f.dp, + ), + val body2: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Normal, + fontSize = 14.dp, + lineHeight = 21f.dp, + ), + val button0: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 16.dp, + lineHeight = 22.4f.dp, + ), + val button1: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 16.dp, + lineHeight = 22.4f.dp, + ), + val button2: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 14.dp, + lineHeight = 18.2f.dp, + ), + val button3: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 14.dp, + lineHeight = 18.2f.dp, + ), + val button4: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 12.dp, + lineHeight = 16.8f.dp, + ), + val caption0: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 12.dp, + lineHeight = 15.6f.dp, + ), + val caption1: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 12.dp, + lineHeight = 15.6f.dp, + ), + val caption2: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Medium, + fontSize = 11.dp, + lineHeight = 14.3f.dp, + ), + val display1: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Bold, + fontSize = 40.dp, + lineHeight = 52.dp, + ), + val display2: YdsTextStyle = YdsTextStyle( + fontWeight = FontWeight.Bold, + fontSize = 32.dp, + lineHeight = 41.6f.dp, + ), +) -@Composable -fun Int.dp() = with(LocalDensity.current) { Dp(this@dp.toFloat()).toSp() } +internal val LocalYdsTypography = staticCompositionLocalOf { YdsTypography() } diff --git a/compose/src/main/java/com/yourssu/design/system/compose/foundation/Animation.kt b/compose/src/main/java/com/yourssu/design/system/compose/rule/Animation.kt similarity index 79% rename from compose/src/main/java/com/yourssu/design/system/compose/foundation/Animation.kt rename to compose/src/main/java/com/yourssu/design/system/compose/rule/Animation.kt index c6d27fd1..df35fb14 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/foundation/Animation.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/rule/Animation.kt @@ -1,4 +1,4 @@ -package com.yourssu.design.system.compose.foundation +package com.yourssu.design.system.compose.rule import androidx.compose.animation.core.CubicBezierEasing @@ -7,4 +7,4 @@ internal val YdsInAndOutEasing = CubicBezierEasing(0.25f, 0.1f, 0.25f, 1f) enum class Duration(val millis: Int) { Short(100), Medium(250) -} \ No newline at end of file +} diff --git a/compose/src/main/java/com/yourssu/design/system/compose/rule/Border.kt b/compose/src/main/java/com/yourssu/design/system/compose/rule/Border.kt deleted file mode 100644 index 7e314881..00000000 --- a/compose/src/main/java/com/yourssu/design/system/compose/rule/Border.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.yourssu.design.system.compose.rule - -import androidx.compose.runtime.staticCompositionLocalOf -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp - -internal val minBorderWidth = 0.34.dp -internal val normalBorderWidth = 1.dp -internal val thickBorderWidth = 8.dp - -data class Border( - val thin: Dp = minBorderWidth, - val normal: Dp = normalBorderWidth, - val thick: Dp = thickBorderWidth -) - -internal val YdsBorder = Border() - -internal val LocalYdsBorder = staticCompositionLocalOf { YdsBorder } \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/rule/ItemColor.kt b/compose/src/main/java/com/yourssu/design/system/compose/rule/ItemColor.kt new file mode 100644 index 00000000..e401f876 --- /dev/null +++ b/compose/src/main/java/com/yourssu/design/system/compose/rule/ItemColor.kt @@ -0,0 +1,30 @@ +package com.yourssu.design.system.compose.rule + +import androidx.compose.ui.graphics.Color +import com.yourssu.design.system.compose.foundation.lightColorScheme + +// 백엔드와의 동일한 컬러값 통신을 위해서 사용 +enum class ItemColor { + Mono, + Green, + Emerald, + Aqua, + Blue, + Indigo, + Violet, + Purple, + Pink; + + val semanticColor: Color + get() = when (this) { + Mono -> lightColorScheme.monoItemBG + Green -> lightColorScheme.greenItemBG + Emerald -> lightColorScheme.emeraldItemBG + Aqua -> lightColorScheme.aquaItemBG + Blue -> lightColorScheme.blueItemBG + Indigo -> lightColorScheme.indigoItemBG + Violet -> lightColorScheme.violetItemBG + Purple -> lightColorScheme.purpleItemBG + Pink -> lightColorScheme.pinkItemBG + } +} diff --git a/compose/src/main/java/com/yourssu/design/system/compose/rule/Rounding.kt b/compose/src/main/java/com/yourssu/design/system/compose/rule/Rounding.kt deleted file mode 100644 index deab4bdf..00000000 --- a/compose/src/main/java/com/yourssu/design/system/compose/rule/Rounding.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.yourssu.design.system.compose.rule - -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Shapes -import androidx.compose.runtime.staticCompositionLocalOf -import androidx.compose.ui.unit.dp - -internal val smallRounding = 2.dp -internal val normalRounding = 4.dp -internal val largeRounding = 8.dp - -internal val YdsRounding = Shapes( - small = RoundedCornerShape(smallRounding), - medium = RoundedCornerShape(normalRounding), - large = RoundedCornerShape(largeRounding) -) - -internal val LocalYdsRounding = staticCompositionLocalOf { YdsRounding } \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/rule/YdsBorder.kt b/compose/src/main/java/com/yourssu/design/system/compose/rule/YdsBorder.kt new file mode 100644 index 00000000..5da321e4 --- /dev/null +++ b/compose/src/main/java/com/yourssu/design/system/compose/rule/YdsBorder.kt @@ -0,0 +1,14 @@ +package com.yourssu.design.system.compose.rule + +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp + +internal val minBorderWidth = 0.34.dp +internal val normalBorderWidth = 1.dp +internal val thickBorderWidth = 8.dp + +enum class YdsBorder(val dp: Dp) { + Thin(minBorderWidth), + Normal(normalBorderWidth), + Thick(thickBorderWidth), +} diff --git a/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonColorState.kt b/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonColorState.kt index 15475b22..c764ba93 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonColorState.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonColorState.kt @@ -1,43 +1,43 @@ package com.yourssu.design.system.compose.states -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.interaction.collectIsPressedAsState -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.State +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.setValue import androidx.compose.ui.graphics.Color -import com.yourssu.design.system.compose.util.alterColorIfPressed +import com.yourssu.design.system.compose.foundation.pressedColorFor @Immutable -data class ButtonColorState( +class ButtonColorState( val contentColor: Color = Color.Unspecified, val disabledContentColor: Color = Color.Unspecified, val bgColor: Color = Color.Transparent, - val disabledBgColor: Color = Color.Transparent + val disabledBgColor: Color = Color.Transparent, + pressed: Boolean = false, ) { - @Composable - fun contentColor( - enabled: Boolean, - interactionSource: MutableInteractionSource - ): State { - val pressed = interactionSource.collectIsPressedAsState().value - - return rememberUpdatedState(if (enabled) { - contentColor.alterColorIfPressed(isPressed = pressed) - } else { - disabledContentColor - }) - } + var pressed by mutableStateOf(pressed) + internal set @Composable - fun backgroundColor( - enabled: Boolean, - interactionSource: MutableInteractionSource - ): State { - val pressed by interactionSource.collectIsPressedAsState() + fun contentColor(enabled: Boolean): State = + rememberUpdatedState( + when { + !enabled -> disabledContentColor + pressed -> pressedColorFor(contentColor) + else -> contentColor + } + ) - return rememberUpdatedState(if (enabled) { - bgColor.alterColorIfPressed(isPressed = pressed) - } else { - disabledBgColor - }) - } + @Composable + fun backgroundColor(enabled: Boolean): State = + rememberUpdatedState( + when { + !enabled -> disabledBgColor + pressed -> pressedColorFor(bgColor) + else -> bgColor + } + ) } \ No newline at end of file diff --git a/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonSizeState.kt b/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonSizeState.kt index 48beaea1..4608b9ea 100644 --- a/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonSizeState.kt +++ b/compose/src/main/java/com/yourssu/design/system/compose/states/ButtonSizeState.kt @@ -1,14 +1,14 @@ package com.yourssu.design.system.compose.states import androidx.compose.runtime.Immutable -import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import com.yourssu.design.system.compose.foundation.IconSize +import com.yourssu.design.system.compose.base.IconSize +import com.yourssu.design.system.compose.foundation.YdsTextStyle @Immutable data class ButtonSizeState( - val typo: TextStyle = TextStyle.Default, + val typo: YdsTextStyle = YdsTextStyle.Default, val iconSize: IconSize = IconSize.Medium, val height: Dp = 0.dp, val horizontalPadding: Dp = 0.dp, diff --git a/compose/src/main/java/com/yourssu/design/system/compose/util/ColorUtil.kt b/compose/src/main/java/com/yourssu/design/system/compose/util/ColorUtil.kt deleted file mode 100644 index c7bc0a06..00000000 --- a/compose/src/main/java/com/yourssu/design/system/compose/util/ColorUtil.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.yourssu.design.system.compose.util - -import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.Color -import com.yourssu.design.system.compose.YdsTheme - -@Composable -fun Color.alterColorIfPressed(isPressed: Boolean): Color { - return if (isPressed) { - when (this) { - YdsTheme.colors.buttonNormal -> YdsTheme.colors.buttonNormalPressed - YdsTheme.colors.buttonPoint -> YdsTheme.colors.buttonPointPressed - YdsTheme.colors.buttonWarned -> YdsTheme.colors.buttonWarnedPressed - else -> this - } - } else { - this - } -} \ No newline at end of file