htmx

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package htmx provides HTMX integration helpers including error handling patterns and response utilities for building dynamic web applications.

templ: version: v0.3.1036

templ: version: v0.3.1036

templ: version: v0.3.1036

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CSRFToken

func CSRFToken(token string) templ.Component

CSRFToken renders a hidden input for HTMX forms with CSRF protection

@htmx.CSRFToken("csrf_token_value")

func ConfirmDelete

func ConfirmDelete(hxDelete, hxTarget, confirmMessage string) templ.Component

ConfirmDelete renders a button with a confirmation dialog for destructive actions

@htmx.ConfirmDelete("/delete/123", "#item-123", "Are you sure?")

func GlobalErrorHandling

func GlobalErrorHandling(cfg ErrorHandlingConfig) templ.Component

GlobalErrorHandling renders a comprehensive global HTMX error handling script. Include this once in your base layout, ideally at the end of the body. Requires feedback.ToastContainer on the page for accessible error announcements (aria-live). If ToastContainer is not present, errors are only logged to the console.

@htmx.GlobalErrorHandling(htmx.DefaultErrorHandlingConfig())

func InlineLoadingOverlay

func InlineLoadingOverlay(id string, spinner templ.Component) templ.Component

InlineLoadingOverlay renders a localized loading overlay for HTMX targets. Accepts a spinner component for decoupled loading animation.

@htmx.InlineLoadingOverlay("tc-form-loading", feedback.Spinner(feedback.SpinnerProps{Size: feedback.SpinnerMD, Color: "text-blue-600"}))

func LoadingButton

func LoadingButton(defaultText, loadingText string, spinner templ.Component) templ.Component

LoadingButton renders a button with built-in loading state. Accepts a spinner component for decoupled loading animation.

<button class="btn-primary" hx-post="/save" hx-indicator=".tc-btn-loading">
   @htmx.LoadingButton("Save", "Saving...", feedback.Spinner(feedback.SpinnerProps{Size: feedback.SpinnerSM, Color: "htmx-indicator"}))
</button>

func LoadingIndicator

func LoadingIndicator(spinner templ.Component) templ.Component

LoadingIndicator renders a fixed-position HTMX loading indicator. Accepts a spinner component for decoupled loading animation.

@htmx.LoadingIndicator(feedback.Spinner(feedback.SpinnerProps{Size: feedback.SpinnerLG, Color: "text-blue-600"}))

func SwapOOB

func SwapOOB(selector, swapStyle string) templ.Component

SwapOOB renders an out-of-band swap wrapper for HTMX responses Use this to update multiple elements in a single response

@htmx.SwapOOB("#toast-container", "beforeend") {
   @feedback.Toast(props)
 }

Types

type ErrorHandlingConfig

type ErrorHandlingConfig struct {
	// Nonce is the CSP nonce for inline scripts
	Nonce string
	// MaxErrorHistory is the maximum number of errors to track (default: 10)
	MaxErrorHistory int
	// MaxRetries is the maximum number of retry attempts for server errors (default: 2)
	MaxRetries int
	// RetryDelayMS is the base delay in milliseconds between retries, multiplied by retry count (default: 1000)
	RetryDelayMS int
}

ErrorHandlingConfig configures the global HTMX error handling behavior

func DefaultErrorHandlingConfig

func DefaultErrorHandlingConfig() ErrorHandlingConfig

DefaultErrorHandlingConfig returns sensible defaults for error handling

Jump to

Keyboard shortcuts

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