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 ¶
- func CSRFToken(token string) templ.Component
- func ConfirmDelete(hxDelete, hxTarget, confirmMessage string) templ.Component
- func GlobalErrorHandling(cfg ErrorHandlingConfig) templ.Component
- func InlineLoadingOverlay(id string, spinner templ.Component) templ.Component
- func LoadingButton(defaultText, loadingText string, spinner templ.Component) templ.Component
- func LoadingIndicator(spinner templ.Component) templ.Component
- func SwapOOB(selector, swapStyle string) templ.Component
- type ErrorHandlingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CSRFToken ¶
CSRFToken renders a hidden input for HTMX forms with CSRF protection
@htmx.CSRFToken("csrf_token_value")
func ConfirmDelete ¶
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 ¶
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.SpinnerMD, "text-blue-600"))
func LoadingButton ¶
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.SpinnerSM, "htmx-indicator"))
</button>
func LoadingIndicator ¶
LoadingIndicator renders a fixed-position HTMX loading indicator. Accepts a spinner component for decoupled loading animation.
@htmx.LoadingIndicator(feedback.Spinner(feedback.SpinnerLG, "text-blue-600"))
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