Skip to content

Commit 0efb082

Browse files
committed
feat: Keyboard component
1 parent 50a5c6a commit 0efb082

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed
Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,93 @@
11
package to.bitkit.ui.components
22

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
312
import androidx.compose.runtime.Composable
413
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.text.TextStyle
15+
import androidx.compose.ui.text.font.FontWeight
16+
import androidx.compose.ui.text.style.TextAlign
17+
import androidx.compose.ui.tooling.preview.Preview
18+
import androidx.compose.ui.unit.dp
19+
import androidx.compose.ui.unit.sp
20+
import to.bitkit.ui.theme.AppThemeSurface
21+
import to.bitkit.ui.theme.Colors
22+
import to.bitkit.ui.theme.InterFontFamily
523

624
@Composable
7-
fun Keyboard(modifier: Modifier = Modifier) {
25+
fun Keyboard(
26+
onClick: (String) -> Unit,
27+
isDecimal: Boolean = true,
28+
modifier: Modifier = Modifier
29+
) {
30+
LazyVerticalGrid(
31+
verticalArrangement = Arrangement.spacedBy(34.dp),
32+
columns = GridCells.Fixed(3),
33+
modifier = modifier
34+
) {
35+
item { KeyboardButton(text = "1", onClick = onClick) }
36+
item { KeyboardButton(text = "2", onClick = onClick) }
37+
item { KeyboardButton(text = "3", onClick = onClick) }
38+
item { KeyboardButton(text = "4", onClick = onClick) }
39+
item { KeyboardButton(text = "5", onClick = onClick) }
40+
item { KeyboardButton(text = "6", onClick = onClick) }
41+
item { KeyboardButton(text = "7", onClick = onClick) }
42+
item { KeyboardButton(text = "8", onClick = onClick) }
43+
item { KeyboardButton(text = "9", onClick = onClick) }
44+
item { KeyboardButton(text = if (isDecimal) "." else "000", onClick = onClick) }
45+
item { KeyboardButton(text = "0", onClick = onClick) }
46+
item { KeyboardButton(text = "", onClick = onClick) }
47+
}
48+
}
49+
50+
@Composable
51+
private fun KeyboardButton(
52+
text: String,
53+
onClick: (String) -> Unit
54+
) {
55+
Text(
56+
text = text,
57+
style = TextStyle(
58+
fontFamily = InterFontFamily,
59+
fontWeight = FontWeight.Normal,
60+
fontSize = 24.sp,
61+
lineHeight = 44.sp,
62+
letterSpacing = (-0.1).sp,
63+
textAlign = TextAlign.Center,
64+
color = Colors.White,
65+
),
66+
modifier = Modifier.clickable(
67+
onClick = {
68+
onClick(text)
69+
},
70+
onClickLabel = text
71+
),
72+
)
73+
}
874

75+
@Preview(showBackground = true)
76+
@Composable
77+
private fun Preview() {
78+
AppThemeSurface {
79+
Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
80+
Keyboard(modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {})
81+
}
82+
}
83+
}
84+
85+
@Preview(showBackground = true)
86+
@Composable
87+
private fun Preview2() {
88+
AppThemeSurface {
89+
Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
90+
Keyboard(isDecimal = false, modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {})
91+
}
92+
}
993
}

0 commit comments

Comments
 (0)