|
15 | 15 | */
|
16 | 16 | package com.authentication.shrine.ui.common
|
17 | 17 |
|
18 |
| -import androidx.compose.foundation.background |
| 18 | +import androidx.compose.foundation.layout.Arrangement |
| 19 | +import androidx.compose.foundation.layout.Column |
| 20 | +import androidx.compose.foundation.layout.fillMaxWidth |
19 | 21 | import androidx.compose.foundation.layout.padding
|
20 |
| -import androidx.compose.foundation.layout.width |
| 22 | +import androidx.compose.foundation.shape.RoundedCornerShape |
21 | 23 | import androidx.compose.material3.MaterialTheme
|
22 |
| -import androidx.compose.material3.TextField |
| 24 | +import androidx.compose.material3.OutlinedTextField |
| 25 | +import androidx.compose.material3.OutlinedTextFieldDefaults |
| 26 | +import androidx.compose.material3.Text |
23 | 27 | import androidx.compose.runtime.Composable
|
24 | 28 | import androidx.compose.ui.Modifier
|
25 | 29 | import androidx.compose.ui.res.dimensionResource
|
26 |
| -import androidx.compose.ui.res.stringResource |
27 |
| -import androidx.compose.ui.text.input.TextFieldValue |
28 | 30 | import androidx.compose.ui.tooling.preview.Preview
|
29 |
| -import androidx.compose.ui.unit.dp |
30 | 31 | import com.authentication.shrine.R
|
31 | 32 | import com.authentication.shrine.ui.theme.ShrineTheme
|
| 33 | +import com.authentication.shrine.ui.theme.grayBackground |
32 | 34 |
|
33 |
| -/** |
34 |
| - * A custom TextField composable for the Shrine app. |
35 |
| - * |
36 |
| - * @param modifier The modifier to be applied to the TextField. |
37 |
| - * @param value The current value of the TextField. |
38 |
| - * @param onValueChange The callback to be invoked when the TextField value changes. |
39 |
| - */ |
40 | 35 | @Composable
|
41 | 36 | fun ShrineTextField(
|
42 |
| - value: TextFieldValue, |
43 |
| - onValueChange: (TextFieldValue) -> Unit, |
44 |
| - modifier: Modifier = Modifier, |
| 37 | + title: String, |
| 38 | + text: String = "", |
45 | 39 | ) {
|
46 |
| - TextField( |
47 |
| - value = value, |
48 |
| - onValueChange = onValueChange, |
49 |
| - modifier = modifier |
50 |
| - .width(300.dp) |
51 |
| - .background(MaterialTheme.colorScheme.tertiaryContainer) |
52 |
| - .padding(dimensionResource(R.dimen.dimen_standard)), |
53 |
| - ) |
| 40 | + Column( |
| 41 | + modifier = Modifier |
| 42 | + .fillMaxWidth() |
| 43 | + .padding(horizontal = dimensionResource(R.dimen.padding_small)), |
| 44 | + verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_extra_small)), |
| 45 | + ) { |
| 46 | + Text(text = title) |
| 47 | + |
| 48 | + OutlinedTextField( |
| 49 | + value = text, |
| 50 | + onValueChange = { }, |
| 51 | + modifier = Modifier |
| 52 | + .fillMaxWidth(), |
| 53 | + enabled = false, |
| 54 | + shape = RoundedCornerShape(dimensionResource(R.dimen.size_standard)), |
| 55 | + colors = OutlinedTextFieldDefaults.colors( |
| 56 | + focusedBorderColor = MaterialTheme.colorScheme.onBackground, |
| 57 | + errorBorderColor = MaterialTheme.colorScheme.error, |
| 58 | + focusedContainerColor = grayBackground, |
| 59 | + unfocusedContainerColor = grayBackground, |
| 60 | + disabledContainerColor = grayBackground, |
| 61 | + errorContainerColor = grayBackground, |
| 62 | + ), |
| 63 | + ) |
| 64 | + } |
54 | 65 | }
|
55 | 66 |
|
56 |
| -/** |
57 |
| - * A preview of the ShrineTextField composable. |
58 |
| - */ |
59 |
| -@Preview |
| 67 | +@Preview(showSystemUi = true) |
60 | 68 | @Composable
|
61 |
| -private fun ShrineTextFieldPreview() { |
| 69 | +fun ShrineTextFieldPreview() { |
62 | 70 | ShrineTheme {
|
63 | 71 | ShrineTextField(
|
64 |
| - value = TextFieldValue(stringResource(R.string.demo)), |
65 |
| - onValueChange = { }, |
| 72 | + "Full Name", |
| 73 | + "ABC XYZ", |
66 | 74 | )
|
67 | 75 | }
|
68 | 76 | }
|
0 commit comments