Skip to content

Commit 55e66f9

Browse files
committed
feat: primary button style
1 parent 3369686 commit 55e66f9

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

app/src/main/java/to/bitkit/ui/components/Button.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package to.bitkit.ui.components
22

33
import androidx.compose.foundation.BorderStroke
4+
import androidx.compose.foundation.interaction.MutableInteractionSource
5+
import androidx.compose.foundation.interaction.collectIsPressedAsState
46
import androidx.compose.foundation.layout.Arrangement
57
import androidx.compose.foundation.layout.Box
68
import androidx.compose.foundation.layout.Column
@@ -16,10 +18,13 @@ import androidx.compose.material.icons.filled.Home
1618
import androidx.compose.material3.Button
1719
import androidx.compose.material3.CircularProgressIndicator
1820
import androidx.compose.material3.Icon
21+
import androidx.compose.material3.MaterialTheme
1922
import androidx.compose.material3.OutlinedButton
2023
import androidx.compose.material3.Text
2124
import androidx.compose.material3.TextButton
2225
import androidx.compose.runtime.Composable
26+
import androidx.compose.runtime.getValue
27+
import androidx.compose.runtime.remember
2328
import androidx.compose.ui.Alignment
2429
import androidx.compose.ui.Modifier
2530
import androidx.compose.ui.draw.alpha
@@ -28,6 +33,7 @@ import androidx.compose.ui.text.style.TextOverflow
2833
import androidx.compose.ui.tooling.preview.Preview
2934
import androidx.compose.ui.unit.Dp
3035
import androidx.compose.ui.unit.dp
36+
import to.bitkit.ui.shared.util.primaryButtonStyle
3137
import to.bitkit.ui.theme.AppButtonDefaults
3238
import to.bitkit.ui.theme.AppThemeSurface
3339
import to.bitkit.ui.theme.Colors
@@ -47,6 +53,7 @@ enum class ButtonSize {
4753
}
4854
}
4955

