Browse Source

SimpleAlertDialogContent: enforce button submit instead of button cancel and improve API around dialogs.

pull/1726/head
Benoit Marty 11 months ago committed by Benoit Marty
parent
commit
70ea2beaf9
  1. 11
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ErrorDialog.kt
  2. 2
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ListDialog.kt
  3. 6
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/SingleSelectionDialog.kt
  4. 58
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/AlertDialogContent.kt

11
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ErrorDialog.kt

@ -32,17 +32,17 @@ import io.element.android.libraries.ui.strings.CommonStrings
@Composable @Composable
fun ErrorDialog( fun ErrorDialog(
content: String, content: String,
onDismiss: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String = ErrorDialogDefaults.title, title: String = ErrorDialogDefaults.title,
submitText: String = ErrorDialogDefaults.submitText, submitText: String = ErrorDialogDefaults.submitText,
onDismiss: () -> Unit = {},
) { ) {
AlertDialog(modifier = modifier, onDismissRequest = onDismiss) { AlertDialog(modifier = modifier, onDismissRequest = onDismiss) {
ErrorDialogContent( ErrorDialogContent(
title = title, title = title,
content = content, content = content,
submitText = submitText, submitText = submitText,
onSubmitText = onDismiss, onSubmitClicked = onDismiss,
) )
} }
} }
@ -50,17 +50,17 @@ fun ErrorDialog(
@Composable @Composable
private fun ErrorDialogContent( private fun ErrorDialogContent(
content: String, content: String,
onSubmitClicked: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String = ErrorDialogDefaults.title, title: String = ErrorDialogDefaults.title,
submitText: String = ErrorDialogDefaults.submitText, submitText: String = ErrorDialogDefaults.submitText,
onSubmitText: () -> Unit = {},
) { ) {
SimpleAlertDialogContent( SimpleAlertDialogContent(
modifier = modifier, modifier = modifier,
title = title, title = title,
content = content, content = content,
cancelText = submitText, submitText = submitText,
onCancelClicked = onSubmitText, onSubmitClicked = onSubmitClicked,
) )
} }
@ -76,6 +76,7 @@ internal fun ErrorDialogPreview() {
DialogPreview { DialogPreview {
ErrorDialogContent( ErrorDialogContent(
content = "Content", content = "Content",
onSubmitClicked = {},
) )
} }
} }

2
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ListDialog.kt

