feedback

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 7 Imported by: 5

Documentation

Overview

templ: version: v0.3.1036

Package feedback provides user feedback components including alerts, toasts, loading overlays, and step indicators.

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

Package feedback provides user feedback components such as alerts, toasts, and loading indicators.

templ: version: v0.3.1036

Index

Examples

Constants

View Source
const (
	AlertSuccess = FeedbackSuccess
	AlertError   = FeedbackError
	AlertWarning = FeedbackWarning
	AlertInfo    = FeedbackInfo
)
View Source
const (
	ToastSuccess = FeedbackSuccess
	ToastError   = FeedbackError
	ToastWarning = FeedbackWarning
	ToastInfo    = FeedbackInfo
)
View Source
const (
	ToastDurationShort  = 3000
	ToastDurationMedium = 5000
	ToastDurationLong   = 8000
)

Default toast durations

Variables

This section is empty.

Functions

func Alert

func Alert(props AlertProps) templ.Component

Alert renders a full-width alert banner

@feedback.Alert(feedback.AlertProps{Title: "Error", Message: "Something went wrong", Type: feedback.AlertError})

The dismiss-button markup is intentionally duplicated in errorpage.ErrorAlert: errorpage must not import feedback (kept minimal for error paths) and no shared markup package exists. JS behaviour is shared via utils.DismissScript().

Example
package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/larsartmann/templ-components/feedback"
)

func main() {
	props := feedback.DefaultAlertProps()
	props.Type = feedback.AlertSuccess
	props.Title = "Success"
	props.Message = "Your changes have been saved."

	var buf bytes.Buffer
	_ = feedback.Alert(props).Render(context.Background(), &buf)
	fmt.Println(buf.String())
}

func InlineError

func InlineError(message string) templ.Component

InlineError renders a compact inline error message for forms

@feedback.InlineError("This field is required")

func InlineLoading

func InlineLoading(message string) templ.Component

InlineLoading renders a compact inline loading indicator

@feedback.InlineLoading("Saving...")

func InlineSuccess

func InlineSuccess(message string) templ.Component

InlineSuccess renders a compact inline success message

@feedback.InlineSuccess("Saved successfully")

func LoadingOverlay

func LoadingOverlay(props LoadingOverlayProps) templ.Component

LoadingOverlay renders a full-screen loading overlay

@feedback.LoadingOverlay(feedback.LoadingOverlayProps{Message: "Loading...", ShowProgress: true, Progress: 45})

func ProgressBar

func ProgressBar(props ProgressBarProps) templ.Component

ProgressBar renders a progress indicator

@feedback.ProgressBar(feedback.ProgressBarProps{Current: 45, Total: 100, Label: "Uploading"})

func Skeleton

func Skeleton(variant SkeletonVariant) templ.Component

Skeleton renders a pulsing placeholder for loading content

@feedback.Skeleton("text")

func SkeletonGroup

func SkeletonGroup(variants []SkeletonVariant) templ.Component

SkeletonGroup renders multiple skeleton placeholders under a single role="status" announcement to avoid redundant screen-reader reads.

@feedback.SkeletonGroup([]string{"title", "text", "text", "text"})

func Spinner

func Spinner(props SpinnerProps) templ.Component

Spinner renders a simple animated loading spinner

@feedback.Spinner(feedback.SpinnerProps{Size: feedback.SpinnerMD, Color: "text-blue-600"})
Example
package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/larsartmann/templ-components/feedback"
)

func main() {
	var buf bytes.Buffer
	_ = feedback.Spinner(feedback.SpinnerProps{Size: feedback.SpinnerMD, Color: "text-blue-600"}).
		Render(context.Background(), &buf)
	fmt.Println(buf.String())
}

func StepIndicator

func StepIndicator(props StepIndicatorProps) templ.Component

StepIndicator renders a step indicator (horizontal or vertical)

@feedback.StepIndicator(feedback.StepIndicatorProps{Steps: []string{"Details", "Review", "Confirm"}, CurrentStep: 1})

func Toast

func Toast(props ToastProps) templ.Component

Toast renders a single toast notification (server-side rendered) For HTMX responses, use ToastContainer + the tcShowToast() JS function

@feedback.Toast(feedback.ToastProps{Message: "Saved!", Type: feedback.ToastSuccess})
Example
package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/larsartmann/templ-components/feedback"
)

func main() {
	props := feedback.DefaultToastProps()
	props.Type = feedback.ToastInfo
	props.Title = "Notification"
	props.Message = "You have a new message."

	var buf bytes.Buffer
	_ = feedback.Toast(props).Render(context.Background(), &buf)
	fmt.Println(buf.String())
}

