toast

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package toast provides a toast notification plugin for ForgeUI.

The toast plugin uses Alpine.js stores for state management and provides a clean API for showing temporary notification messages.

Basic Usage

registry := plugin.NewRegistry()
registry.Use(toast.New())

Features

  • Multiple variants (info, success, warning, error)
  • Auto-dismiss with configurable timeout
  • Queue management (max 5 visible)
  • Position options (top-right, bottom-center, etc.)
  • Custom styling per variant

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Container

func Container() g.Node

Container renders the toast container that holds all toasts.

This should be added once to your layout, typically near the end of the body.

Example:

html.Body(
    // ... page content ...
    toast.Container(),
)

func ErrorScript

func ErrorScript(message string) string

ErrorScript returns JavaScript to show an error toast.

func InfoScript

func InfoScript(message string) string

InfoScript returns JavaScript to show an info toast.

func ShowScript

func ShowScript(message, variant string, timeout int) string

ShowScript returns JavaScript to show a toast. Useful for triggering toasts from server-side events.

Example:

htmx.TriggerEventWithDetail(w, "showToast", map[string]any{
    "message": "Item saved!",
    "variant": "success",
})

func SuccessScript

func SuccessScript(message string) string

SuccessScript returns JavaScript to show a success toast.

func ToastItem

func ToastItem() g.Node

ToastItem renders a single toast notification.

func WarningScript

func WarningScript(message string) string

WarningScript returns JavaScript to show a warning toast.

Types

type Config

type Config struct {
	// Position determines where toasts appear
	Position string

	// MaxVisible is the maximum number of toasts to show at once
	MaxVisible int

	// DefaultTimeout is the default auto-dismiss time in milliseconds
	DefaultTimeout int
}

Config holds toast plugin configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default toast configuration.

type Option

type Option func(*Config)

Option configures the toast plugin.

func WithDefaultTimeout

func WithDefaultTimeout(ms int) Option

WithDefaultTimeout sets the default timeout in milliseconds.

func WithMaxVisible

func WithMaxVisible(maxVisible int) Option

WithMaxVisible sets the maximum visible toasts.

func WithPosition

func WithPosition(position string) Option

WithPosition sets the toast position.

type Toast

type Toast struct {
	*plugin.PluginBase
	// contains filtered or unexported fields
}

Toast plugin implements Alpine and Component plugins.

func New

func New(opts ...Option) *Toast

New creates a new Toast plugin with default config.

func (*Toast) AlpineComponents

func (t *Toast) AlpineComponents() []plugin.AlpineComponent

AlpineComponents returns Alpine.data components.

func (*Toast) Directives

func (t *Toast) Directives() []plugin.AlpineDirective

Directives returns custom Alpine directives.

func (*Toast) Init

func (t *Toast) Init(ctx context.Context, registry *plugin.Registry) error

Init initializes the toast plugin.

func (*Toast) Magics

func (t *Toast) Magics() []plugin.AlpineMagic

Magics returns custom magic properties.

func (*Toast) Scripts

func (t *Toast) Scripts() []plugin.Script

Scripts returns scripts needed for the toast plugin.

func (*Toast) Shutdown

func (t *Toast) Shutdown(ctx context.Context) error

Shutdown cleanly shuts down the plugin.

func (*Toast) Stores

func (t *Toast) Stores() []plugin.AlpineStore

Stores returns Alpine stores for toast management.

Jump to

Keyboard shortcuts

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