Skip to content

[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 5 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -8,28 +8,57 @@ import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
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.Color
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 FilledButtonColors {
Primary,
Warning,
Danger,
}
Comment on lines +20 to +24
Copy link
Contributor

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.primaryButtonColors()
ButtonDefauts.warningButtonColors()
...

이런식으로 이용할 수 있게 해주는 게 좋을 것 같아요.

ButtonDefaults.buttonColors(containerColor = ...)
또 이렇게 named argument 지정해서 특정 색만 바꿀 수 있게 해주는 것처럼도 만들어주면 더 좋을 것 같아요..


@Composable
fun FilledButton(
modifier: Modifier = Modifier,
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
textStyle: TextStyle = KoinTheme.typography.medium15,
shape: Shape = RoundedCornerShape(5.dp),
enabled: Boolean = true,
colors: FilledButtonColors = FilledButtonColors.Primary,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
) {
val buttonColors = filledButtonColorByType(type = colors)
Button(
modifier = modifier,
onClick = onClick,
shape = shape,
enabled = enabled,
colors = buttonColors,
contentPadding = contentPadding
) {
Text(
text = text,
style = textStyle
)
}
}

@Composable
fun FilledButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
textStyle: TextStyle = KoinTheme.typography.medium15,
shape: Shape = RoundedCornerShape(5.dp),
enabled: Boolean = true,
colors: ButtonColors = ButtonDefaults.buttonColors(
containerColor = KoinTheme.colors.primary500,
contentColor = Color.White,
disabledContainerColor = KoinTheme.colors.neutral300,
disabledContentColor = KoinTheme.colors.neutral600
),
colors: ButtonColors,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
) {
Button(
Expand All @@ -47,6 +76,31 @@ fun FilledButton(
}
}

@Composable
@Stable
internal fun filledButtonColorByType(type: FilledButtonColors): ButtonColors = when (type) {
FilledButtonColors.Primary -> ButtonColors(
containerColor = KoinTheme.colors.primary500,
contentColor = KoinTheme.colors.neutral0,
disabledContainerColor = KoinTheme.colors.neutral300,
disabledContentColor = KoinTheme.colors.neutral600
)

FilledButtonColors.Warning -> ButtonColors(
containerColor = KoinTheme.colors.sub500,
contentColor = KoinTheme.colors.neutral0,
disabledContainerColor = KoinTheme.colors.neutral300,
disabledContentColor = KoinTheme.colors.neutral600
)

FilledButtonColors.Danger -> ButtonColors(
containerColor = KoinTheme.colors.danger700,
contentColor = KoinTheme.colors.neutral0,
disabledContainerColor = KoinTheme.colors.neutral300,
disabledContentColor = KoinTheme.colors.neutral600
)
}

@Preview
@Composable
private fun FilledButtonPreview() {
Expand All @@ -69,4 +123,16 @@ private fun FilledButtonDisabledPreview() {
@Composable
private fun FilledButtonCustomColorPreview() {
FilledButton(text = "조회하기", onClick = {}, enabled = false, modifier = Modifier.fillMaxWidth())
}

@Preview
@Composable
private fun FilledButtonWarningPreview() {
FilledButton(text = "조회하기", onClick = {}, colors = FilledButtonColors.Warning)
}

@Preview
@Composable
private fun FilledButtonDangerPreview() {
FilledButton(text = "조회하기", onClick = {}, colors = FilledButtonColors.Danger)
}
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 = {}
)
}
}
Loading
Loading