-
Notifications
You must be signed in to change notification settings - Fork 1
PrezelChip 구현 #41
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
Open
HamBeomJoon
wants to merge
3
commits into
develop
Choose a base branch
from
feat/#27-prezel-chip
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PrezelChip 구현 #41
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
...designsystem/src/main/java/com/team/prezel/core/designsystem/component/chip/PrezelChip.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| package com.team.prezel.core.designsystem.component.chip | ||
|
|
||
| import androidx.compose.foundation.BorderStroke | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.LocalContentColor | ||
| import androidx.compose.material3.LocalTextStyle | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import com.team.prezel.core.designsystem.icon.DrawableIcon | ||
| import com.team.prezel.core.designsystem.icon.IconSource | ||
| import com.team.prezel.core.designsystem.icon.PrezelIcons | ||
| import com.team.prezel.core.designsystem.preview.PreviewScaffold | ||
| import com.team.prezel.core.designsystem.preview.ThemePreview | ||
| import com.team.prezel.core.designsystem.theme.PrezelTheme | ||
|
|
||
| @Composable | ||
| fun PrezelChip( | ||
| modifier: Modifier = Modifier, | ||
| text: String? = null, | ||
| icon: IconSource? = null, | ||
| style: PrezelChipStyle = PrezelChipStyle(), | ||
| ) { | ||
| val hasText = text != null | ||
| val hasIcon = icon != null | ||
| val iconOnly = hasIcon && !hasText | ||
| require(hasText || hasIcon) { "Chip은 text 또는 icon 중 하나는 반드시 필요합니다." } | ||
| val (chipType, chipSize, interaction, feedback) = style | ||
|
|
||
| Surface( | ||
| modifier = modifier, | ||
| shape = prezelChipShape(chipSize), | ||
| color = prezelChipContainerColor(type = chipType, interaction = interaction, feedback = feedback, iconOnly = iconOnly), | ||
| border = prezelChipBorderStroke(type = chipType, interaction = interaction, feedback = feedback), | ||
| ) { | ||
| CompositionLocalProvider( | ||
| LocalTextStyle provides prezelChipTextStyle(chipSize), | ||
| LocalContentColor provides prezelChipContentColor(interaction = interaction, feedback = feedback), | ||
| ) { | ||
| Row( | ||
| modifier = Modifier.padding(prezelChipContentPadding(size = chipSize, onlyIcon = hasIcon && !hasText)), | ||
| horizontalArrangement = Arrangement.Center, | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| PrezelChipIcon(icon = icon, size = chipSize) | ||
|
|
||
| if (!hasText) return@Row | ||
| if (hasIcon) { | ||
| val spacing = if (chipSize == PrezelChipSize.REGULAR) PrezelTheme.spacing.V4 else PrezelTheme.spacing.V2 | ||
| Spacer(modifier = Modifier.width(width = spacing)) | ||
| } | ||
|
|
||
| Text(text = text) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun PrezelChip( | ||
| modifier: Modifier = Modifier, | ||
| text: String? = null, | ||
| icon: IconSource? = null, | ||
| style: PrezelChipStyle = PrezelChipStyle(), | ||
| containerColor: Color? = null, | ||
| contentColor: Color? = null, | ||
| ) { | ||
| val hasText = text != null | ||
| val hasIcon = icon != null | ||
| val iconOnly = hasIcon && !hasText | ||
| require(hasText || hasIcon) { "Chip은 text 또는 icon 중 하나는 반드시 필요합니다." } | ||
| val (_, chipSize, _, _) = style | ||
|
|
||
| val resolvedBorder = | ||
| resolveChipBorder( | ||
| style = style, | ||
| hasCustomContainerColor = containerColor != null, | ||
| ) | ||
|
|
||
| val resolvedContainerColor = | ||
| resolveChipContainerColor( | ||
| style = style, | ||
| iconOnly = iconOnly, | ||
| overrideColor = containerColor, | ||
| ) | ||
|
|
||
| val resolvedContentColor = | ||
| resolveChipContentColor( | ||
| style = style, | ||
| overrideColor = contentColor, | ||
| ) | ||
|
|
||
| Surface( | ||
| modifier = modifier, | ||
| shape = prezelChipShape(chipSize), | ||
| color = resolvedContainerColor, | ||
| border = resolvedBorder, | ||
| ) { | ||
| CompositionLocalProvider( | ||
| LocalTextStyle provides prezelChipTextStyle(chipSize), | ||
| LocalContentColor provides resolvedContentColor, | ||
| ) { | ||
| Row( | ||
| modifier = Modifier.padding(prezelChipContentPadding(size = chipSize, onlyIcon = hasIcon && !hasText)), | ||
| horizontalArrangement = Arrangement.Center, | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| PrezelChipIcon(icon = icon, size = chipSize) | ||
|
|
||
| if (!hasText) return@Row | ||
| if (hasIcon) { | ||
| val spacing = if (chipSize == PrezelChipSize.REGULAR) PrezelTheme.spacing.V4 else PrezelTheme.spacing.V2 | ||
| Spacer(modifier = Modifier.width(width = spacing)) | ||
| } | ||
|
|
||
| Text(text = text) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+102
to
+128
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Composable | ||
| private fun resolveChipBorder( | ||
| style: PrezelChipStyle, | ||
| hasCustomContainerColor: Boolean, | ||
| ): BorderStroke? = | ||
| if (hasCustomContainerColor) { | ||
| null | ||
| } else { | ||
| prezelChipBorderStroke( | ||
| type = style.type, | ||
| interaction = style.interaction, | ||
| feedback = style.feedback, | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun resolveChipContainerColor( | ||
| style: PrezelChipStyle, | ||
| iconOnly: Boolean, | ||
| overrideColor: Color?, | ||
| ): Color = | ||
| overrideColor ?: prezelChipContainerColor( | ||
| type = style.type, | ||
| interaction = style.interaction, | ||
| feedback = style.feedback, | ||
| iconOnly = iconOnly, | ||
| ) | ||
|
|
||
| @Composable | ||
| private fun resolveChipContentColor( | ||
| style: PrezelChipStyle, | ||
| overrideColor: Color?, | ||
| ): Color = | ||
| overrideColor ?: prezelChipContentColor( | ||
| interaction = style.interaction, | ||
| feedback = style.feedback, | ||
| ) | ||
|
|
||
| @ThemePreview | ||
| @Composable | ||
| private fun PrezelChipPreview() { | ||
| PrezelTheme { | ||
| PrezelTheme { | ||
| PreviewScaffold { | ||
| PrezelChipPreviewByType( | ||
| type = PrezelChipType.FILLED, | ||
| ) { style -> PrezelChipPreviewItem(style) } | ||
|
|
||
| HorizontalDivider() | ||
|
|
||
| PrezelChipPreviewByType( | ||
| type = PrezelChipType.OUTLINED, | ||
| ) { style -> PrezelChipPreviewItem(style) } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PrezelChipPreviewItem(style: PrezelChipStyle) { | ||
| PrezelChip( | ||
| text = "Label", | ||
| icon = DrawableIcon(resId = PrezelIcons.Blank), | ||
| style = style, | ||
| ) | ||
| } | ||
130 changes: 130 additions & 0 deletions
130
...ystem/src/main/java/com/team/prezel/core/designsystem/component/chip/PrezelChipPreview.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package com.team.prezel.core.designsystem.component.chip | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import com.team.prezel.core.designsystem.theme.PrezelTheme | ||
| import kotlinx.collections.immutable.persistentListOf | ||
|
|
||
| internal typealias PrezelChipPreviewContent = @Composable (PrezelChipStyle) -> Unit | ||
|
|
||
| private val DefaultInteractionVariants = persistentListOf( | ||
| PrezelChipInteraction.DEFAULT, | ||
| PrezelChipInteraction.ACTIVE, | ||
| PrezelChipInteraction.DISABLED, | ||
| ) | ||
|
|
||
| private val PreviewSizes = persistentListOf( | ||
| PrezelChipSize.SMALL, | ||
| PrezelChipSize.REGULAR, | ||
| ) | ||
|
|
||
| @Composable | ||
| internal fun PrezelChipPreviewByType( | ||
| type: PrezelChipType, | ||
| content: PrezelChipPreviewContent, | ||
| ) { | ||
| Text( | ||
| text = type.name, | ||
| style = PrezelTheme.typography.title2Medium, | ||
| ) | ||
|
|
||
| HorizontalDivider() | ||
|
|
||
| PrezelChipBadSection( | ||
| type = type, | ||
| content = content, | ||
| ) | ||
|
|
||
| HorizontalDivider() | ||
|
|
||
| PrezelChipDefaultSection( | ||
| type = type, | ||
| content = content, | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PrezelChipBadSection( | ||
| type: PrezelChipType, | ||
| content: PrezelChipPreviewContent, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Column( | ||
| modifier = modifier, | ||
| verticalArrangement = Arrangement.spacedBy(12.dp), | ||
| ) { | ||
| Text( | ||
| text = "Feedback: BAD", | ||
| style = PrezelTheme.typography.body2Medium, | ||
| ) | ||
|
|
||
| PrezelChipPreviewBlock( | ||
| type = type, | ||
| feedback = PrezelChipFeedback.BAD, | ||
| interaction = PrezelChipInteraction.DEFAULT, | ||
| content = content, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PrezelChipDefaultSection( | ||
| type: PrezelChipType, | ||
| content: PrezelChipPreviewContent, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Column( | ||
| modifier = modifier, | ||
| verticalArrangement = Arrangement.spacedBy(12.dp), | ||
| ) { | ||
| Text( | ||
| text = "Feedback: DEFAULT", | ||
| style = PrezelTheme.typography.body2Medium, | ||
| ) | ||
|
|
||
| DefaultInteractionVariants.forEach { interaction -> | ||
| Text( | ||
| text = "Interaction: $interaction", | ||
| style = PrezelTheme.typography.body3Medium, | ||
| ) | ||
|
|
||
| PrezelChipPreviewBlock( | ||
| type = type, | ||
| feedback = PrezelChipFeedback.DEFAULT, | ||
| interaction = interaction, | ||
| content = content, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PrezelChipPreviewBlock( | ||
| type: PrezelChipType, | ||
| interaction: PrezelChipInteraction, | ||
| feedback: PrezelChipFeedback, | ||
| content: PrezelChipPreviewContent, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Row( | ||
| modifier = modifier, | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
| ) { | ||
| PreviewSizes.forEach { size -> | ||
| content( | ||
| PrezelChipStyle( | ||
| type = type, | ||
| size = size, | ||
| interaction = interaction, | ||
| feedback = feedback, | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color를nullable로 처리하기보다는Color.Unspecified를 사용하는 편이 코드 가독성 측면에서 더 깔끔해 보입니다.또한 기본 Material3 컴포넌트의 설계 방식과도 일관성을 유지할 수 있을 것 같아요.