Design kit: add destructive dialog action
This commit is contained in:
parent
1af4bfb1d8
commit
f34fdcc87b
2 changed files with 34 additions and 6 deletions
|
|
@ -38,6 +38,7 @@ fun ConfirmationDialog(
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
submitText: String = stringResource(id = CommonStrings.action_ok),
|
submitText: String = stringResource(id = CommonStrings.action_ok),
|
||||||
cancelText: String = stringResource(id = CommonStrings.action_cancel),
|
cancelText: String = stringResource(id = CommonStrings.action_cancel),
|
||||||
|
destructiveSubmit: Boolean = false,
|
||||||
thirdButtonText: String? = null,
|
thirdButtonText: String? = null,
|
||||||
onCancelClicked: () -> Unit = onDismiss,
|
onCancelClicked: () -> Unit = onDismiss,
|
||||||
onThirdButtonClicked: () -> Unit = {},
|
onThirdButtonClicked: () -> Unit = {},
|
||||||
|
|
@ -49,6 +50,7 @@ fun ConfirmationDialog(
|
||||||
submitText = submitText,
|
submitText = submitText,
|
||||||
cancelText = cancelText,
|
cancelText = cancelText,
|
||||||
thirdButtonText = thirdButtonText,
|
thirdButtonText = thirdButtonText,
|
||||||
|
destructiveSubmit = destructiveSubmit,
|
||||||
onSubmitClicked = onSubmitClicked,
|
onSubmitClicked = onSubmitClicked,
|
||||||
onCancelClicked = onCancelClicked,
|
onCancelClicked = onCancelClicked,
|
||||||
onThirdButtonClicked = onThirdButtonClicked,
|
onThirdButtonClicked = onThirdButtonClicked,
|
||||||
|
|
@ -67,6 +69,7 @@ private fun ConfirmationDialogContent(
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
thirdButtonText: String? = null,
|
thirdButtonText: String? = null,
|
||||||
onThirdButtonClicked: () -> Unit = {},
|
onThirdButtonClicked: () -> Unit = {},
|
||||||
|
destructiveSubmit: Boolean = false,
|
||||||
icon: @Composable (() -> Unit)? = null,
|
icon: @Composable (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
SimpleAlertDialogContent(
|
SimpleAlertDialogContent(
|
||||||
|
|
@ -79,6 +82,7 @@ private fun ConfirmationDialogContent(
|
||||||
onCancelClicked = onCancelClicked,
|
onCancelClicked = onCancelClicked,
|
||||||
thirdButtonText = thirdButtonText,
|
thirdButtonText = thirdButtonText,
|
||||||
onThirdButtonClicked = onThirdButtonClicked,
|
onThirdButtonClicked = onThirdButtonClicked,
|
||||||
|
destructiveSubmit = destructiveSubmit,
|
||||||
icon = icon,
|
icon = icon,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ internal fun SimpleAlertDialogContent(
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: @Composable (() -> Unit)? = null,
|
subtitle: @Composable (() -> Unit)? = null,
|
||||||
submitText: String? = null,
|
submitText: String? = null,
|
||||||
|
destructiveSubmit: Boolean = false,
|
||||||
onSubmitClicked: () -> Unit = {},
|
onSubmitClicked: () -> Unit = {},
|
||||||
thirdButtonText: String? = null,
|
thirdButtonText: String? = null,
|
||||||
onThirdButtonClicked: () -> Unit = {},
|
onThirdButtonClicked: () -> Unit = {},
|
||||||
|
|
@ -76,6 +77,7 @@ internal fun SimpleAlertDialogContent(
|
||||||
title = title,
|
title = title,
|
||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
submitText = submitText,
|
submitText = submitText,
|
||||||
|
destructiveSubmit = destructiveSubmit,
|
||||||
onSubmitClicked = onSubmitClicked,
|
onSubmitClicked = onSubmitClicked,
|
||||||
thirdButtonText = thirdButtonText,
|
thirdButtonText = thirdButtonText,
|
||||||
onThirdButtonClicked = onThirdButtonClicked,
|
onThirdButtonClicked = onThirdButtonClicked,
|
||||||
|
|
@ -92,6 +94,7 @@ internal fun SimpleAlertDialogContent(
|
||||||
title: String? = null,
|
title: String? = null,
|
||||||
subtitle: @Composable (() -> Unit)? = null,
|
subtitle: @Composable (() -> Unit)? = null,
|
||||||
submitText: String? = null,
|
submitText: String? = null,
|
||||||
|
destructiveSubmit: Boolean = false,
|
||||||
onSubmitClicked: () -> Unit = {},
|
onSubmitClicked: () -> Unit = {},
|
||||||
thirdButtonText: String? = null,
|
thirdButtonText: String? = null,
|
||||||
onThirdButtonClicked: () -> Unit = {},
|
onThirdButtonClicked: () -> Unit = {},
|
||||||
|
|
@ -126,6 +129,7 @@ internal fun SimpleAlertDialogContent(
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
size = ButtonSize.Medium,
|
size = ButtonSize.Medium,
|
||||||
onClick = onSubmitClicked,
|
onClick = onSubmitClicked,
|
||||||
|
destructive = destructiveSubmit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -345,8 +349,10 @@ private fun AlertDialogFlowRow(
|
||||||
val arrangement = Arrangement.End
|
val arrangement = Arrangement.End
|
||||||
val mainAxisPositions = IntArray(childrenMainAxisSizes.size) { 0 }
|
val mainAxisPositions = IntArray(childrenMainAxisSizes.size) { 0 }
|
||||||
with(arrangement) {
|
with(arrangement) {
|
||||||
arrange(mainAxisLayoutSize, childrenMainAxisSizes,
|
arrange(
|
||||||
layoutDirection, mainAxisPositions)
|
mainAxisLayoutSize, childrenMainAxisSizes,
|
||||||
|
layoutDirection, mainAxisPositions
|
||||||
|
)
|
||||||
}
|
}
|
||||||
placeables.forEachIndexed { j, placeable ->
|
placeables.forEachIndexed { j, placeable ->
|
||||||
placeable.place(
|
placeable.place(
|
||||||
|
|
@ -385,22 +391,22 @@ internal object DialogContentDefaults {
|
||||||
val containerColor: Color
|
val containerColor: Color
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get()= ElementTheme.colors.bgCanvasDefault
|
get() = ElementTheme.colors.bgCanvasDefault
|
||||||
|
|
||||||
val textContentColor: Color
|
val textContentColor: Color
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get()= ElementTheme.materialColors.onSurfaceVariant
|
get() = ElementTheme.materialColors.onSurfaceVariant
|
||||||
|
|
||||||
val titleContentColor: Color
|
val titleContentColor: Color
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get()= ElementTheme.materialColors.onSurface
|
get() = ElementTheme.materialColors.onSurface
|
||||||
|
|
||||||
val iconContentColor: Color
|
val iconContentColor: Color
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get()= ElementTheme.materialColors.primary
|
get() = ElementTheme.materialColors.primary
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paddings for each of the dialog's parts. Taken from M3 source code.
|
// Paddings for each of the dialog's parts. Taken from M3 source code.
|
||||||
|
|
@ -462,3 +468,21 @@ internal fun DialogWithOnlyMessageAndOkButtonPreview() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview(group = PreviewGroup.Dialogs, name = "Dialog with destructive button")
|
||||||
|
@Composable
|
||||||
|
@Suppress("MaxLineLength")
|
||||||
|
internal fun DialogWithDestructiveButtonPreview() {
|
||||||
|
ElementThemedPreview(showBackground = false) {
|
||||||
|
DialogPreview {
|
||||||
|
SimpleAlertDialogContent(
|
||||||
|
title = "Dialog Title",
|
||||||
|
content = "A dialog with a destructive action",
|
||||||
|
cancelText = "Cancel",
|
||||||
|
submitText = "Delete",
|
||||||
|
destructiveSubmit = true,
|
||||||
|
onCancelClicked = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue