Skip to content

Commit

Permalink
[MERGE] #16 -> develop
Browse files Browse the repository at this point in the history
[ADD/#16] Button / ์ปดํฌ๋„ŒํŠธ ๊ตฌํ˜„
  • Loading branch information
leeeyubin authored Jul 9, 2024
2 parents f1ac929 + 37378e6 commit f580d96
Show file tree
Hide file tree
Showing 30 changed files with 276 additions and 64 deletions.
3 changes: 3 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ dependencies {
implementation(libs.androidx.foundation.android)
implementation(libs.androidx.material3.android)

// Compose Preview
debugImplementation(libs.compose.ui.tooling)

// Test Dependency
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
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) {
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
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.runtime.Composable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Icon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -50,4 +50,4 @@ fun TerningBasicTopAppBar(
}
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ fun SearchTextField(
hint: String,
leftIcon: Int,
) {
TerningBasicTextField(
value = text,
onValueChange = onValueChange,
textStyle = TerningTheme.typography.button3,
textColor = Grey400,
cursorBrush = SolidColor(Grey300),
drawLineColor = Grey300,
strokeWidth = 2f,
hint = hint,
hintColor = Grey300,
leftIcon = leftIcon,
leftIconColor = Grey400,
)
// TerningBasicTextField(
// value = text,
// onValueChange = onValueChange,
// textStyle = TerningTheme.typography.button3,
// textColor = Grey400,
// cursorBrush = SolidColor(Grey300),
// drawLineColor = Grey300,
// strokeWidth = 2f,
// hint = hint,
// hintColor = Grey300,
// leftIcon = leftIcon,
// leftIconColor = Grey400,
// )
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ val Black = Color(0xFF171717)

// Main Color
val TerningMain = Color(0xFF1EA65E)
val TerningMain2 = Color(0xFF179653)

// Calendar Color
val CalRed = Color(0xFFED4E54)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun ProvideTerningTypography(typography: TerningTypography, content: @Composable
}

@Composable
fun TerningTheme(
fun TerningPointTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ class TerningTypography internal constructor(
}
}


@Composable
fun TerningTypography(): TerningTypography {
return TerningTypography(
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/terning/core/extension/Retrofit.kt
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
}
19 changes: 19 additions & 0 deletions core/src/main/java/com/terning/core/util/NoRippleTheme.kt
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
)
}
8 changes: 6 additions & 2 deletions core/src/main/res/values/strings.xml
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>
6 changes: 2 additions & 4 deletions feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ dependencies {
// Material Design
implementation(libs.material)
implementation(libs.androidx.material3.android)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.ui.graphics)

// TestDependencies
Expand All @@ -91,9 +90,8 @@ dependencies {
implementation(libs.ossLicense)
implementation(libs.lottie)

//Compose Preview
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.ui.tooling.preview)
// Compose Preview
debugImplementation(libs.compose.ui.tooling)

// KakaoDependencies
implementation(libs.kakao.user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.terning.core.designsystem.theme.Black
import com.terning.core.designsystem.theme.Grey150
import com.terning.core.designsystem.theme.Grey200
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.White
import com.terning.feature.calendar.models.DayModel
Expand Down Expand Up @@ -78,7 +79,7 @@ fun CalendarDay(
@Preview(showBackground = true)
@Composable
fun CalendarDayPreview() {
TerningTheme {
TerningPointTheme {
Row {
CalendarDay(
dayData = DayModel(LocalDate.now(), false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.theme.Grey150
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.feature.calendar.models.MonthData
import com.terning.feature.calendar.models.Scrap
Expand Down Expand Up @@ -75,7 +76,7 @@ fun CalendarMonth(
@Preview(showBackground = true)
@Composable
fun CalendarMonthPreview() {
TerningTheme {
TerningPointTheme {
CalendarMonth(
monthData = MonthData(YearMonth.now()),
selectedDate = LocalDate.now(),
Expand Down
Loading

0 comments on commit f580d96

Please sign in to comment.