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 ¶
- Variables
- func ContainerColor(c api.Composer) graphics.Color
- func DialogButtonRow(buttons ...api.Composable) api.Composable
- func DialogContent(icon api.Composable, title api.Composable, content api.Composable, ...) api.Composable
- func DialogSurface(content api.Composable, onDismiss func()) api.Composable
- func IconContentColor(c api.Composer) graphics.Color
- func TextContent(content string) api.Composable
- func TextContentColor(c api.Composer) graphics.Color
- func TitleContentColor(c api.Composer) graphics.Color
- type Composable
- type Composer
- type DialogOption
- type DialogOptions
Constants ¶
This section is empty.
Variables ¶
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.
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
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, onDismiss func(), ) 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
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
TextContentColor returns the default supporting text 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, options ...DialogOption, ) 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 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.