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 ¶
- func Container() g.Node
- func ErrorScript(message string) string
- func InfoScript(message string) string
- func ShowScript(message, variant string, timeout int) string
- func SuccessScript(message string) string
- func ToastItem() g.Node
- func WarningScript(message string) string
- type Config
- type Option
- type Toast
- func (t *Toast) AlpineComponents() []plugin.AlpineComponent
- func (t *Toast) Directives() []plugin.AlpineDirective
- func (t *Toast) Init(ctx context.Context, registry *plugin.Registry) error
- func (t *Toast) Magics() []plugin.AlpineMagic
- func (t *Toast) Scripts() []plugin.Script
- func (t *Toast) Shutdown(ctx context.Context) error
- func (t *Toast) Stores() []plugin.AlpineStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Container ¶
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 ¶
ErrorScript returns JavaScript to show an error toast.
func InfoScript ¶
InfoScript returns JavaScript to show an info toast.
func ShowScript ¶
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 ¶
SuccessScript returns JavaScript to show a success toast.
func WarningScript ¶
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 ¶
WithDefaultTimeout sets the default timeout in milliseconds.
func WithMaxVisible ¶
WithMaxVisible sets the maximum visible toasts.
type Toast ¶
type Toast struct {
*plugin.PluginBase
// contains filtered or unexported fields
}
Toast plugin implements Alpine and Component plugins.
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) Magics ¶
func (t *Toast) Magics() []plugin.AlpineMagic
Magics returns custom magic properties.
func (*Toast) Stores ¶
func (t *Toast) Stores() []plugin.AlpineStore
Stores returns Alpine stores for toast management.