-
Notifications
You must be signed in to change notification settings - Fork 1
[Feature] 다이얼로그, 윤곽선 버튼 컴포넌트 추가 #450
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
166 changes: 166 additions & 0 deletions
166
...m/src/main/java/in/koreatech/koin/core/designsystem/component/button/OutlinedBoxButton.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,166 @@ | ||
package `in`.koreatech.koin.core.designsystem.component.button | ||
|
||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.material3.ButtonColors | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.OutlinedButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import `in`.koreatech.koin.core.designsystem.theme.KoinTheme | ||
|
||
|
||
enum class OutlinedBoxButtonColors { | ||
Primary, | ||
Neutral | ||
} | ||
|
||
/** | ||
* 테두리 선이 있는 텍스트 버튼 | ||
* @param text 텍스트 | ||
* @param onClick 버튼 클릭시 실행할 함수 | ||
* @param textStyle 텍스트 스타일 | ||
* @param shape 버튼 모양 | ||
* @param enabled 버튼 활성화 여부 | ||
* @param colors 버튼 색상 타입 | ||
* @param contentPadding 버튼 내부 padding | ||
* @see OutlinedBoxButtonColors | ||
*/ | ||
@Composable | ||
fun OutlinedBoxButton( | ||
text: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
textStyle: TextStyle = KoinTheme.typography.medium15, | ||
shape: Shape = KoinTheme.shapes.extraSmall, | ||
enabled: Boolean = true, | ||
colors: OutlinedBoxButtonColors = OutlinedBoxButtonColors.Primary, | ||
contentPadding: PaddingValues = ButtonDefaults.ContentPadding, | ||
) { | ||
val buttonColors = outlinedBoxButtonColorByType(colors) | ||
val buttonBorder = outlinedBoxButtonBorderByType(colors) | ||
|
||
OutlinedButton( | ||
modifier = modifier, | ||
onClick = onClick, | ||
enabled = enabled, | ||
shape = shape, | ||
colors = buttonColors, | ||
border = buttonBorder, | ||
contentPadding = contentPadding, | ||
) { | ||
Text( | ||
text = text, | ||
style = textStyle | ||
) | ||
} | ||
} | ||
|
||
|
||
/** | ||
* 테두리 선이 있는 텍스트 버튼 | ||
* @param text 텍스트 | ||
* @param onClick 버튼 클릭시 실행할 함수 | ||
* @param textStyle 텍스트 스타일 | ||
* @param shape 버튼 모양 | ||
* @param enabled 버튼 활성화 여부 | ||
* @param colors 버튼 색상 | ||
* @param border 테두리 선 | ||
* @param contentPadding 버튼 내부 padding | ||
* @see OutlinedBoxButtonColors | ||
*/ | ||
@Composable | ||
fun OutlinedBoxButton( | ||
text: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
textStyle: TextStyle = KoinTheme.typography.medium15, | ||
shape: Shape = KoinTheme.shapes.extraSmall, | ||
enabled: Boolean = true, | ||
colors: ButtonColors = ButtonColors( | ||
containerColor = KoinTheme.colors.neutral0, | ||
contentColor = KoinTheme.colors.neutral0, | ||
disabledContainerColor = KoinTheme.colors.neutral400, | ||
disabledContentColor = KoinTheme.colors.neutral500 | ||
), | ||
border: BorderStroke, | ||
contentPadding: PaddingValues = ButtonDefaults.ContentPadding, | ||
) { | ||
OutlinedButton( | ||
modifier = modifier, | ||
onClick = onClick, | ||
enabled = enabled, | ||
shape = shape, | ||
colors = colors, | ||
border = border, | ||
contentPadding = contentPadding, | ||
) { | ||
Text( | ||
text = text, | ||
style = textStyle | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
@Stable | ||
internal fun outlinedBoxButtonColorByType(type: OutlinedBoxButtonColors): ButtonColors = when (type) { | ||
OutlinedBoxButtonColors.Primary -> ButtonColors( | ||
containerColor = KoinTheme.colors.neutral0, | ||
contentColor = KoinTheme.colors.primary500, | ||
disabledContainerColor = KoinTheme.colors.neutral400, | ||
disabledContentColor = KoinTheme.colors.neutral500 | ||
) | ||
|
||
OutlinedBoxButtonColors.Neutral -> ButtonColors( | ||
containerColor = KoinTheme.colors.neutral0, | ||
contentColor = KoinTheme.colors.neutral500, | ||
disabledContainerColor = KoinTheme.colors.neutral400, | ||
disabledContentColor = KoinTheme.colors.neutral500 | ||
) | ||
} | ||
|
||
|
||
@Composable | ||
@Stable | ||
internal fun outlinedBoxButtonBorderByType(type: OutlinedBoxButtonColors): BorderStroke = when (type) { | ||
OutlinedBoxButtonColors.Primary -> BorderStroke( | ||
1.0.dp, | ||
color = KoinTheme.colors.primary500 | ||
) | ||
|
||
OutlinedBoxButtonColors.Neutral -> BorderStroke( | ||
1.0.dp, | ||
color = KoinTheme.colors.neutral500 | ||
) | ||
} | ||
|
||
|
||
@Preview | ||
@Composable | ||
private fun OutlinedButtonPrimaryPreview() { | ||
KoinTheme { | ||
OutlinedBoxButton( | ||
text = "대체하기", | ||
onClick = {} | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun OutlinedButtonNeutralPreview() { | ||
KoinTheme { | ||
OutlinedBoxButton( | ||
text = "대체하기", | ||
colors = OutlinedBoxButtonColors.Neutral, | ||
onClick = {} | ||
) | ||
} | ||
} |
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.
색이 더 늘어나진 않겠지만...(설마)
혹시 버튼에 다른 색이 필요하면 enum property를 추가해줘야 한단 점에서 컴포넌트가 좀 한정지어지는 느낌이 듭니다.
컴포즈에선 기본 버튼 색상을
ButtonDefaults.buttonColors()
로 제공하고 있는데, 이런 느낌 따라서이런식으로 이용할 수 있게 해주는 게 좋을 것 같아요.
ButtonDefaults.buttonColors(containerColor = ...)
또 이렇게 named argument 지정해서 특정 색만 바꿀 수 있게 해주는 것처럼도 만들어주면 더 좋을 것 같아요..