interactions

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package interactions contains optional client-interaction template helpers.

The core go-partial package does not register these helpers automatically. Applications opt in with:

root.SetFunc(interactions.FuncMap())

Index

Constants

View Source
const (
	// SwapInnerHTML replaces the target element's inner HTML.
	SwapInnerHTML = string(connector.SwapInnerHTML)
	// SwapOuterHTML replaces the target element itself.
	SwapOuterHTML = string(connector.SwapOuterHTML)
)
View Source
const RenderKindInteraction partial.RenderKind = "interaction"

RenderKindInteraction is the renderer kind used for interaction markup.

Variables

This section is empty.

Functions

func Async

func Async(runtime *partial.Runtime, value any, args ...any) template.HTML

Async renders an async interaction. Pass either an endpoint string with optional key/value parameters or an Interaction configured in Go.

go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns the optional interaction template helpers.

func On

func On(runtime *partial.Runtime, value any, args ...any) template.HTML

On renders an interaction that refreshes when a browser event is dispatched. Pass either an Interaction or an event name followed by an endpoint.

go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, event string, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

func Poll

func Poll(runtime *partial.Runtime, value any, args ...any) template.HTML

Poll renders an interaction that refreshes on an interval. When an endpoint string is used, a single extra argument is treated as the interval.

go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

func Prefetch

func Prefetch(runtime *partial.Runtime, value any, args ...any) template.HTML

Prefetch renders a non-visual prefetch hint.

go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

func Refresh

func Refresh(runtime *partial.Runtime, value any, args ...any) template.HTML

Refresh renders a control that explicitly refreshes a target.

go-doc:include go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

func Render

func Render(kind connector.InteractionKind, value any, runtime *partial.Runtime, args ...any) template.HTML

func Reveal

func Reveal(runtime *partial.Runtime, value any, args ...any) template.HTML

Reveal renders an interaction that loads when the element enters the viewport.

go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

func Stage

func Stage(markup ...MarkupRenderer) partial.RenderStage

Stage returns a partial render stage for interaction markup.

func Stream

func Stream(runtime *partial.Runtime, value any, args ...any) template.HTML

Stream renders an SSE-backed interaction placeholder.

go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, endpoint string, params ...any) html/template.HTML go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, interaction github.com/donseba/go-partial/exp/interactions.Interaction) html/template.HTML

Types

type Data

type Data struct {
	Runtime     *partial.Runtime
	Interaction connector.Interaction
	Attrs       map[string]string
}

Data is the render payload for RenderKindInteraction.

type Interaction

type Interaction struct {
	// contains filtered or unexported fields
}

Interaction is an optional builder for connector-aware client interactions. Register values with partial.SetContract("interaction", ...).

func NewAsync

func NewAsync(endpoint string) Interaction

NewAsync creates an async interaction contract value.

func NewOn

func NewOn(event string, endpoint string) Interaction

NewOn creates an event-driven interaction contract value.

func NewPoll

func NewPoll(endpoint string) Interaction

NewPoll creates a polling interaction contract value.

func NewPrefetch

func NewPrefetch(endpoint string) Interaction

NewPrefetch creates a prefetch interaction contract value.

func NewRefresh

func NewRefresh(endpoint string) Interaction

NewRefresh creates a refresh-control interaction contract value.

func NewReveal

func NewReveal(endpoint string) Interaction

NewReveal creates a reveal interaction contract value.

func NewStream

func NewStream(endpoint string) Interaction

NewStream creates an SSE-backed interaction contract value.

func (Interaction) As

func (i Interaction) As(name string) Interaction

As sets the contract name for this interaction.

func (Interaction) ContractName

func (i Interaction) ContractName() string

ContractName returns the contract name used when registering the interaction.

func (Interaction) Every

func (i Interaction) Every(interval time.Duration) Interaction

Every sets the polling interval.

func (Interaction) EveryString

func (i Interaction) EveryString(interval string) Interaction

EveryString sets the polling interval from a raw connector interval string.

func (Interaction) From

func (i Interaction) From(source string) Interaction

From sets the event source option for event-driven interactions.

func (Interaction) ID

func (i Interaction) ID(id string) Interaction

ID sets the element ID used by the rendered interaction.

func (Interaction) Interaction

func (i Interaction) Interaction() connector.Interaction

Interaction returns the connector interaction represented by the builder.

func (Interaction) Option

func (i Interaction) Option(key string, value any) Interaction

Option sets a connector option.

func (Interaction) Param

func (i Interaction) Param(key string, value any) Interaction

Param sets a URL/path parameter used when resolving the endpoint.

func (Interaction) Placeholder

func (i Interaction) Placeholder(placeholder string) Interaction

Placeholder sets the placeholder markup text rendered before content loads.

func (Interaction) Swap

func (i Interaction) Swap(swap string) Interaction

Swap sets the connector swap strategy.

func (Interaction) Target

func (i Interaction) Target(target string) Interaction

Target sets the client-side target selector.

func (Interaction) Trigger

func (i Interaction) Trigger(trigger string) Interaction

Trigger sets the browser event or connector trigger.

type MarkupRenderer

type MarkupRenderer func(runtime *partial.Runtime, interaction connector.Interaction, attrs map[string]string) (template.HTML, error)

MarkupRenderer renders connector interaction attributes into final HTML.

func DefaultMarkupRenderer

func DefaultMarkupRenderer() MarkupRenderer

DefaultMarkupRenderer renders small, unstyled wrappers around connector attributes.

Jump to

Keyboard shortcuts

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