Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mz 156 badge #22

Merged
merged 10 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.susu.core.designsystem.component.badge

import androidx.compose.ui.graphics.Color
import com.susu.core.designsystem.theme.Gray10
import com.susu.core.designsystem.theme.Gray70

enum class BadgeColor(
val backgroundColor: Color,
val textColor: Color,
) {
Gray20(
backgroundColor = com.susu.core.designsystem.theme.Gray20,
textColor = Gray70,
),
Orange60(
backgroundColor = com.susu.core.designsystem.theme.Orange60,
textColor = Gray10,
),
Blue60(
backgroundColor = com.susu.core.designsystem.theme.Blue60,
textColor = Gray10,
),
Gray90(
backgroundColor = com.susu.core.designsystem.theme.Gray90,
textColor = Gray10,
),
Gray40(
backgroundColor = com.susu.core.designsystem.theme.Gray40,
textColor = Gray10,
),
Gray30(
backgroundColor = com.susu.core.designsystem.theme.Gray30,
textColor = Gray70,
),
Red60(
backgroundColor = com.susu.core.designsystem.theme.Red60,
textColor = Gray10,
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.susu.core.designsystem.component.badge

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp
import com.susu.core.designsystem.theme.SusuTheme

data class BadgePadding(
val horizontalPadding: Dp,
val verticalPadding: Dp,
)

object BadgeStyle {
val smallBadge: @Composable () -> BadgePadding = {
BadgePadding(
horizontalPadding = SusuTheme.spacing.spacing_xxs,
verticalPadding = SusuTheme.spacing.spacing_xxxxxs,
)
}
val extraSmallBadge: @Composable () -> BadgePadding = {
BadgePadding(
horizontalPadding = SusuTheme.spacing.spacing_xxs,
verticalPadding = SusuTheme.spacing.spacing_xxxxxs,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.susu.core.designsystem.component.badge

import androidx.compose.foundation.background
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.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.susu.core.designsystem.theme.SusuTheme

@Composable
fun SusuBadge(
modifier: Modifier = Modifier,
shape: Shape = RoundedCornerShape(4.dp),
color: BadgeColor,
text: String,
padding: @Composable () -> BadgePadding,
) {
val horizontalPadding = padding().horizontalPadding
val verticalPadding = padding().verticalPadding

Box(
modifier = modifier.background(color.backgroundColor, shape),
) {
Text(
text = text,
style = SusuTheme.typography.title_xxxs,
color = color.textColor,
modifier = modifier.padding(
horizontal = horizontalPadding,
vertical = verticalPadding,
),
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 하면 padding() 람다가 2번 실행되는 문제가 있습니다!

Suggested change
val horizontalPadding = padding().horizontalPadding
val verticalPadding = padding().verticalPadding
Box(
modifier = modifier.background(color.backgroundColor, shape),
) {
Text(
text = text,
style = SusuTheme.typography.title_xxxs,
color = color.textColor,
modifier = modifier.padding(
horizontal = horizontalPadding,
vertical = verticalPadding,
),
)
}
with(padding()) {
Box(
modifier = modifier.background(color.backgroundColor, shape),
) {
Text(
text = text,
style = SusuTheme.typography.title_xxxs,
color = color.textColor,
modifier = modifier.padding(
horizontal = horizontalPadding,
vertical = verticalPadding,
),
)
}
}

}

@Preview(showBackground = true)
@Composable
fun SusuSmallBadgePreview() {
SusuTheme {
Row(
horizontalArrangement = Arrangement.spacedBy(20.dp),
) {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
SusuBadge(
color = BadgeColor.Gray20,
text = "전체 100,000원",
padding = BadgeStyle.smallBadge,
)
SusuBadge(
color = BadgeColor.Orange60,
text = "가족",
padding = BadgeStyle.smallBadge,
)
SusuBadge(
color = BadgeColor.Blue60,
text = "미방문",
padding = BadgeStyle.smallBadge,
)
SusuBadge(
color = BadgeColor.Gray90,
text = "선물 O",
padding = BadgeStyle.smallBadge,
)
SusuBadge(
color = BadgeColor.Gray40,
text = "선물 O",
padding = BadgeStyle.smallBadge,
)
SusuBadge(
color = BadgeColor.Gray30,
text = "전체 100,000원",
padding = BadgeStyle.smallBadge,
)
SusuBadge(
color = BadgeColor.Red60,
text = "미방문",
padding = BadgeStyle.smallBadge,
)
}

Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
SusuBadge(
color = BadgeColor.Gray20,
text = "전체 100,000원",
padding = BadgeStyle.extraSmallBadge,
)
SusuBadge(
color = BadgeColor.Orange60,
text = "가족",
padding = BadgeStyle.extraSmallBadge,
)
SusuBadge(
color = BadgeColor.Blue60,
text = "미방문",
padding = BadgeStyle.extraSmallBadge,
)
SusuBadge(
color = BadgeColor.Gray90,
text = "선물 O",
padding = BadgeStyle.extraSmallBadge,
)
SusuBadge(
color = BadgeColor.Gray40,
text = "선물 O",
padding = BadgeStyle.extraSmallBadge,
)
SusuBadge(
color = BadgeColor.Gray30,
text = "전체 100,000원",
padding = BadgeStyle.extraSmallBadge,
)
SusuBadge(
color = BadgeColor.Red60,
text = "미방문",
padding = BadgeStyle.extraSmallBadge,
)
}
}
}
}