Skip to content

Commit bb56f75

Browse files
authored
Add styling options for delete button (#43)
1 parent 1a80311 commit bb56f75

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## Version 4.0.7 *(15/06/2024)*
4+
5+
- Added `iconTint` and `colors` parameters to `NumberKeyboardAuxButton` to allow
6+
customization of delete button color and styling
7+
38
## Version 4.0.6 *(07/03/2024)*
49

510
- Downgrade to Java 18

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Add the dependency:
2525

2626
```gradle
2727
dependencies {
28-
implementation 'com.github.davidmigloz:number-keyboard:4.0.6'
28+
implementation 'com.github.davidmigloz:number-keyboard:4.0.7'
2929
}
3030
```
3131

@@ -63,6 +63,7 @@ NumberKeyboard(
6363
modifier = buttonModifier,
6464
textStyle = buttonTextStyle,
6565
imageVector = Icons.Rounded.Backspace,
66+
iconTint = MaterialTheme.colorScheme.primary,
6667
clicked = { clickedListener.onRightAuxButtonClicked() }
6768
)
6869
},
@@ -141,6 +142,25 @@ fun NumberKeyboardButton(
141142
}
142143
```
143144

145+
`NumberKeyboardAuxButton` provides the default look for the auxiliary keys. It
146+
now accepts `colors` and `iconTint` so you can customise the delete button and
147+
other icons:
148+
149+
```kotlin
150+
@Composable
151+
fun NumberKeyboardAuxButton(
152+
modifier: Modifier,
153+
textStyle: TextStyle,
154+
shape: Shape = RoundedCornerShape(size = 8.dp),
155+
haptics: HapticFeedback = LocalHapticFeedback.current,
156+
value: String? = null,
157+
imageVector: ImageVector? = null,
158+
clicked: () -> Unit,
159+
colors: ButtonColors = ButtonDefaults.outlinedButtonColors(),
160+
iconTint: Color = LocalContentColor.current
161+
)
162+
```
163+
144164
##### NumberKeyboardListener
145165

146166
This listener is _optional_, but if you want to utilise this. Make sure that the `NumberKeyboardClickedListener` is configured properly when you are building your button layouts.

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
ext {
77
versionMajor = 4 // API Changes, adding big new feature, redesign the App
88
versionMinor = 0 // New features in a backwards-compatible manner
9-
versionPatch = 6 // Backwards-compatible bug fixes
9+
versionPatch = 7 // Backwards-compatible bug fixes
1010
versionClassifier = null // Pre-releases (alpha, beta, rc, SNAPSHOT...)
1111
}
1212

lib/src/main/java/com/davidmiguel/numberkeyboard/NumberKeyboardButton.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ import androidx.compose.foundation.Image
55
import androidx.compose.foundation.layout.RowScope
66
import androidx.compose.foundation.layout.Spacer
77
import androidx.compose.foundation.shape.RoundedCornerShape
8+
import androidx.compose.material3.ButtonColors
9+
import androidx.compose.material3.ButtonDefaults
810
import androidx.compose.material3.OutlinedButton
911
import androidx.compose.material3.Text
1012
import androidx.compose.runtime.Composable
1113
import androidx.compose.ui.Modifier
1214
import androidx.compose.ui.graphics.Color
15+
import androidx.compose.ui.graphics.ColorFilter
1316
import androidx.compose.ui.graphics.Shape
1417
import androidx.compose.ui.graphics.vector.ImageVector
1518
import androidx.compose.ui.hapticfeedback.HapticFeedback
1619
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
1720
import androidx.compose.ui.platform.LocalHapticFeedback
21+
import androidx.compose.ui.platform.LocalContentColor
1822
import androidx.compose.ui.text.TextStyle
1923
import androidx.compose.ui.unit.dp
2024
import com.davidmiguel.numberkeyboard.listener.NumberKeyboardClickedListener
@@ -44,6 +48,19 @@ fun NumberKeyboardButton(
4448
}
4549
}
4650

51+
/**
52+
* Default auxiliary button for [NumberKeyboard]. Can display either text or an icon.
53+
*
54+
* @param modifier button modifier
55+
* @param textStyle style applied to [value] text
56+
* @param shape button shape
57+
* @param haptics haptic feedback implementation
58+
* @param value optional text displayed inside the button
59+
* @param imageVector optional icon displayed when [value] is null or blank
60+
* @param clicked callback invoked when the button is clicked
61+
* @param colors customizable [ButtonColors] for the button
62+
* @param iconTint tint applied to [imageVector]
63+
*/
4764
@Composable
4865
fun NumberKeyboardAuxButton(
4966
modifier: Modifier,
@@ -52,13 +69,16 @@ fun NumberKeyboardAuxButton(
5269
haptics: HapticFeedback = LocalHapticFeedback.current,
5370
value: String? = null,
5471
imageVector: ImageVector? = null,
55-
clicked: () -> Unit
72+
clicked: () -> Unit,
73+
colors: ButtonColors = ButtonDefaults.outlinedButtonColors(),
74+
iconTint: Color = LocalContentColor.current
5675
) {
5776
if (value.isNullOrBlank() && imageVector == null) return
5877
OutlinedButton(
5978
modifier = modifier,
6079
shape = shape,
6180
border = BorderStroke(1.dp, Color.LightGray),
81+
colors = colors,
6282
onClick = {
6383
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
6484
clicked.invoke()
@@ -72,7 +92,8 @@ fun NumberKeyboardAuxButton(
7292
} else if (imageVector != null) {
7393
Image(
7494
imageVector = imageVector,
75-
contentDescription = imageVector.name
95+
contentDescription = imageVector.name,
96+
colorFilter = ColorFilter.tint(iconTint)
7697
)
7798
}
7899
}
@@ -81,4 +102,4 @@ fun NumberKeyboardAuxButton(
81102
@Composable
82103
fun RowScope.NumberKeyboardBlank() {
83104
Spacer(modifier = Modifier.weight(1F))
84-
}
105+
}

0 commit comments

Comments
 (0)