func ToastContainer

func ToastContainer(nonce string) templ.Component

ToastContainer renders the fixed-position container for toasts Place this once near the top of your body

@feedback.ToastContainer()

Types

type AlertProps

type AlertProps struct {
	utils.BaseProps
	Title       string
	Message     string
	Type        AlertType
	Dismissible bool
}

AlertProps configures an alert banner

func DefaultAlertProps

func DefaultAlertProps() AlertProps

DefaultAlertProps returns sensible defaults

type AlertType

type AlertType = FeedbackType

AlertType represents the visual style of an alert Deprecated: Use FeedbackType instead. Will be removed in v1.0.

type FeedbackType

type FeedbackType string

FeedbackType represents the severity/visual style of a feedback component. Shared by Alert and Toast components.

const (
	FeedbackSuccess FeedbackType = "success"
	FeedbackError   FeedbackType = "error"
	FeedbackWarning FeedbackType = "warning"
	FeedbackInfo    FeedbackType = "info"
)

Feedback severity levels shared by Alert and Toast components.

type LoadingOverlayProps

type LoadingOverlayProps struct {
	utils.BaseProps
	Message      string
	ShowProgress bool
	Progress     int
}

LoadingOverlayProps configures a full-screen loading overlay

func DefaultLoadingOverlayProps

func DefaultLoadingOverlayProps() LoadingOverlayProps

DefaultLoadingOverlayProps returns sensible defaults

type ProgressBarProps

type ProgressBarProps struct {
	utils.BaseProps
	Current       int
	Total         int
	Label         string
	Size          ProgressBarSize
	Color         string
	ShowLabel     bool
	Indeterminate bool
}

ProgressBarProps configures a progress bar

func DefaultProgressBarProps

func DefaultProgressBarProps() ProgressBarProps

DefaultProgressBarProps returns sensible defaults

type ProgressBarSize

type ProgressBarSize string

ProgressBarSize defines the height of a progress bar

const (
	ProgressBarSizeSM ProgressBarSize = "sm"
	ProgressBarSizeMD ProgressBarSize = "md"
	ProgressBarSizeLG ProgressBarSize = "lg"
)

type SkeletonVariant

type SkeletonVariant string

SkeletonVariant defines the shape of a skeleton placeholder

const (
	SkeletonText      SkeletonVariant = "text"
	SkeletonTextShort SkeletonVariant = "text-short"
	SkeletonTitle     SkeletonVariant = "title"
	SkeletonAvatar    SkeletonVariant = "avatar"
	SkeletonImage     SkeletonVariant = "image"
	SkeletonCard      SkeletonVariant = "card"
	SkeletonTableRow  SkeletonVariant = "table-row"
)

type SpinnerProps added in v0.3.0

type SpinnerProps struct {
	utils.BaseProps
	Size  SpinnerSize
	Color string
}

SpinnerProps configures a loading spinner component

func DefaultSpinnerProps added in v0.3.0

func DefaultSpinnerProps() SpinnerProps

DefaultSpinnerProps returns sensible defaults

type SpinnerSize

type SpinnerSize string

SpinnerSize defines the size of a loading spinner

const (
	SpinnerSM SpinnerSize = "sm"
	SpinnerMD SpinnerSize = "md"
	SpinnerLG SpinnerSize = "lg"
)

type StepIndicatorOrientation

type StepIndicatorOrientation string

StepIndicatorOrientation defines the layout direction of a step indicator

const (
	StepHorizontal StepIndicatorOrientation = "horizontal"
	StepVertical   StepIndicatorOrientation = "vertical"
)

type StepIndicatorProps

type StepIndicatorProps struct {
	utils.BaseProps
	Steps       []string
	CurrentStep int
	Orientation StepIndicatorOrientation
}

StepIndicatorProps configures a step/progress indicator

func DefaultStepIndicatorProps

func DefaultStepIndicatorProps() StepIndicatorProps

DefaultStepIndicatorProps returns sensible defaults

type ToastProps

type ToastProps struct {
	utils.BaseProps
	Message  string
	Title    string
	Type     ToastType
	Duration int // milliseconds, 0 for no auto-dismiss
}

ToastProps configures a toast notification

func DefaultToastProps

func DefaultToastProps() ToastProps

DefaultToastProps returns sensible defaults

type ToastType

type ToastType = FeedbackType

ToastType represents the visual style of a toast Deprecated: Use FeedbackType instead. Will be removed in v1.0.

Jump to

Keyboard shortcuts

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