56+
@Suppress("UnusedParameter")
5057
@Composable
5158
fun PrimaryButton(
5259
text: String?,
@@ -57,17 +64,31 @@ fun PrimaryButton(
5764
size: ButtonSize = ButtonSize.Large,
5865
enabled: Boolean = true,
5966
fullWidth: Boolean = true,
60-
color: Color = Colors.White16,
67+
color: Color = Colors.White16, // Deprecated: Color customization no longer supported
6168
) {
6269
val contentPadding = PaddingValues(horizontal = size.horizontalPadding.takeIf { text != null } ?: 0.dp)
70+
val interactionSource = remember { MutableInteractionSource() }
71+
val isPressed by interactionSource.collectIsPressedAsState()
72+
val buttonShape = MaterialTheme.shapes.large
73+
6374
Button(
6475
onClick = onClick,
6576
enabled = enabled && !isLoading,
66-
colors = AppButtonDefaults.primaryColors.copy(containerColor = color),
77+
colors = AppButtonDefaults.primaryColors.copy(
78+
containerColor = Color.Transparent,
79+
disabledContainerColor = Color.Transparent
80+
),
6781
contentPadding = contentPadding,
82+
interactionSource = interactionSource,
83+
shape = buttonShape,
6884
modifier = Modifier
6985
.then(if (fullWidth) Modifier.fillMaxWidth() else Modifier)
7086
.requiredHeight(size.height)
87+
.primaryButtonStyle(
88+
isPressed = isPressed,
89+
isEnabled = enabled && !isLoading,
90+
shape = buttonShape
91+
)
7192
.then(modifier)
7293
) {
7394
if (isLoading) {

app/src/main/java/to/bitkit/ui/shared/util/Modifiers.kt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package to.bitkit.ui.shared.util
22

33
import androidx.compose.animation.core.animateFloatAsState
44
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.border
56
import androidx.compose.foundation.clickable
67
import androidx.compose.foundation.interaction.MutableInteractionSource
78
import androidx.compose.foundation.interaction.collectIsPressedAsState
9+
import androidx.compose.foundation.layout.Box
810
import androidx.compose.foundation.layout.WindowInsets
911
import androidx.compose.foundation.layout.fillMaxSize
1012
import androidx.compose.foundation.layout.systemBars
@@ -17,10 +19,18 @@ import androidx.compose.runtime.mutableStateOf
1719
import androidx.compose.runtime.remember
1820
import androidx.compose.ui.Modifier
1921
import androidx.compose.ui.composed
22+
import androidx.compose.ui.draw.clip
23+
import androidx.compose.ui.draw.drawWithContent
24+
import androidx.compose.ui.geometry.Offset
25+
import androidx.compose.ui.geometry.Size
26+
import androidx.compose.ui.draw.shadow
2027
import androidx.compose.ui.graphics.Brush
2128
import androidx.compose.ui.graphics.Color
29+
import androidx.compose.ui.graphics.Shape
2230
import androidx.compose.ui.graphics.graphicsLayer
2331
import androidx.compose.ui.input.pointer.pointerInput
32+
import androidx.compose.ui.unit.dp
33+
import to.bitkit.ui.theme.ButtonGradients
2434
import to.bitkit.ui.theme.Colors
2535

2636
/**
@@ -97,3 +107,59 @@ fun Modifier.screen(
97107
.fillMaxSize()
98108
.then(if (noBackground) Modifier else Modifier.background(MaterialTheme.colorScheme.background))
99109
.then(if (insets == null) Modifier else Modifier.windowInsetsPadding(insets))
110+
111+
fun Modifier.primaryButtonStyle(
112+
isPressed: Boolean,
113+
isEnabled: Boolean,
114+
shape: Shape
115+
): Modifier {
116+
return this
117+
// Step 1: Add shadow (only when enabled)
118+
.then(
119+
if (isEnabled) {
120+
Modifier.shadow(
121+
elevation = 16.dp,
122+
shape = shape,
123+
clip = false // Don't clip content, just add shadow
124+
)
125+
} else {
126+
Modifier
127+
}
128+
)
129+
// Step 2: Clip to shape first
130+
.clip(shape)
131+
// Step 3: Apply gradient background with border overlay
132+
.then(
133+
if (isEnabled) {
134+
Modifier.drawWithContent {
135+
// Draw the main gradient background
136+
val mainBrush = if (isPressed) ButtonGradients.Pressed else ButtonGradients.Active
137+
drawRect(brush = mainBrush)
138+
139+
// Draw top border highlight (2dp gradient fade)
140+
val borderHeight = 2.dp.toPx()
141+
drawRect(
142+
brush = Brush.verticalGradient(
143+
colors = listOf(
144+
Colors.White16,
145+
Color.Transparent
146+
),
147+
startY = 0f,
148+
endY = borderHeight
149+
),
150+
topLeft = Offset(0f, 0f),
151+
size = Size(size.width, borderHeight)
152+
)
153+
154+
// Draw the actual button content on top
155+
drawContent()
156+
}
157+
} else {
158+
Modifier.background(
159+
brush = Brush.verticalGradient(
160+
listOf(Colors.White06, Colors.White06)
161+
)
162+
)
163+
}
164+
)
165+
}

app/src/main/java/to/bitkit/ui/theme/Colors.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package to.bitkit.ui.theme
22

3+
import androidx.compose.ui.graphics.Brush
34
import androidx.compose.ui.graphics.Color
45

56
object Colors {
@@ -55,3 +56,12 @@ object Colors {
5556
val Yellow16 = Yellow.copy(alpha = 0.16f)
5657
val Yellow24 = Yellow.copy(alpha = 0.24f)
5758
}
59+
60+
object ButtonGradients {
61+
val Active = Brush.verticalGradient(
62+
colors = listOf(Color(0xFF2A2A2A), Color(0xFF1C1C1C))
63+
)
64+
val Pressed = Brush.verticalGradient(
65+
colors = listOf(Color(0xFF3A3A3A), Color(0xFF2A2A2A))
66+
)
67+
}

0 commit comments

Comments
 (0)