-
Notifications
You must be signed in to change notification settings - Fork 2
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
[ADD/#16] Button / 컴포넌트 구현 #21
Changes from 17 commits
66cdad6
738ac30
4f0bff5
9b56e34
cb7e768
54d204a
db426d6
b124445
d16b53e
195a182
c06c29d
c8f3c5b
0b7ea2e
7062258
5a860ac
9c5c0f0
eaf301b
6cb7ff2
3d46e51
1d328f2
e04ae18
37378e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.terning.core.designsystem.component.button | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.terning.core.R | ||
import com.terning.core.designsystem.theme.TerningPointTheme | ||
import com.terning.core.designsystem.theme.TerningTheme | ||
|
||
@Composable | ||
fun RectangleButton( | ||
style: TextStyle, | ||
paddingVertical: Dp, | ||
@StringRes text: Int, | ||
onButtonClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
isEnabled: Boolean = true | ||
) { | ||
TerningBasicButton( | ||
style = style, | ||
paddingVertical = paddingVertical, | ||
text = text, | ||
onButtonClick = onButtonClick, | ||
modifier = modifier, | ||
isEnabled = isEnabled, | ||
shape = RoundedCornerShape(0.dp), | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun RectangleButtonPreview() { | ||
TerningPointTheme { | ||
RectangleButton( | ||
style = TerningTheme.typography.button0, | ||
text = R.string.button_preview, | ||
paddingVertical = 19.dp, | ||
onButtonClick = {} | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.terning.core.designsystem.component.button | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.terning.core.R | ||
import com.terning.core.designsystem.theme.TerningPointTheme | ||
import com.terning.core.designsystem.theme.TerningTheme | ||
|
||
@Composable | ||
fun RoundButton( | ||
style: TextStyle, | ||
paddingVertical: Dp, | ||
cornerRadius: Dp, | ||
@StringRes text: Int, | ||
onButtonClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
isEnabled: Boolean = true, | ||
) { | ||
TerningBasicButton( | ||
modifier = modifier, | ||
style = style, | ||
paddingVertical = paddingVertical, | ||
shape = RoundedCornerShape(cornerRadius), | ||
text = text, | ||
onButtonClick = onButtonClick, | ||
isEnabled = isEnabled, | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun RoundButtonPreview() { | ||
TerningPointTheme { | ||
RoundButton( | ||
style = TerningTheme.typography.button0, | ||
text = R.string.button_preview, | ||
paddingVertical = 19.dp, | ||
cornerRadius = 10.dp, | ||
onButtonClick = {} | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.terning.core.designsystem.component.button | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.interaction.collectIsPressedAsState | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.ripple.LocalRippleTheme | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.terning.core.R | ||
import com.terning.core.designsystem.theme.Black | ||
import com.terning.core.designsystem.theme.Grey150 | ||
import com.terning.core.designsystem.theme.TerningMain | ||
import com.terning.core.designsystem.theme.TerningMain2 | ||
import com.terning.core.designsystem.theme.TerningPointTheme | ||
import com.terning.core.designsystem.theme.TerningTheme | ||
import com.terning.core.designsystem.theme.White | ||
import com.terning.core.util.NoRippleTheme | ||
|
||
@Composable | ||
fun TerningBasicButton( | ||
shape: Shape, | ||
style: TextStyle, | ||
paddingVertical: Dp, | ||
@StringRes text: Int, | ||
onButtonClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
isEnabled: Boolean = true, | ||
) { | ||
val interactionSource = remember { MutableInteractionSource() } | ||
val isPressed by interactionSource.collectIsPressedAsState() | ||
val backgroundColor = if (isPressed) TerningMain2 else TerningMain | ||
|
||
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) { | ||
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. 궁금한거 있습니다!!! 이렇게 선언만 해두면 바로 ripple이 사라지는건가요?????? 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. 네! 기존에 있던 LocalRippleTheme을 NoRippleTheme으로 바꿔준 겁니당 |
||
Button( | ||
modifier = modifier.fillMaxWidth(), | ||
interactionSource = interactionSource, | ||
enabled = isEnabled, | ||
colors = ButtonDefaults.buttonColors( | ||
containerColor = backgroundColor, | ||
contentColor = White, | ||
disabledContainerColor = Grey150, | ||
disabledContentColor = Black | ||
), | ||
shape = shape, | ||
onClick = { onButtonClick() } | ||
) { | ||
Text( | ||
text = stringResource(id = text), | ||
style = style, | ||
modifier = modifier.padding(vertical = paddingVertical) | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun TerningBasicButtonPreview() { | ||
TerningPointTheme { | ||
TerningBasicButton( | ||
text = R.string.button_preview, | ||
shape = ButtonDefaults.shape, | ||
style = TerningTheme.typography.button0, | ||
paddingVertical = 19.dp, | ||
onButtonClick = {} | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ fun ProvideTerningTypography(typography: TerningTypography, content: @Composable | |
} | ||
|
||
@Composable | ||
fun TerningTheme( | ||
fun TerningPointTheme( | ||
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. 우왕 완전 센스쟁이!! |
||
darkTheme: Boolean = isSystemInDarkTheme(), | ||
// Dynamic color is available on Android 12+ | ||
dynamicColor: Boolean = true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package com.terning.core.extension | ||
|
||
|
||
fun String?.isJsonObject(): Boolean = this?.startsWith("{") == true && this.endsWith("}") | ||
|
||
fun String?.isJsonArray(): Boolean = this?.startsWith("[") == true && this.endsWith("]") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.terning.core.util | ||
|
||
import androidx.compose.foundation.interaction.Interaction | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.emptyFlow | ||
|
||
object NoRippleInteractionSource : MutableInteractionSource { | ||
|
||
override val interactions: Flow<Interaction> = emptyFlow() | ||
|
||
override suspend fun emit(interaction: Interaction) {} | ||
|
||
override fun tryEmit(interaction: Interaction) = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.terning.core.util | ||
|
||
import androidx.compose.material.ripple.RippleAlpha | ||
import androidx.compose.material.ripple.RippleTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
|
||
object NoRippleTheme : RippleTheme { | ||
@Composable | ||
override fun defaultColor() = Color.Unspecified | ||
|
||
@Composable | ||
override fun rippleAlpha(): RippleAlpha = RippleAlpha( | ||
draggedAlpha = 0.0f, | ||
focusedAlpha = 0.0f, | ||
hoveredAlpha = 0.0f, | ||
pressedAlpha = 0.0f | ||
) | ||
Comment on lines
+13
to
+18
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. 리플테마 적용 감사해용 🥹 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- ContentDescription--> | ||
<!--ContentDescription--> | ||
<string name="ic_back">뒤로가기 버튼</string> | ||
<string name="ic_logo">탑 바 로고</string> | ||
<string name="ic_20_right">오른쪽 버튼</string> | ||
|
||
<!-- MyPage--> | ||
<!-- MyPage--> | ||
<string name="my_page_top_app_bar">프로필 수정</string> | ||
|
||
<!-- button--> | ||
<string name="button_preview">button</string> | ||
|
||
</resources> |
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.
버튼 색상 변경 방법 신기하네요!!
InteractionSource를 알아보다가 말았는데 여기서 배우고 갑니다!!
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.
오호!! 저도 새로운거 알아갑니다~~!!