80 lines
2.8 KiB
Kotlin
80 lines
2.8 KiB
Kotlin
package com.hyperling.roomexample
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.material3.AlertDialog
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TextField
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
import androidx.compose.ui.text.style.TextGeometricTransform
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
@Composable
|
|
fun AddContactDialog(
|
|
state: ContactState,
|
|
onEvent: (ContactEvent) -> Unit,
|
|
modifier: Modifier = Modifier
|
|
) {
|
|
AlertDialog(
|
|
onDismissRequest = {
|
|
onEvent(ContactEvent.HideDialog)
|
|
},
|
|
title = { Text(text = "Add Contact") },
|
|
text = {
|
|
Column (
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
){
|
|
TextField(
|
|
value = state.firstName,
|
|
onValueChange = {
|
|
onEvent(ContactEvent.SetFirstName(it))
|
|
},
|
|
placeholder = {
|
|
Text(text = "First Name")
|
|
},
|
|
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Words)
|
|
)
|
|
TextField(
|
|
value = state.lastName,
|
|
onValueChange = {
|
|
onEvent(ContactEvent.SetLastName(it))
|
|
},
|
|
placeholder = {
|
|
Text(text = "Last Name")
|
|
},
|
|
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Words)
|
|
)
|
|
TextField(
|
|
value = state.phoneNumber,
|
|
onValueChange = {
|
|
onEvent(ContactEvent.SetPhoneNumber(it))
|
|
},
|
|
placeholder = {
|
|
Text(text = "Phone Number")
|
|
},
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone)
|
|
)
|
|
}
|
|
},
|
|
confirmButton = {
|
|
Box(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Button(onClick = {
|
|
onEvent(ContactEvent.SaveContact)
|
|
}) {
|
|
Text(text = "Save")
|
|
}
|
|
}
|
|
}
|
|
)
|
|
} |