All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.github.lyxnx.compose.compodals.popups.PopupDialog.opinionated.kt Maven / Gradle / Ivy

package io.github.lyxnx.compose.compodals.popups

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.NonRestartableComposable
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import io.github.lyxnx.compose.compodals.CompodalProperties
import io.github.lyxnx.compose.compodals.dialogs.DialogSize

/**
 * An opinionated, but still customisable, popup dialog that accepts a title, custom content for the center message area
 * along with neutral, negative, and positive buttons
 *
 * @param onDismiss callback used when the dialog is dismissed. This will be called when the user touches outside the
 * content area and [dismissOnTouchOutside][CompodalProperties.dismissOnTouchOutside] is true
 * @param title the title of the popup
 * @param size the size of the dialog content area
 * @param properties properties to apply to the dialog window
 * @param colors colors to apply to the popup
 * @param shape shape of the dialog content area - the content area will be clipped to this, so any elements that go outside
 * this will not be visible
 * @param contentPadding inner padding to apply to the dialog content
 * @param contentAlignment method of aligning all the content within the popup dialog
 * @param contentSpacing the amount of spacing between each of the [title], [content] and the button row elements
 * @param verticalScrollState scroll state for the vertical direction. Use null to prevent scrolling in this direction
 * @param horizontalScrollState scroll state for the horizontal direction. Use null to prevent scrolling in this direction
 * @param neutralButton neutral button text - eg "Dismiss"
 * @param negativeButton negative button text - eg "Delete"
 * @param positiveButton positive button text - eg "Accept"
 * @param titleStyle the text style to apply to [title]
 * @param buttonSpacing the amount of spacing between each of the [neutralButton], [negativeButton], and [positiveButton]
 * elements (if specified)
 * @param content the center content area of the popup. This could be a simple message or some more complex content such
 * as a loading spinner
 *
 * @see popupDialogButton
 */
@Composable
@NonRestartableComposable
public fun PopupDialog(
    onDismiss: () -> Unit,
    title: AnnotatedString?,
    size: DialogSize = defaultPopupSize(),
    properties: CompodalProperties = CompodalProperties(),
    colors: PopupDialogColors = PopupDialogDefaults.popupColors(),
    shape: Shape = PopupDialogDefaults.DialogShape,
    contentPadding: PaddingValues = PopupDialogDefaults.ContentPadding,
    contentAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    contentSpacing: Dp = PopupDialogDefaults.ContentSpacing,
    verticalScrollState: ScrollState? = null,
    horizontalScrollState: ScrollState? = null,
    neutralButton: (@Composable () -> Unit)? = null,
    negativeButton: (@Composable () -> Unit)? = null,
    positiveButton: (@Composable () -> Unit)? = null,
    titleStyle: TextStyle = PopupDialogDefaults.DialogTitleStyle,
    buttonSpacing: Dp = PopupDialogDefaults.DialogButtonSpacing,
    content: @Composable ColumnScope.() -> Unit
) {
    PopupDialog(
        onDismiss = onDismiss,
        title = title?.let {
            {
                Text(
                    text = title,
                    style = titleStyle,
                )
            }
        },
        size = size,
        properties = properties,
        dimColor = colors.dimColor,
        backgroundColor = colors.backgroundColor,
        shape = shape,
        contentPadding = contentPadding,
        contentAlignment = contentAlignment,
        contentSpacing = contentSpacing,
        verticalScrollState = verticalScrollState,
        horizontalScrollState = horizontalScrollState,
        neutralButton = neutralButton,
        negativeButton = negativeButton,
        positiveButton = positiveButton,
        buttonSpacing = buttonSpacing,
        content = content
    )
}

/**
 * An opinionated, but still customisable, popup dialog that accepts a title, custom content for the center message area
 * along with neutral, negative, and positive buttons
 *
 * @param onDismiss callback used when the dialog is dismissed. This will be called when the user touches outside the
 * content area and [dismissOnTouchOutside][CompodalProperties.dismissOnTouchOutside] is true
 * @param title the title of the popup
 * @param size the size of the dialog content area
 * @param properties properties to apply to the dialog window
 * @param colors colors to apply to the popup
 * @param shape shape of the dialog content area - the content area will be clipped to this, so any elements that go outside
 * this will not be visible
 * @param contentPadding inner padding to apply to the dialog content
 * @param contentAlignment method of aligning all the content within the popup dialog
 * @param contentSpacing the amount of spacing between each of the [title], [content] and the button row elements
 * @param verticalScrollState scroll state for the vertical direction. Use null to prevent scrolling in this direction
 * @param horizontalScrollState scroll state for the horizontal direction. Use null to prevent scrolling in this direction
 * @param neutralButton neutral button text - eg "Dismiss"
 * @param negativeButton negative button text - eg "Delete"
 * @param positiveButton positive button text - eg "Accept"
 * @param titleStyle the text style to apply to [title]
 * @param buttonSpacing the amount of spacing between each of the [neutralButton], [negativeButton], and [positiveButton]
 * elements (if specified)
 * @param content the center content area of the popup. This could be a simple message or some more complex content such
 * as a loading spinner
 *
 * @see popupDialogButton
 */
@Composable
@NonRestartableComposable
public fun PopupDialog(
    onDismiss: () -> Unit,
    title: String?,
    size: DialogSize = defaultPopupSize(),
    properties: CompodalProperties = CompodalProperties(),
    colors: PopupDialogColors = PopupDialogDefaults.popupColors(),
    shape: Shape = PopupDialogDefaults.DialogShape,
    contentPadding: PaddingValues = PopupDialogDefaults.ContentPadding,
    contentAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    contentSpacing: Dp = PopupDialogDefaults.ContentSpacing,
    verticalScrollState: ScrollState? = null,
    horizontalScrollState: ScrollState? = null,
    neutralButton: (@Composable () -> Unit)? = null,
    negativeButton: (@Composable () -> Unit)? = null,
    positiveButton: (@Composable () -> Unit)? = null,
    titleStyle: TextStyle = PopupDialogDefaults.DialogTitleStyle,
    buttonSpacing: Dp = PopupDialogDefaults.DialogButtonSpacing,
    content: @Composable ColumnScope.() -> Unit
) {
    PopupDialog(
        onDismiss = onDismiss,
        title = title?.let { AnnotatedString(it) },
        size = size,
        properties = properties,
        colors = colors,
        shape = shape,
        contentPadding = contentPadding,
        contentAlignment = contentAlignment,
        contentSpacing = contentSpacing,
        verticalScrollState = verticalScrollState,
        horizontalScrollState = horizontalScrollState,
        neutralButton = neutralButton,
        negativeButton = negativeButton,
        positiveButton = positiveButton,
        titleStyle = titleStyle,
        buttonSpacing = buttonSpacing,
        content = content
    )
}

/**
 * An opinionated, but still customisable, popup dialog that accepts a title, custom content for the center message area
 * along with neutral, negative, and positive buttons
 *
 * @param onDismiss callback used when the dialog is dismissed. This will be called when the user touches outside the
 * content area and [dismissOnTouchOutside][CompodalProperties.dismissOnTouchOutside] is true
 * @param title the title of the popup
 * @param message the message of the popup
 * @param size the size of the dialog content area
 * @param properties properties to apply to the dialog window
 * @param colors colors to apply to the popup
 * @param shape shape of the dialog content area - the content area will be clipped to this, so any elements that go outside
 * this will not be visible
 * @param contentPadding inner padding to apply to the dialog content
 * @param contentAlignment method of aligning all the content within the popup dialog
 * @param contentSpacing the amount of spacing between each of the [title], [message] and the button row elements
 * @param verticalScrollState scroll state for the vertical direction. Use null to prevent scrolling in this direction
 * @param horizontalScrollState scroll state for the horizontal direction. Use null to prevent scrolling in this direction
 * @param neutralButton neutral button text - eg "Dismiss"
 * @param negativeButton negative button text - eg "Delete"
 * @param positiveButton positive button text - eg "Accept"
 * @param titleStyle the text style to apply to [title]
 * @param messageStyle the text style to apply to [message]
 * @param buttonSpacing the amount of spacing between each of the [neutralButton], [negativeButton], and [positiveButton]
 * elements (if specified)
 *
 * @see popupDialogButton
 */
@Composable
@NonRestartableComposable
public fun PopupDialog(
    onDismiss: () -> Unit,
    title: AnnotatedString? = null,
    message: AnnotatedString,
    size: DialogSize = defaultPopupSize(),
    properties: CompodalProperties = CompodalProperties(),
    colors: PopupDialogColors = PopupDialogDefaults.popupColors(),
    shape: Shape = PopupDialogDefaults.DialogShape,
    contentPadding: PaddingValues = PopupDialogDefaults.ContentPadding,
    contentAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    contentSpacing: Dp = PopupDialogDefaults.ContentSpacing,
    verticalScrollState: ScrollState? = null,
    horizontalScrollState: ScrollState? = null,
    neutralButton: (@Composable () -> Unit)? = null,
    negativeButton: (@Composable () -> Unit)? = null,
    positiveButton: (@Composable () -> Unit)? = null,
    titleStyle: TextStyle = PopupDialogDefaults.DialogTitleStyle,
    messageStyle: TextStyle = PopupDialogDefaults.DialogMessageStyle,
    buttonSpacing: Dp = PopupDialogDefaults.DialogButtonSpacing
) {
    PopupDialog(
        onDismiss = onDismiss,
        title = title,
        size = size,
        properties = properties,
        colors = colors,
        shape = shape,
        contentPadding = contentPadding,
        contentAlignment = contentAlignment,
        contentSpacing = contentSpacing,
        verticalScrollState = verticalScrollState,
        horizontalScrollState = horizontalScrollState,
        neutralButton = neutralButton,
        negativeButton = negativeButton,
        positiveButton = positiveButton,
        titleStyle = titleStyle,
        buttonSpacing = buttonSpacing
    ) {
        Text(
            text = message,
            style = messageStyle
        )
    }
}

/**
 * An opinionated, but still customisable, popup dialog that accepts a title, custom content for the center message area
 * along with neutral, negative, and positive buttons
 *
 * @param onDismiss callback used when the dialog is dismissed. This will be called when the user touches outside the
 * content area and [dismissOnTouchOutside][CompodalProperties.dismissOnTouchOutside] is true
 * @param title the title of the popup
 * @param message the message of the popup
 * @param size the size of the dialog content area. By default this will wrap the content size
 * @param properties properties to apply to the dialog window
 * @param colors colors to apply to the popup
 * @param shape shape of the dialog content area - the content area will be clipped to this, so any elements that go outside
 * this will not be visible
 * @param contentPadding inner padding to apply to the dialog content
 * @param contentAlignment method of aligning all the content within the popup dialog
 * @param contentSpacing the amount of spacing between each of the [title], [message] and the button row elements
 * @param verticalScrollState scroll state for the vertical direction. Use null to prevent scrolling in this direction
 * @param horizontalScrollState scroll state for the horizontal direction. Use null to prevent scrolling in this direction
 * @param neutralButton neutral button text - eg "Dismiss"
 * @param negativeButton negative button text - eg "Delete"
 * @param positiveButton positive button text - eg "Accept"
 * @param titleStyle the text style to apply to [title]
 * @param messageStyle the text style to apply to [message]
 * @param buttonSpacing the amount of spacing between each of the [neutralButton], [negativeButton], and [positiveButton]
 * elements (if specified)
 *
 * @see popupDialogButton
 */
@Composable
@NonRestartableComposable
public fun PopupDialog(
    onDismiss: () -> Unit,
    title: String? = null,
    message: String,
    size: DialogSize = DialogSize(),
    properties: CompodalProperties = CompodalProperties(),
    colors: PopupDialogColors = PopupDialogDefaults.popupColors(),
    shape: Shape = PopupDialogDefaults.DialogShape,
    contentPadding: PaddingValues = PopupDialogDefaults.ContentPadding,
    contentAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    contentSpacing: Dp = PopupDialogDefaults.ContentSpacing,
    verticalScrollState: ScrollState? = null,
    horizontalScrollState: ScrollState? = null,
    neutralButton:  (@Composable () -> Unit)? = null,
    negativeButton: (@Composable () -> Unit)? = null,
    positiveButton: (@Composable () -> Unit)? = null,
    titleStyle: TextStyle = PopupDialogDefaults.DialogTitleStyle,
    messageStyle: TextStyle = PopupDialogDefaults.DialogMessageStyle,
    buttonSpacing: Dp = PopupDialogDefaults.DialogButtonSpacing
) {
    PopupDialog(
        onDismiss = onDismiss,
        title = title?.let { AnnotatedString(it) },
        message = AnnotatedString(message),
        size = size,
        properties = properties,
        colors = colors,
        shape = shape,
        contentPadding = contentPadding,
        contentAlignment = contentAlignment,
        contentSpacing = contentSpacing,
        verticalScrollState = verticalScrollState,
        horizontalScrollState = horizontalScrollState,
        neutralButton = neutralButton,
        negativeButton = negativeButton,
        positiveButton = positiveButton,
        titleStyle = titleStyle,
        messageStyle = messageStyle,
        buttonSpacing = buttonSpacing
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy