toast

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterToastStore

func RegisterToastStore() g.Node

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

func ToastError(title string) string

ToastError is a convenience helper to show an error toast.

func ToastInfo

func ToastInfo(title string) string

ToastInfo is a convenience helper to show an info toast.

func ToastSuccess

func ToastSuccess(title string) string

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

func ToastWarning(title string) string

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

type ToastAction struct {
	Label   string
	OnClick string // Alpine expression
}

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

Jump to

Keyboard shortcuts

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