-
Notifications
You must be signed in to change notification settings - Fork 0
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
Chip 구현 #25
Open
hoyaboi
wants to merge
1
commit into
main
Choose a base branch
from
feature/hoya/chip
base: main
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
Chip 구현 #25
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
149 changes: 149 additions & 0 deletions
149
app/src/main/kotlin/com/yourssu/handy/demo/ChipPreview.kt
This file contains 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,149 @@ | ||
package com.yourssu.handy.demo | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.Color.Companion.White | ||
import androidx.compose.ui.layout.VerticalAlignmentLine | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.yourssu.handy.compose.Chip | ||
import com.yourssu.handy.compose.ChipSize | ||
import com.yourssu.handy.compose.HandyTheme | ||
import com.yourssu.handy.compose.icons.HandyIcons | ||
import com.yourssu.handy.compose.icons.line.Cancel | ||
import com.yourssu.handy.compose.icons.line.Close | ||
import com.yourssu.handy.compose.icons.line.Crop | ||
import com.yourssu.handy.compose.icons.line.InfoCircle | ||
|
||
@Preview | ||
@Composable | ||
fun ChipPreview() { | ||
HandyTheme { | ||
Column ( | ||
modifier = Modifier | ||
.background(White) | ||
.padding(10.dp), | ||
verticalArrangement = Arrangement.spacedBy(30.dp) | ||
) { | ||
Row ( | ||
horizontalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
Column ( | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
checked = false | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
checked = true | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
enabled = false | ||
) | ||
} | ||
|
||
Column ( | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
leftIcon = HandyIcons.Line.InfoCircle, | ||
rightIcon = HandyIcons.Line.Close, | ||
checked = false | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
leftIcon = HandyIcons.Line.InfoCircle, | ||
rightIcon = HandyIcons.Line.Close, | ||
checked = true | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
leftIcon = HandyIcons.Line.InfoCircle, | ||
rightIcon = HandyIcons.Line.Close, | ||
enabled = false | ||
) | ||
} | ||
} | ||
|
||
Row ( | ||
horizontalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
Column ( | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
sizeType = ChipSize.Small, | ||
checked = false | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
sizeType = ChipSize.Small, | ||
checked = true | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
sizeType = ChipSize.Small, | ||
enabled = false | ||
) | ||
} | ||
|
||
Column ( | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
sizeType = ChipSize.Small, | ||
leftIcon = HandyIcons.Line.InfoCircle, | ||
rightIcon = HandyIcons.Line.Close, | ||
checked = false | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
sizeType = ChipSize.Small, | ||
leftIcon = HandyIcons.Line.InfoCircle, | ||
rightIcon = HandyIcons.Line.Close, | ||
checked = true | ||
) | ||
|
||
Chip( | ||
onCheckedChange = {}, | ||
text = "Label", | ||
sizeType = ChipSize.Small, | ||
leftIcon = HandyIcons.Line.InfoCircle, | ||
rightIcon = HandyIcons.Line.Close, | ||
enabled = false | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
compose/src/main/kotlin/com/yourssu/handy/compose/Chip.kt
This file contains 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,104 @@ | ||||||||||||||
package com.yourssu.handy.compose | ||||||||||||||
|
||||||||||||||
import androidx.compose.foundation.layout.Row | ||||||||||||||
import androidx.compose.foundation.layout.height | ||||||||||||||
import androidx.compose.foundation.layout.padding | ||||||||||||||
import androidx.compose.runtime.Composable | ||||||||||||||
import androidx.compose.ui.Alignment | ||||||||||||||
import androidx.compose.ui.Modifier | ||||||||||||||
import androidx.compose.ui.graphics.vector.ImageVector | ||||||||||||||
import androidx.compose.ui.unit.Dp | ||||||||||||||
import androidx.compose.ui.unit.dp | ||||||||||||||
import com.yourssu.handy.compose.foundation.HandyTextStyle | ||||||||||||||
import com.yourssu.handy.compose.foundation.HandyTypography | ||||||||||||||
|
||||||||||||||
sealed class ChipSize( | ||||||||||||||
val height: Dp, | ||||||||||||||
val iconSize: IconSize = IconSize.XS, | ||||||||||||||
val horizontalPadding: Dp = 12.dp, | ||||||||||||||
val round: Dp = 40.dp | ||||||||||||||
) { | ||||||||||||||
data object Small : ChipSize(height = 24.dp) | ||||||||||||||
data object Medium : ChipSize(height = 32.dp) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* 정보를 입력하거나 선택하여 컨텐츠를 필터링할 수 있는 [Chip]입니다. | ||||||||||||||
* | ||||||||||||||
* @param onCheckedChange Chip의 선택 상태가 변경될 때 호출되는 함수 | ||||||||||||||
* @param text Chip 내부 텍스트 | ||||||||||||||
* @param sizeType Chip 사이즈 설정 : Small, Medium(Default) | ||||||||||||||
* @param leftIcon Chip 내부 텍스트의 왼쪽에 표시되는 아이콘 | ||||||||||||||
* @param rightIcon Chip 내부 텍스트의 오른쪽에 표시되는 아이콘 | ||||||||||||||
* @param checked Chip의 선택 여부 | ||||||||||||||
* @param enabled Chip의 활성화 여부 | ||||||||||||||
*/ | ||||||||||||||
@Composable | ||||||||||||||
fun Chip( | ||||||||||||||
onCheckedChange: (Boolean) -> Unit, | ||||||||||||||
modifier: Modifier = Modifier, | ||||||||||||||
text: String, | ||||||||||||||
Comment on lines
+37
to
+40
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.
Comment on lines
+38
to
+40
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. 기본값이 없는 파라미터(필수 파라미터)의 경우 modifier보다 위에 두는 것을 권장합니다! 기본값이 있는 optional 파라미터는 modifier 밑으로 두면됩니다
Suggested change
|
||||||||||||||
sizeType: ChipSize = ChipSize.Medium, | ||||||||||||||
leftIcon: ImageVector? = null, | ||||||||||||||
rightIcon: ImageVector? = null, | ||||||||||||||
checked: Boolean = false, | ||||||||||||||
enabled: Boolean = true, | ||||||||||||||
) { | ||||||||||||||
val iconSize = sizeType.iconSize | ||||||||||||||
val height = sizeType.height | ||||||||||||||
val horizontalPadding = sizeType.horizontalPadding | ||||||||||||||
val round = sizeType.round | ||||||||||||||
|
||||||||||||||
val typo = when { | ||||||||||||||
checked -> HandyTypography.B3Sb14 | ||||||||||||||
else -> HandyTypography.B3Rg14 | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
val backgroundColor = when { | ||||||||||||||
checked -> HandyTheme.colors.chipSelected | ||||||||||||||
!enabled -> HandyTheme.colors.chipDisabled | ||||||||||||||
else -> HandyTheme.colors.chipUnselected | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
val contentColor = when { | ||||||||||||||
checked -> HandyTheme.colors.textBrandPrimary | ||||||||||||||
!enabled -> HandyTheme.colors.textBasicDisabled | ||||||||||||||
else -> HandyTheme.colors.textBasicSecondary | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
Surface( | ||||||||||||||
checked = checked, | ||||||||||||||
onCheckedChange = onCheckedChange, | ||||||||||||||
modifier = modifier.height(height), | ||||||||||||||
enabled = enabled, | ||||||||||||||
rounding = round, | ||||||||||||||
backgroundColor = backgroundColor, | ||||||||||||||
contentColor = contentColor | ||||||||||||||
) { | ||||||||||||||
Row( | ||||||||||||||
modifier = Modifier.padding(horizontal = horizontalPadding), | ||||||||||||||
verticalAlignment = Alignment.CenterVertically | ||||||||||||||
) { | ||||||||||||||
leftIcon?.let { | ||||||||||||||
Icon( | ||||||||||||||
imageVector = leftIcon, | ||||||||||||||
iconSize = iconSize, | ||||||||||||||
modifier = Modifier.padding(end = 4.dp) | ||||||||||||||
) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
Text( | ||||||||||||||
text = text, | ||||||||||||||
style = typo, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
rightIcon?.let { | ||||||||||||||
Icon( | ||||||||||||||
imageVector = rightIcon, | ||||||||||||||
iconSize = iconSize, | ||||||||||||||
modifier = Modifier.padding(start = 4.dp) | ||||||||||||||
) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
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.
이 부분이 chip의 사이즈에 영향을 받지 않는 부분이라면 파일 맨 끝에 아래와 같이 명시 하는게 어떠할까요? 상수 값을 따로 뺀다면 sealed class여야 할 이유도 없어 보입니다..! 지금도 너무 좋은 코드지만, 다른 핸디 컴포넌트 구현들과 구조를 맞추는게 좋지 아니할까 싶습니닷..!!
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.
기존에 구현된 컴포넌트 코드를 보니, 사이즈에 따라 타이포나 아이콘 사이즈 등이 달라지는 경우에는 sealed class, 단순 size 구분에는 enum class를 사용한 걸로 파악이 됩니다!