Documentation
¶
Overview ¶
Package interactive provides declarative interactivity primitives for GoFastr components. It wraps arbitrary render.HTML with data-fui-* attributes the runtime understands — RPC calls, signal bindings, widget chaining — without writing any JavaScript.
Usage:
interactive.OnClick(btn, interactive.Post("/api/like"),
interactive.OnSuccess(interactive.SetSignal("count", "response")),
)
The package only emits attributes the runtime already handles (data-fui-rpc, data-fui-signal, data-fui-open, etc.) plus new ones added for chaining (data-fui-rpc-open, data-fui-rpc-signals).
Index ¶
- func AnimateOnSignal(html render.HTML, signalName, cssClass string) render.HTML
- func CancelEdit(html render.HTML, signalName string) render.HTML
- func Dropdown(trigger, panel render.HTML) render.HTML
- func EditToggle(html render.HTML, signalName string) render.HTML
- func IncLocal(html render.HTML, signalName string, delta int) render.HTML
- func LiveSearch(form render.HTML, action Action, debounceMs int) render.HTML
- func OnClick(html render.HTML, action Action) render.HTML
- func OnSubmit(html render.HTML, action Action) render.HTML
- func OptimisticUpdate(action Action, idle, success render.HTML) render.HTML
- func Reveal(html render.HTML, animationType string) render.HTML
- func SectionMenu(cfg SectionMenuConfig) render.HTML
- func SectionMenuDrawer(cfg SectionMenuConfig) *widget.Builder
- func SetLocal(html render.HTML, signalName, value string) render.HTML
- func ToggleLocal(html render.HTML, signalName string) render.HTML
- type Action
- type Effect
- type SectionGroup
- type SectionItem
- type SectionMenuConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnimateOnSignal ¶
AnimateOnSignal wraps an element so it gets a CSS class when a signal is truthy and loses it when falsy. Used for CSS transition-driven animations like slide-down, fade, etc.
Panics if signalName or cssClass is empty.
func CancelEdit ¶
CancelEdit wraps an element so clicking it sets a signal to false, closing the inline-edit mode. Typically used on a cancel button inside the edit form.
func EditToggle ¶
EditToggle wraps an element so clicking it toggles a boolean signal. Semantic alias for ToggleLocal used in inline-edit patterns: clicking the text span enters edit mode.
func IncLocal ¶
IncLocal wraps an HTML element so clicking it increments a numeric signal by delta (default 1). No RPC is fired.
func LiveSearch ¶
LiveSearch wraps a form element so input changes fire debounced RPCs. The search input should be the first <input> inside the form. Results are written into the signal named by the action's OnSuccess effect (typically via SetSignal).
debounceMs controls the delay between keystrokes and the RPC call. If debounceMs is 0, a default of 300ms is used.
func OnClick ¶
OnClick wraps an HTML element so that clicking it fires the action. The element must be a clickable element (button, a, etc.).
func OptimisticUpdate ¶
─── Optimistic update ─────────────────────────────────────────────
OptimisticUpdate renders a button that flips to its "success" visual state immediately on click, fires an RPC in the background, and reverts to idle if the RPC fails (non-2xx or network error).
The runtime module optimisticaction.js handles the full lifecycle: idle → pending (optimistic flip) → committed (RPC 2xx) or error → idle.
The caller provides two visual states:
- idle: the default appearance (e.g. "♡ Like")
- success: the committed appearance (e.g. "♥ Liked")
Example:
OptimisticUpdate(
interactive.Post("/api/like/42"),
render.HTML(`<span class="icon">♡</span> Like`),
render.HTML(`<span class="icon">♥</span> Liked`),
)
Produces:
<button data-fui-comp="ui-optimistic-action"
data-state="idle"
data-fui-optimistic-endpoint="/api/like/42"
data-fui-optimistic-method="POST">
<span data-fui-optimistic-idle><span class="icon">♡</span> Like</span>
<span hidden data-fui-optimistic-success><span class="icon">♥</span> Liked</span>
</button>
func Reveal ¶
Reveal wraps an element so it animates in when it enters the viewport. The animationType determines the direction ("fade-up", "fade-in", "slide-left", "slide-right"). Empty → "fade-in". The element renders visible without JS (progressive enhancement); reveal.js adds the hidden state on boot and removes it on intersection.
func SectionMenu ¶
func SectionMenu(cfg SectionMenuConfig) render.HTML
SectionMenu renders the desktop rail plus the mobile trigger button. Mount the matching drawer once with SectionMenuDrawer.
func SectionMenuDrawer ¶
func SectionMenuDrawer(cfg SectionMenuConfig) *widget.Builder
SectionMenuDrawer returns the mobile drawer widget for a SectionMenu — a left-edge preset.Drawer (backdrop + click-outside / Escape close + scroll lock + focus trap) carrying the same menu body. Mount it once at startup:
widget.MountBuilder(router, interactive.SectionMenuDrawer(cfg))
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
Action describes an RPC call triggered by click or submit.
type Effect ¶
type Effect interface {
// contains filtered or unexported methods
}
Effect is something that happens after an RPC response.
func CloseWidget ¶
func CloseWidget() Effect
CloseWidget closes the enclosing widget on RPC success. Maps to data-fui-rpc-close="true".
func Navigate ¶
Navigate does an SPA navigation on RPC success. Maps to data-fui-rpc-navigate="path".
func OpenWidget ¶
OpenWidget opens a named widget when the RPC succeeds. Maps to data-fui-rpc-open="name".
type SectionGroup ¶
type SectionGroup struct {
Label string
Eyebrow string // optional ordinal/kicker shown before the label (e.g. "01")
Items []SectionItem
// Collapsed starts the group closed in the mobile drawer. A group holding
// the active item is forced open regardless. (The desktop rail always
// shows every group expanded.)
Collapsed bool
}
SectionGroup is a labelled, collapsible cluster of items.
type SectionItem ¶
type SectionItem struct {
Label string
Href string
Active bool // marks the current page (aria-current="page" + .is-active)
}
SectionItem is one navigable link in a SectionMenu group.
type SectionMenuConfig ¶
type SectionMenuConfig struct {
// Lead is an optional ungrouped item rendered above the groups
// (e.g. an "Overview" / index link).
Lead *SectionItem
Groups []SectionGroup
// AriaLabel names the nav landmark (e.g. "Documentation sections").
AriaLabel string
// TriggerLabel is the mobile trigger button's text. Default "Menu".
TriggerLabel string
// DrawerName is the widget name shared by the trigger button
// (data-fui-open) and SectionMenuDrawer. Required for the mobile sheet;
// must be unique per distinct menu on a site.
DrawerName string
Class string
ID string
}
SectionMenuConfig configures a SectionMenu and its drawer.