toast

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

templ: version: v0.2.778

Index

Examples

Constants

View Source
const (
	StyleOK      style.Style = 1 << 8
	StyleWarning style.Style = 1 << 9
	StyleError   style.Style = 1 << 10
)

Variables

This section is empty.

Functions

func C

func C(def D) templ.Component
Example
package main

import (
	"context"
	"os"

	"github.com/jfbus/templ-components/components/toast"
)

func main() {
	c := toast.C(toast.D{
		ContainerID: "toasts",
		Style:       toast.StyleError,
		Content:     "An error occurred !",
	})
	_ = c.Render(context.TODO(), os.Stdout)
}
Output:

func Retarget

func Retarget(ctx context.Context, def D, w http.ResponseWriter, statusCode int) error

Retarget returns a HTMX response that retargets the response to display the response to the toast container, ignoring the initial target. When using error status codes, do not forget to add your error codes to the list of codes for which HTMX swaps the content - https://htmx.org/docs/#requests

Types

type Close

type Close int
const (
	CloseAuto Close = iota
	CloseButton
)

type D

type D struct {

	// ContainerID is the ID of the container.C where the toast will be added.
	//playground:default:"toasts"
	ContainerID string
	// Style defines the toast style.
	Style style.Style
	// Icon defines an optional icon. StyleOK/StyleWarning/StyleError include a default icon
	// that can be overriden.
	Icon string
	// Content defines the text content of the toast.
	// You may also define a custom child content :
	//  @toast.C(toast.D{}){
	//    // your custom content
	//  }
	Content string
	Close   Close
	// AutoCloseDelay defines the close delay (default 5s).
	AutoCloseDelay time.Duration
	// CustomStyle defines a custom style.
	// 	style.Custom{
	// 		"toast":      style.D{style.Add("...")},
	// 		"toast/icon": style.D{style.Add("...")},
	//	}
	CustomStyle style.Custom
	// contains filtered or unexported fields
}

Directories

Path Synopsis
templ: version: v0.2.778
templ: version: v0.2.778

Jump to

Keyboard shortcuts

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