Features | Installation | Usage | Custom Icons | Theming | Examples | Contributing
- No External Dependencies: Built with native Go and the
templlibrary - no JavaScript required. - Multiple Toasts: Display several notifications simultaneously.
- Configurable: Control appearance (border, rounded), behavior, and position.
- Variants:
Accent,AccentLight,AccentDark,Filled,Outlined,Soft,Minimal,Brutalist,Retro, andNeon. - Themeable: Style with CSS variables to match your app's design.
- Icon Support: Default SVG icons for common toast types - or use your own.
- Flexible Positioning: Place toasts in any corner of the screen.
- Auto-Dismiss Progress Bar: Visual countdown indicator for auto-dismissed toasts.
- Smooth Animations: Built-in entrance/exit transitions, fully controllable via CSS variables. Can be disabled.
go get github.com/indaco/goaster@latestimport "github.com/indaco/goaster"func HandleSingle(w http.ResponseWriter, r *http.Request) {
toaster := goaster.ToasterDefaults()
templ.Handler(pages.HomePage(toaster)).ServeHTTP(w, r)
}func HandleSingle(w http.ResponseWriter, r *http.Request) {
toaster := goaster.NewToaster(
goaster.WithVariant(goaster.Filled),
goaster.WithBorder(false),
goaster.WithRounded(true),
goaster.WithShowIcon(true),
goaster.WithButton(true),
goaster.WithAutoDismiss(false),
goaster.WithAnimation(true),
goaster.WithProgressBar(false),
goaster.WithPosition(goaster.TopRight),
)
templ.Handler(pages.HomePage(toaster)).ServeHTTP(w, r)
}| Option | Description | Default |
|---|---|---|
WithVariant(Variant) |
Style variant (Accent, Filled, Neon, etc.) |
(none) |
WithBorder(bool) |
Display border around the toast | true |
WithRounded(bool) |
Use rounded corners | true |
WithShowIcon(bool) |
Show the toast icon | true |
WithButton(bool) |
Show the close button | true |
WithAutoDismiss(bool) |
Auto-dismiss after timeout | true |
WithAnimation(bool) |
Enable entrance/exit animations | true |
WithProgressBar(bool) |
Show auto-dismiss progress bar | true |
WithPosition(Position) |
Screen position (TopRight, BottomLeft, etc.) |
BottomRight |
WithIcon(Level, string) |
Custom SVG icon for a toast level | built-in icons |
func HandleSingle(w http.ResponseWriter, r *http.Request) {
toaster := goaster.NewToasterBuilder().
WithVariant(goaster.Neon).
WithBorder(true).
WithRounded(true).
WithAutoDismiss(false).
WithPosition(goaster.TopRight).
Build()
templ.Handler(pages.HomePage(toaster)).ServeHTTP(w, r)
}In your templ template, call the method for the desired level:
templ UserPage(toaster *goaster.Toaster) {
@toaster.Default("Sample message.")
@toaster.Success("Operation completed successfully.")
@toaster.Error("An error occurred.")
@toaster.Info("Here's some information.")
@toaster.Warning("This is a warning message.")
}To display multiple toasts, queue them in your handler:
toaster.PushDefault("Sample message.")
toaster.PushSuccess("Operation completed successfully.")
toaster.PushError("An error occurred.")
toaster.PushInfo("Here's some information.")
toaster.PushWarning("This is a warning message.")Then render them all in your templ page:
templ UserPage(toaster *goaster.Toaster) {
@toaster.RenderAll()
}Override the default icon for any toast level:
toaster := goaster.NewToaster(
goaster.WithIcon(goaster.SuccessLevel, "<svg>...</svg>"),
goaster.WithIcon(goaster.ErrorLevel, "<svg>...</svg>"),
)Theme goaster using CSS custom properties prefixed with gtt. See the CSS Custom Properties reference for full details.
goaster includes HTMLGenerator for use with Go's html/template:
func HandlePage(w http.ResponseWriter, r *http.Request) {
toaster := goaster.ToasterDefaults()
toaster.PushSuccess("Operation completed.")
gen := goaster.NewHTMLGenerator()
toastHTML, err := gen.DisplayAll(r.Context(), toaster)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl.Execute(w, map[string]any{
"Toasts": toastHTML,
})
}See the examples for a complete showcase with setup instructions.
See the Contributing Guide.
This project is licensed under the MIT License - see the LICENSE file for details.
