70 lines
2.5 KiB
Kotlin
70 lines
2.5 KiB
Kotlin
package com.power.ops.components
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.text.KeyboardActions
|
|
import androidx.compose.material3.AlertDialog
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
import androidx.compose.material3.OutlinedTextField
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TextButton
|
|
import androidx.compose.material3.TextFieldDefaults
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.unit.dp
|
|
import com.power.ops.theme.Char600
|
|
import com.power.ops.theme.Primary500
|
|
import com.power.ops.theme.Secondary400
|
|
import com.power.ops.theme.Typography
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
@Composable
|
|
fun Dialog(
|
|
showDialog: Boolean,
|
|
title: String = "请输入",
|
|
defaultValue: String = "",
|
|
onDismiss: () -> Unit,
|
|
onConfirm: (String) -> Unit
|
|
) {
|
|
var inputValue by remember { mutableStateOf(defaultValue) }
|
|
|
|
if (showDialog) {
|
|
AlertDialog(
|
|
onDismissRequest = onDismiss,
|
|
title = {
|
|
Text(text = title, modifier = Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = Typography.titleLarge) },
|
|
text = {
|
|
Column {
|
|
OutlinedTextField(
|
|
value = inputValue,
|
|
onValueChange = { inputValue = it },
|
|
modifier = Modifier
|
|
.padding(top = 14.dp),
|
|
colors = TextFieldDefaults.outlinedTextFieldColors(unfocusedBorderColor = Char600, focusedBorderColor = Primary500),
|
|
keyboardActions = KeyboardActions(onDone = { onConfirm(inputValue) }),
|
|
)
|
|
}
|
|
},
|
|
confirmButton = {
|
|
TextButton(onClick = {
|
|
onConfirm(inputValue)
|
|
onDismiss()
|
|
}) {
|
|
Text(text = "确认")
|
|
}
|
|
},
|
|
dismissButton = {
|
|
TextButton(onClick = onDismiss) {
|
|
Text(text = "取消")
|
|
}
|
|
},
|
|
containerColor = Secondary400
|
|
)
|
|
}
|
|
} |