@ -38,8 +38,8 @@ import io.element.android.libraries.ui.strings.CommonStrings
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun ListDialog( fun ListDialog(
onDismissRequest: () -> Unit,
onSubmit: () -> Unit, onSubmit: () -> Unit,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String? = null, title: String? = null,
subtitle: String? = null, subtitle: String? = null,

6
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/SingleSelectionDialog.kt

@ -77,8 +77,8 @@ fun SingleSelectionDialog(
private fun SingleSelectionDialogContent( private fun SingleSelectionDialogContent(
options: ImmutableList<ListOption>, options: ImmutableList<ListOption>,
onOptionSelected: (Int) -> Unit, onOptionSelected: (Int) -> Unit,
onDismissRequest: () -> Unit,
dismissButtonTitle: String, dismissButtonTitle: String,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String? = null, title: String? = null,
initialSelection: Int? = null, initialSelection: Int? = null,
@ -88,8 +88,8 @@ private fun SingleSelectionDialogContent(
title = title, title = title,
subtitle = subtitle, subtitle = subtitle,
modifier = modifier, modifier = modifier,
cancelText = dismissButtonTitle, submitText = dismissButtonTitle,
onCancelClicked = onDismissRequest, onSubmitClicked = onDismissRequest,
applyPaddingToContents = false, applyPaddingToContents = false,
) { ) {
LazyColumn { LazyColumn {

58
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/AlertDialogContent.kt

@ -53,14 +53,14 @@ import kotlin.math.max
@Composable @Composable
internal fun SimpleAlertDialogContent( internal fun SimpleAlertDialogContent(
content: String, content: String,
cancelText: String, submitText: String,
onCancelClicked: () -> Unit, onSubmitClicked: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String? = null, title: String? = null,
subtitle: @Composable (() -> Unit)? = null, subtitle: @Composable (() -> Unit)? = null,
submitText: String? = null,
destructiveSubmit: Boolean = false, destructiveSubmit: Boolean = false,
onSubmitClicked: () -> Unit = {}, cancelText: String? = null,
onCancelClicked: () -> Unit = {},
thirdButtonText: String? = null, thirdButtonText: String? = null,
onThirdButtonClicked: () -> Unit = {}, onThirdButtonClicked: () -> Unit = {},
applyPaddingToContents: Boolean = true, applyPaddingToContents: Boolean = true,
@ -90,14 +90,14 @@ internal fun SimpleAlertDialogContent(
@Composable @Composable
internal fun SimpleAlertDialogContent( internal fun SimpleAlertDialogContent(
cancelText: String, submitText: String,
onCancelClicked: () -> Unit, onSubmitClicked: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String? = null, title: String? = null,
subtitle: @Composable (() -> Unit)? = null, subtitle: @Composable (() -> Unit)? = null,
submitText: String? = null,
destructiveSubmit: Boolean = false, destructiveSubmit: Boolean = false,
onSubmitClicked: () -> Unit = {}, cancelText: String? = null,
onCancelClicked: () -> Unit = {},
thirdButtonText: String? = null, thirdButtonText: String? = null,
onThirdButtonClicked: () -> Unit = {}, onThirdButtonClicked: () -> Unit = {},
applyPaddingToContents: Boolean = true, applyPaddingToContents: Boolean = true,
@ -121,24 +121,22 @@ internal fun SimpleAlertDialogContent(
onClick = onThirdButtonClicked, onClick = onThirdButtonClicked,
) )
} }
TextButton( if (cancelText != null) {
modifier = Modifier.testTag( TextButton(
if (submitText == null) TestTags.dialogPositive else TestTags.dialogNegative modifier = Modifier.testTag(TestTags.dialogNegative),
), text = cancelText,
text = cancelText,
size = ButtonSize.Medium,
onClick = onCancelClicked,
)
if (submitText != null) {
Button(
modifier = Modifier.testTag(TestTags.dialogPositive),
text = submitText,
enabled = enabled,
size = ButtonSize.Medium, size = ButtonSize.Medium,
onClick = onSubmitClicked, onClick = onCancelClicked,
destructive = destructiveSubmit,
) )
} }
Button(
modifier = Modifier.testTag(TestTags.dialogPositive),
text = submitText,
enabled = enabled,
size = ButtonSize.Medium,
onClick = onSubmitClicked,
destructive = destructiveSubmit,
)
} }
}, },
modifier = modifier, modifier = modifier,
@ -438,8 +436,8 @@ internal fun DialogWithTitleIconAndOkButtonPreview() {
}, },
title = "Dialog Title", title = "Dialog Title",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more", content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
cancelText = "OK", submitText = "OK",
onCancelClicked = {}, onSubmitClicked = {},
) )
} }
} }
@ -454,8 +452,8 @@ internal fun DialogWithTitleAndOkButtonPreview() {
SimpleAlertDialogContent( SimpleAlertDialogContent(
title = "Dialog Title", title = "Dialog Title",
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more", content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
cancelText = "OK", submitText = "OK",
onCancelClicked = {}, onSubmitClicked = {},
) )
} }
} }
@ -469,8 +467,8 @@ internal fun DialogWithOnlyMessageAndOkButtonPreview() {
DialogPreview { DialogPreview {
SimpleAlertDialogContent( SimpleAlertDialogContent(
content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more", content = "A dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made. Learn more",
cancelText = "OK", submitText = "OK",
onCancelClicked = {}, onSubmitClicked = {},
) )
} }
} }
@ -488,7 +486,7 @@ internal fun DialogWithDestructiveButtonPreview() {
cancelText = "Cancel", cancelText = "Cancel",
submitText = "Delete", submitText = "Delete",
destructiveSubmit = true, destructiveSubmit = true,
onCancelClicked = {}, onSubmitClicked = {},
) )
} }
} }

Loading…
Cancel
Save