Documentation
¶
Overview ¶
Package toast provides notification system with queue management.
Toasts are temporary notifications that appear on screen, typically at the top or bottom. They support:
- Multiple variants (default, success, error, warning)
- Auto-dismiss with timer
- Manual dismiss
- Stacking/queuing
- Progress bar
- Action buttons
Basic usage:
// In your page, include the Toaster container:
html.Body(
toast.Toaster(),
// ... rest of your content
)
// Trigger a toast notification:
button.Button(
g.Text("Show Toast"),
button.WithAttr(
alpine.XOn("click", "$store.toast.add({title: 'Success', variant: 'success', duration: 3000})"),
),
)
Index ¶
- func RegisterToastStore() g.Node
- func Toast(props ToastProps) g.Node
- func ToastError(title string) string
- func ToastInfo(title string) string
- func ToastSuccess(title string) string
- func ToastWarning(title string) string
- func Toaster(opts ...ToasterOption) g.Node
- type ToastAction
- type ToastProps
- type ToasterOption
- type ToasterProps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterToastStore ¶
RegisterToastStore returns the Alpine store registration script.
Include this once in your page (typically in the head or body) to register the toast Alpine store.
Example:
html.Body(
toast.RegisterToastStore(),
toast.Toaster(),
// ... content
)
func Toast ¶
func Toast(props ToastProps) g.Node
Toast creates a single toast notification.
Note: Typically you won't call this directly. Instead, use the Toaster container and trigger toasts via Alpine store:
$store.toast.add({title: "Success", variant: "success", duration: 3000})
func ToastError ¶
ToastError is a convenience helper to show an error toast.
func ToastSuccess ¶
ToastSuccess is a convenience helper to show a success toast.
Returns an Alpine expression to trigger a success toast. Use with alpine.XOn:
button.Button(
g.Text("Save"),
button.WithAttr(alpine.XOn("click", toast.ToastSuccess("Saved successfully!"))),
)
func ToastWarning ¶
ToastWarning is a convenience helper to show a warning toast.
func Toaster ¶
func Toaster(opts ...ToasterOption) g.Node
Toaster creates the toast notification container.
Place this component in your page layout (typically in the body) to display toast notifications. Toasts are managed via Alpine store.
Example in your layout:
html.Body(
toast.RegisterToastStore(), // Register the Alpine store
toast.Toaster(), // Toast container
// ... rest of your content
)
Trigger toasts from anywhere:
button.Button(
g.Text("Show Success"),
button.WithAttr(
alpine.XOn("click", `
$store.toast.add({
title: 'Success!',
description: 'Your action completed',
variant: 'success',
duration: 3000
})
`),
),
)
Types ¶
type ToastAction ¶
ToastAction defines an action button configuration
type ToastProps ¶
type ToastProps struct {
// Variant specifies the visual style
Variant forgeui.Variant
// Duration is the auto-dismiss time in milliseconds (0 = no auto-dismiss)
Duration int
// Title is the main toast message
Title string
// Description is optional additional text
Description string
// Action is an optional action button
Action *ToastAction
// ShowProgress displays a progress bar for auto-dismiss
ShowProgress bool
// Class adds additional CSS classes
Class string
}
ToastProps defines configuration for a toast notification
type ToasterOption ¶
type ToasterOption func(*ToasterProps)
ToasterOption is a functional option for configuring the toaster
func WithMaxToasts ¶
func WithMaxToasts(maxToasts int) ToasterOption
WithMaxToasts sets the maximum number of visible toasts
func WithPosition ¶
func WithPosition(pos string) ToasterOption
WithPosition sets the toast container position
func WithToasterClass ¶
func WithToasterClass(class string) ToasterOption
WithToasterClass adds custom classes to the toaster
type ToasterProps ¶
type ToasterProps struct {
Position string // "top-left", "top-right", "top-center", "bottom-left", "bottom-right", "bottom-center"
MaxToasts int // Maximum number of visible toasts (0 = unlimited)
Class string
}
ToasterProps defines toaster container configuration