Skip to content

Banner

A banner shows a prominent message inside your view, e.g. a hint, a warning or the result of an action. The intent sets the color and the icon. Bind it to a *core.State[bool] with Closeable to let the user dismiss it. To show a short-lived message on top of the view instead, use Banner Messages. All banner types live in package presentation/ui/alert.

Banner

presented := core.AutoState[bool](wnd).Init(func() bool { return true })

VStack(
	alert.Banner("Saved", "Your changes have been saved.").
		Intent(alert.IntentSuccess).
		Closeable(presented),
	alert.Banner("Note", "The system will be updated tonight.").
		Intent(alert.IntentOk),
	alert.Banner("Quota", "You use 90% of your storage.").
		Intent(alert.IntentWarning),
	alert.Banner("Failed", "The file could not be uploaded.").
		Intent(alert.IntentError),
).Gap(L16)

The intents are IntentError (the zero value and therefore the default), IntentOk, IntentWarning and IntentSuccess.

Constructors

ConstructorDescription
func Banner(title, message string) TBannerCreates a banner with the given title and message.

The package also has helpers which return banners: alert.NotFound() core.View shows a “not found” banner and sets the window title, and alert.IfPermissionDenied(wnd core.Window, oneOf ...permission.ID) core.View returns a banner if the user is not logged in or has none of the permissions, otherwise nil.

Methods

MethodDescription
AutoCloseTimeoutOrDefault(d time.Duration) TBannerDeprecated: will be removed because of accessibility concerns.
Closeable(presented *core.State[bool]) TBannerCloseable makes the banner dismissible by binding its visibility to the given state.
Frame(frame ui.Frame) TBannerFrame sets a custom frame (layout constraints) for the banner.
ID(id string) TBannerID sets an optional ID for the banner component.
Intent(intent Intent) TBannerIntent sets the visual intent of the banner (e.g., success, warning, error).
OnClosed(fn func()) TBannerOnClosed sets a callback function that is triggered when the banner is closed.

Related