|
| 1 | +package to.bitkit.ui.components |
| 2 | + |
| 3 | +import androidx.compose.foundation.clickable |
| 4 | +import androidx.compose.foundation.layout.Arrangement |
| 5 | +import androidx.compose.foundation.layout.Column |
| 6 | +import androidx.compose.foundation.layout.fillMaxSize |
| 7 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 8 | +import androidx.compose.foundation.layout.padding |
| 9 | +import androidx.compose.foundation.lazy.grid.GridCells |
| 10 | +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid |
| 11 | +import androidx.compose.material3.Text |
| 12 | +import androidx.compose.runtime.Composable |
| 13 | +import androidx.compose.ui.Modifier |
| 14 | +import androidx.compose.ui.platform.testTag |
| 15 | +import androidx.compose.ui.text.TextStyle |
| 16 | +import androidx.compose.ui.text.font.FontWeight |
| 17 | +import androidx.compose.ui.text.style.TextAlign |
| 18 | +import androidx.compose.ui.tooling.preview.Devices |
| 19 | +import androidx.compose.ui.tooling.preview.Preview |
| 20 | +import androidx.compose.ui.unit.dp |
| 21 | +import androidx.compose.ui.unit.sp |
| 22 | +import to.bitkit.ui.theme.AppThemeSurface |
| 23 | +import to.bitkit.ui.theme.Colors |
| 24 | +import to.bitkit.ui.theme.InterFontFamily |
| 25 | + |
| 26 | +@Composable |
| 27 | +fun Keyboard( |
| 28 | + onClick: (String) -> Unit, |
| 29 | + isDecimal: Boolean = true, |
| 30 | + modifier: Modifier = Modifier |
| 31 | +) { |
| 32 | + LazyVerticalGrid( |
| 33 | + verticalArrangement = Arrangement.spacedBy(34.dp), |
| 34 | + columns = GridCells.Fixed(3), |
| 35 | + modifier = modifier |
| 36 | + ) { |
| 37 | + item { KeyboardButton(text = "1", onClick = onClick) } |
| 38 | + item { KeyboardButton(text = "2", onClick = onClick) } |
| 39 | + item { KeyboardButton(text = "3", onClick = onClick) } |
| 40 | + item { KeyboardButton(text = "4", onClick = onClick) } |
| 41 | + item { KeyboardButton(text = "5", onClick = onClick) } |
| 42 | + item { KeyboardButton(text = "6", onClick = onClick) } |
| 43 | + item { KeyboardButton(text = "7", onClick = onClick) } |
| 44 | + item { KeyboardButton(text = "8", onClick = onClick) } |
| 45 | + item { KeyboardButton(text = "9", onClick = onClick) } |
| 46 | + item { KeyboardButton(text = if (isDecimal) "." else "000", onClick = onClick) } |
| 47 | + item { KeyboardButton(text = "0", onClick = onClick) } |
| 48 | + item { KeyboardButton(text = "", onClick = onClick) } |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +@Composable |
| 53 | +private fun KeyboardButton( |
| 54 | + text: String, |
| 55 | + onClick: (String) -> Unit |
| 56 | +) { |
| 57 | + Text( |
| 58 | + text = text, |
| 59 | + style = TextStyle( |
| 60 | + fontFamily = InterFontFamily, |
| 61 | + fontWeight = FontWeight.Normal, |
| 62 | + fontSize = 24.sp, |
| 63 | + lineHeight = 44.sp, |
| 64 | + letterSpacing = (-0.1).sp, |
| 65 | + textAlign = TextAlign.Center, |
| 66 | + color = Colors.White, |
| 67 | + ), |
| 68 | + modifier = Modifier.clickable( |
| 69 | + onClick = { |
| 70 | + onClick(text) |
| 71 | + }, |
| 72 | + onClickLabel = text |
| 73 | + ).testTag("KeyboardButton_$text"), |
| 74 | + ) |
| 75 | +} |
| 76 | + |
| 77 | +@Preview(showBackground = true) |
| 78 | +@Composable |
| 79 | +private fun Preview() { |
| 80 | + AppThemeSurface { |
| 81 | + Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) { |
| 82 | + Keyboard(modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {}) |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +@Preview(showBackground = true) |
| 88 | +@Composable |
| 89 | +private fun Preview2() { |
| 90 | + AppThemeSurface { |
| 91 | + Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) { |
| 92 | + Keyboard(isDecimal = false, modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {}) |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +@Preview(showBackground = true, device = Devices.PIXEL_TABLET) |
| 98 | +@Composable |
| 99 | +private fun Preview3() { |
| 100 | + AppThemeSurface { |
| 101 | + Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) { |
| 102 | + Keyboard(isDecimal = false, modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {}) |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments