dialog

package
v0.1.120 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 17 Imported by: 0

README

AlertDialog

Use dialogs to make sure users act on information Two types: basic and full-screen Should be dedicated to completing a single task Can also display information relevant to the task Commonly used to confirm high-risk actions like deleting progress

@Composable
fun AlertDialog(
    onDismissRequest: () -> Unit,
    confirmButton: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    dismissButton: (@Composable () -> Unit)? = null,
    icon: (@Composable () -> Unit)? = null,
    title: (@Composable () -> Unit)? = null,
    text: (@Composable () -> Unit)? = null,
    shape: Shape = AlertDialogDefaults.shape,
    containerColor: Color = AlertDialogDefaults.containerColor,
    iconContentColor: Color = AlertDialogDefaults.iconContentColor,
    titleContentColor: Color = AlertDialogDefaults.titleContentColor,
    textContentColor: Color = AlertDialogDefaults.textContentColor,
    tonalElevation: Dp = AlertDialogDefaults.TonalElevation,
    properties: DialogProperties = DialogProperties()
): Unit

Documentation

Overview

Package dialog contains Material 3 Dialog components.

Reference: [Dialogs](https://m3.material.io/components/dialogs/overview) Specs: [Dialogs Specs](https://m3.material.io/components/dialogs/specs)

Index

Constants

This section is empty.

Variables

View Source
var DialogDefaults = struct {
	// Shape is the default shape for alert dialogs (ExtraLarge - 28dp radius).
	Shape shape.Shape
	// MinWidth is the minimum dialog width.
	MinWidth unit.Dp
	// MaxWidth is the maximum dialog width.
	MaxWidth unit.Dp
	// TonalElevation is the default tonal elevation (0dp for dialogs).
	TonalElevation unit.Dp
	// ShadowElevation is the default shadow elevation (Level 3).
	ShadowElevation unit.Dp
}{
	Shape:           &shape.RoundedCornerShape{Radius: unit.Dp(28)},
	MinWidth:        unit.Dp(280),
	MaxWidth:        unit.Dp(560),
	TonalElevation:  unit.Dp(0),
	ShadowElevation: unit.Dp(6),
}

DialogDefaults contains default values for AlertDialog and BasicAlertDialog styling. Follows Material Design 3 dialog specifications.

View Source
var DialogPadding = struct {
	// All is the uniform padding around dialog content.
	All unit.Dp
	// IconBottom is the spacing below the icon.
	IconBottom unit.Dp
	// TitleBottom is the spacing below the title.
	TitleBottom unit.Dp
	// TextBottom is the spacing below the supporting text.
	TextBottom unit.Dp
	// ButtonSpacing is the spacing between buttons.
	ButtonSpacing unit.Dp
}{
	All:           unit.Dp(24),
	IconBottom:    unit.Dp(16),
	TitleBottom:   unit.Dp(16),
	TextBottom:    unit.Dp(24),
	ButtonSpacing: unit.Dp(8),
}

DialogPadding contains the spacing values for dialog content.

Functions

func ContainerColor added in v0.1.52

func ContainerColor(c api.Composer) graphics.Color

ContainerColor returns the default container color for dialogs.

func DialogButtonRow added in v0.1.52

func DialogButtonRow(buttons ...api.Composable) api.Composable

DialogButtonRow creates a row layout for dialog buttons with proper spacing. Buttons are arranged end-aligned with 8dp spacing between them.

func DialogContent added in v0.1.52

func DialogContent(
	icon api.Composable,
	title api.Composable,
	content api.Composable,
	buttons api.Composable,
) api.Composable

DialogContent creates the internal layout structure for a Material3 dialog. It arranges the icon, title, text, and buttons according to Material Design 3 specifications.

Layout structure:

  • Icon (optional, centered)
  • Title (optional, centered if icon present, start-aligned otherwise)
  • Text (optional, start-aligned)
  • Buttons (end-aligned in a row)

func DialogSurface added in v0.1.52

func DialogSurface(content api.Composable, onDismiss func()) api.Composable

DialogSurface wraps content in a dialog-styled surface with proper Material3 styling (rounded corners, elevation, background color). Used by BasicAlertDialog for custom dialog content.

func IconContentColor added in v0.1.52

func IconContentColor(c api.Composer) graphics.Color

IconContentColor returns the default icon content color for dialogs.

func TextContent added in v0.1.53

func TextContent(content string) api.Composable

func TextContentColor added in v0.1.52

func TextContentColor(c api.Composer) graphics.Color

TextContentColor returns the default supporting text content color for dialogs.

func TitleContentColor added in v0.1.52

func TitleContentColor(c api.Composer) graphics.Color

TitleContentColor returns the default title content color for dialogs.

Types

type Composable

type Composable = api.Composable

func AlertDialog

func AlertDialog(
	onDismissRequest func(),
	confirmButton api.Composable,
	content api.Composable,
	options ...DialogOption,
) Composable

AlertDialog creates a Material3 alert dialog.

The dialog displays optional icon, title, and text content, with a required confirm button and optional dismiss button. All content slots accept composables, allowing for rich custom content.

Note: This dialog should be wrapped in an overlay.Overlay to display with a scrim and handle click-outside-to-dismiss behavior:

overlay.Overlay(
    dialog.AlertDialog(
        onDismissRequest,
        button.Text(onConfirm, "Confirm"),
        dialog.WithTitleText("Delete Item?"),
        dialog.WithTextContent("This action cannot be undone."),
        dialog.WithDismissButton(button.Text(onDismiss, "Cancel")),
    ),
    overlay.WithOnDismiss(onDismissRequest),
)

Parameters:

  • onDismissRequest: Called when the user tries to dismiss the dialog by clicking outside or pressing the back button. This is NOT called when the dismiss button is clicked.
  • confirmButton: A composable for the confirm action button (typically button.Text).
  • options: Optional configuration including icon, title, text, and dismiss button.

func BasicAlertDialog added in v0.1.52

func BasicAlertDialog(
	onDismissRequest func(),
	content api.Composable,
) Composable

BasicAlertDialog creates a bare dialog surface that accepts arbitrary content. Use this when you need full control over the dialog layout.

Note: This dialog should be wrapped in an overlay.Overlay to display with a scrim and handle click-outside-to-dismiss behavior.

type Composer

type Composer = api.Composer

type DialogOption

type DialogOption func(*DialogOptions)

DialogOption is a function that modifies DialogOptions.

func WithDismissButton

func WithDismissButton(button api.Composable) DialogOption

WithDismissButton sets a composable dismiss/cancel button.

func WithIcon

func WithIcon(icon api.Composable) DialogOption

WithIcon sets a composable icon displayed above the title.

func WithModifier

func WithModifier(m ui.Modifier) DialogOption

WithModifier sets the modifier for the dialog.

func WithTitle

func WithTitle(title api.Composable) DialogOption

WithTitle sets a composable title displayed above the text.

func WithTitleText added in v0.1.52

func WithTitleText(title string) DialogOption

WithTitleText is a convenience function that sets the title as a text string with HeadlineSmall typography.

type DialogOptions

type DialogOptions struct {
	// Modifier applied to the dialog container.
	Modifier ui.Modifier
	// Icon composable displayed above the title.
	Icon api.Composable
	// Title composable displayed above the text.
	Title api.Composable
	// DismissButton composable for the dismiss/cancel action.
	DismissButton api.Composable
}

DialogOptions configures an AlertDialog.

func DefaultDialogOptions

func DefaultDialogOptions() DialogOptions

DefaultDialogOptions returns the default dialog options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL