toasts

package
v1.3.25 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// INFO is the info level.
	INFO = "info"
	// SUCCESS is the success level.
	SUCCESS = "success"
	// ERROR is the error level.
	ERROR = "error"
)

Variables

View Source
var DefaultErrorHandler = func(c *fiber.Ctx, err error) error {
	code := fiber.StatusInternalServerError

	var te Toast
	if !errors.As(err, &te) {
		te = Error("there has been an unexpected error")
	}

	var e *fiber.Error // if this is not a toast then use the error message
	if errors.As(err, &e) {
		code = e.Code
		te = Error(e.Message)
	}

	if te.Level != SUCCESS {
		htmx.ReSwap(c, "none")
	}

	te.SetHXTriggerHeader(c)

	c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8)

	return c.Status(code).SendString(err.Error())
}

DefaultErrorHandler is the default error handler for toasts.

Functions

func Success added in v1.3.24

func Success(c *fiber.Ctx, message string, code ...int)

Success returns a success message.

func Toasts added in v1.3.15

func Toasts() htmx.Node

Toast is the toast component.

Types

type Toast

type Toast struct {
	// Level is the level of the toast.
	Level string `json:"level"`
	// Message is the message of the toast.
	Message string `json:"message"`
	// Code is the http status code of the toast.
	Code int `json:"code"`
}

Toast is a message to display to the user.

func Error added in v1.3.23

func Error(message string, code ...int) Toast

Error returns an error message.

func Info added in v1.3.24

func Info(message string, code ...int) Toast

Info returns an info message.

func New added in v1.3.24

func New(level string, message string, code ...int) Toast

New returns a new Toast.

func (Toast) Error added in v1.3.24

func (t Toast) Error() string

Error returns the error message.

func (Toast) SetHXTriggerHeader added in v1.3.24

func (t Toast) SetHXTriggerHeader(c *fiber.Ctx) error

SetHXTriggerHeader sets the HTMX trigger header.

func (Toast) ToJson added in v1.3.24

func (t Toast) ToJson() (string, error)

ToJson returns the JSON representation of the toast.

type ToasterProps added in v1.3.24

type ToasterProps struct {
	// ClassNames are the class names for the toast.
	ClassNames htmx.ClassNames
}

ToasterProps is the properties for the Toaster component.

Jump to

Keyboard shortcuts

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