Skip to content

Dialog

A dialog shows content in a modal window above the view, e.g. to confirm a destructive action or to edit a few values. alert.Dialog from package presentation/ui/alert is the preferred way: it renders only while its *core.State[bool] is true, and options add the usual buttons, which close the dialog by setting the state to false. If you need full control over the layout, compose a Custom Dialog instead.

Dialog

presented := core.AutoState[bool](wnd)

VStack(
	alert.Dialog(
		"Delete project",
		Text("Do you really want to delete the project? This cannot be undone."),
		presented,
		alert.Closeable(),
		alert.Cancel(nil),
		alert.Delete(func() {
			// delete the project
		}),
	),
	PrimaryButton(func() { presented.Set(true) }).Title("Delete project"),
)

Constructors

ConstructorDescription
func Dialog(title string, body core.View, isPresented *core.State[bool], opts ...Option) TDialogCreates a dialog with the given title, body, visibility state and options.

Options

Buttons are always placed in the order ok, cancel, delete, save, custom. The save-like options take a callback which returns whether the dialog closes.

OptionDescription
Ok() OptionOk adds a default button that closes the dialog.
Cancel(onCancel func()) OptionAdds a cancel button and closes the dialog on Escape.
Back(onCancel func()) OptionBack adds a button that closes the dialog and triggers the given callback.
Delete(onDelete func()) OptionDelete adds a button that closes the dialog and triggers the given callback.
Save(onSave func() (close bool)) OptionSave adds a button that triggers the callback and optionally closes the dialog.
Create(onSave func() (close bool)) OptionLike Save, with the caption “Create”.
Add(onSave func() (close bool)) OptionLike Save, with the caption “Add”.
Apply(onSave func() (close bool)) OptionLike Save, with the caption “Apply”.
Close(onSave func() (close bool)) OptionLike Save, with the caption “Close”.
Confirm(onSave func() (close bool)) OptionLike Save, with the caption “Confirm”.
Custom(makeCustomView func(close func(closeDlg bool)) core.View) OptionCustom adds a custom footer (button) element.
Closeable() OptionAdds a close icon button and closes the dialog on Escape.
Alignment(alignment ui.Alignment) OptionAlignment sets the alignment of the dialog content.
ModalPadding(padding ui.Padding) OptionModalPadding defines the padding inside the modal dialog.
PreBody(v core.View) OptionPreBody sets a view between title and body.
Width(w ui.Length) OptionWidth sets the dialog width to the given Length.
MinWidth(w ui.Length) OptionMinWidth is probably not what you want.
Large() OptionLarge sets the dialog width to 560dp (35rem).
Larger() OptionLarger sets the dialog width to 880dp (55rem).
XLarge() OptionXLarge sets the dialog width to 1200dp (75rem).
XXLarge() OptionXXLarge sets the dialog width to 1600dp (100rem).
Height(h ui.Length) OptionHeight sets the dialog height to the given Length.
FullHeight() OptionFullHeight makes the dialog take the full available height.

Methods

MethodDescription

Related