datastar

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

templ: version: v0.3.1070

Package datastar provides Datastar-specific wrappers for Morpheus web components.

templ: version: v0.3.1070

templ: version: v0.3.1070

templ: version: v0.3.1070

templ: version: v0.3.1070

templ: version: v0.3.1070

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComboboxAsync

func ComboboxAsync(opts ComboboxAsyncOpts) templ.Component

ComboboxAsync renders a <neo-combobox async> wired to a Datastar SSE action that fetches its option fragment on every open. On a successful response the server is expected to morph `<neo-datalist id="<ID>-options">` into the listbox; the combobox kit hides the loading clone automatically once options arrive. When Datastar exhausts its retry budget the Failed template is written into the listbox's datalist as a [data-neo-empty-results] child. The kit's mutation observer flips the listbox into empty-results mode, and the kit's CSS suppresses its default "No results" hint when the listbox already carries that attribute deeper down. The failed template then renders verbatim.

Any descendant in the Failed template that carries data-neo-popover-async-retry becomes a retry button. A click aborts any in-flight fetch and calls the combobox's reload(), which re-enters the loading state and re-fires the load action without closing the combobox.

ComboboxAsync requires Datastar's retry mode to be anything other than `never` for the failure swap to fire; `never` short-circuits before Datastar emits `retries-failed`.

func DialogAsync

func DialogAsync(opts DialogAsyncOpts) templ.Component

DialogAsync renders a <neo-dialog> wired to a Datastar SSE action that fetches its body content on every open. The Loading template is wrapped in [data-neo-async-placeholder] so the dialog can restore it after close; on success the server morphs `<div id="<ID>-body">` in place. When Datastar exhausts its retry budget, Failed is swapped into the same body wrapper.

The trigger label is supplied via children. Any descendant in the Failed template that carries data-neo-popover-async-retry becomes a retry button. A click aborts any in-flight fetch, restores loading, and re-fires the action without closing the dialog.

func DrawerAsync

func DrawerAsync(opts DrawerAsyncOpts) templ.Component

DrawerAsync renders a <neo-drawer> wired to a Datastar SSE action that fetches its body content on every open. The Loading template is wrapped in [data-neo-async-placeholder] so the drawer can restore it after close; on success the server morphs `<div id="<ID>-body">` in place. When Datastar exhausts its retry budget, Failed is swapped into the same body wrapper.

The trigger label is supplied via children. Any descendant in the Failed template that carries data-neo-popover-async-retry becomes a retry button. A click aborts any in-flight fetch, restores loading, and re-fires the action without closing the drawer.

func PopoverAsync

func PopoverAsync(opts PopoverAsyncOpts) templ.Component

PopoverAsync renders a <neo-popover> wired to a Datastar SSE action that fetches its body content on every open. The Loading template shows during the request; on a successful response the server is expected to morph the element with id `<ID>-body` (the wrapper around the placeholder). When Datastar exhausts its retry budget the Failed template is swapped in automatically, listening for `datastar-fetch` with `evt.detail.type === 'retries-failed'`.

The trigger label is supplied via children, mirroring neo.Popover. Any descendant in the Loading or Failed template that carries `data-neo-popover-async-retry` becomes a retry button. A click aborts any in-flight fetch, swaps the body back to the loading placeholder, and re-fires the action without closing the popover.

PopoverAsync requires Datastar's retry mode to be anything other than `never` for the failure swap to fire; `never` short-circuits before Datastar emits `retries-failed`.

func SelectAsync

func SelectAsync(opts SelectAsyncOpts) templ.Component

SelectAsync renders a <neo-select async> wired to a Datastar SSE action that fetches its option fragment on every open. On a successful response the server is expected to morph `<neo-datalist id="<ID>-options">` into the listbox; the select kit hides the loading clone automatically once options arrive. When Datastar exhausts its retry budget the Failed template is written into the visible loading clone, while the source loading slot stays untouched for the next retry/reopen.

Any descendant in the Failed template that carries data-neo-popover-async-retry becomes a retry button. A click aborts any in-flight fetch and calls the select's reload(), which re-enters the loading state and re-fires the load action without closing the select.

SelectAsync requires Datastar's retry mode to be anything other than `never` for the failure swap to fire; `never` short-circuits before Datastar emits `retries-failed`.

func SidebarAsync

func SidebarAsync(opts SidebarAsyncOpts) templ.Component

SidebarAsync renders a <neo-sidebar> wired to a Datastar SSE action that fetches its content slot on every open. The Loading template is wrapped in [data-neo-async-placeholder] so the sidebar can restore it after close; on success the server morphs `<div id="<ID>-body">` in place. When Datastar exhausts its retry budget, Failed is swapped into the same content wrapper.

The sidebar has no built-in trigger. Wire an outside button to `document.getElementById('<ID>').toggle()`. Any descendant in the Failed template that carries data-neo-popover-async-retry becomes a retry button. A click aborts any in-flight fetch, restores loading, and re-fires the action without closing the sidebar.

Types

type ComboboxAsyncOpts

type ComboboxAsyncOpts struct {
	neo.ComboboxOpts
	ID  string
	URL string
	// SearchSignal is the Datastar signal the live-search query is
	// mirrored into before each @post. The combobox reports the query
	// in the `neo-combobox-search` event detail; this wrapper copies it
	// onto the signal (the kit writes no framework attribute itself).
	// Empty leaves the query out of the request.
	SearchSignal  string
	Loading       templ.Component
	Failed        templ.Component
	ExtraPostOpts string
}

ComboboxAsyncOpts configures ComboboxAsync.

ID names the host and must be a valid JS identifier, because it is reused as the AbortController signal name. URL is the Datastar action POSTed on every open. Loading renders inside the host's [data-neo-async-placeholder] slot; the combobox kit clones the slot above the listbox on each open. Failed renders in the visible loading clone after Datastar exhausts its retry budget; pass nil for a built-in fallback. ExtraPostOpts is a JS expression body merged into the @post call (typically retry knobs). SearchDebounce coalesces live-search keystrokes before the combobox dispatches `neo-combobox-search`.

On a successful response the server is expected to morph `<neo-datalist id="<ID>-options">` with the rendered options; the combobox kit hides the loading clone automatically once options arrive. The embedded neo.ComboboxOpts carries every base combobox option (placeholder, search, placement, ...); set it as ComboboxOpts: neo.ComboboxOpts{...}. Async is forced on regardless.

type DialogAsyncOpts

type DialogAsyncOpts struct {
	neo.DialogOpts
	ID            string
	URL           string
	Loading       templ.Component
	Failed        templ.Component
	Title         string
	Description   string
	CloseLabel    string
	ExtraPostOpts string
}

DialogAsyncOpts configures DialogAsync.

ID names the dialog host and must be a valid JS identifier, because it is reused as the AbortController signal name and the morph-target id of the body wrapper. URL is the Datastar action POSTed on every open. Loading renders inside the body while the request is in flight; Failed renders when Datastar dispatches `retries-failed` or finishes the action after at least one `error` event. Pass nil for a built-in fallback.

On a successful response the server is expected to morph `<div id="<ID>-body">` with the rendered dialog body. ExtraPostOpts is a JS expression body merged into the @post call, typically retry knobs (e.g. `retry: $_my_retry, retryMaxCount: $_my_retry_max_count`). The embedded neo.DialogOpts carries every base dialog option (open, dismissible); set it as DialogOpts: neo.DialogOpts{...}.

type DrawerAsyncOpts

type DrawerAsyncOpts struct {
	neo.DrawerOpts
	ID            string
	URL           string
	Loading       templ.Component
	Failed        templ.Component
	Title         string
	Description   string
	CloseLabel    string
	ExtraPostOpts string
}

DrawerAsyncOpts configures DrawerAsync.

ID names the drawer host and must be a valid JS identifier, because it is reused as the AbortController signal name and the morph-target id of the body wrapper. URL is the Datastar action POSTed on every open. Loading renders inside the body while the request is in flight; Failed renders when Datastar dispatches `retries-failed` or finishes the action after at least one `error` event. Pass nil for a built-in fallback.

On a successful response the server is expected to morph `<div id="<ID>-body">` with the rendered drawer body. ExtraPostOpts is a JS expression body merged into the @post call, typically retry knobs (e.g. `retry: $_my_retry, retryMaxCount: $_my_retry_max_count`). The embedded neo.DrawerOpts carries every base drawer option (side, open, dismissible, touch-dismiss); set it as DrawerOpts: neo.DrawerOpts{...}.

type PopoverAsyncOpts

type PopoverAsyncOpts struct {
	neo.PopoverOpts
	ID            string
	URL           string
	Loading       templ.Component
	Failed        templ.Component
	ExtraPostOpts string
}

PopoverAsyncOpts configures PopoverAsync.

ID names the popover and must be a valid JS identifier, because it is reused as the AbortController signal name and the morph-target id of the body wrapper. URL is the Datastar action POSTed on every open. Loading renders inside the body while the request is in flight; Failed renders when Datastar dispatches `retries-failed` or finishes the action after at least one `error` event (the latter covers `retry: 'auto' / 'never'` + HTTP error, where Datastar gives up silently). Pass nil for a built-in fallback.

ExtraPostOpts is a JS expression body merged into the @post call, typically retry knobs (e.g. `retry: $_my_retry, retryMaxCount: $_my_retry_max_count`).

The embedded neo.PopoverOpts carries every base popover option (placement, open, screen-offset, flip, trigger-action, ...); set it as PopoverOpts: neo.PopoverOpts{...}.

type SelectAsyncOpts

type SelectAsyncOpts struct {
	neo.SelectOpts
	ID            string
	URL           string
	Loading       templ.Component
	Failed        templ.Component
	ExtraPostOpts string
}

SelectAsyncOpts configures SelectAsync.

ID names the host and must be a valid JS identifier, because it is reused as the AbortController signal name. URL is the Datastar action POSTed on every open. Loading renders inside the host's [data-neo-async-placeholder] slot; the select kit clones the slot above the listbox on each open. Failed renders in the visible loading clone after Datastar exhausts its retry budget; pass nil for a built-in fallback. ExtraPostOpts is a JS expression body merged into the @post call (typically retry knobs).

On a successful response the server is expected to morph `<neo-datalist id="<ID>-options">` with the rendered options; the select kit hides the loading clone automatically once options arrive. The embedded neo.SelectOpts carries every base select option (value, placeholder, typeahead, placement, ...); set it as SelectOpts: neo.SelectOpts{...}. Async is forced on regardless.

type SidebarAsyncOpts

type SidebarAsyncOpts struct {
	neo.SidebarOpts
	ID            string
	URL           string
	Loading       templ.Component
	Failed        templ.Component
	Header        templ.Component
	Footer        templ.Component
	ExtraPostOpts string
}

SidebarAsyncOpts configures SidebarAsync.

ID names the sidebar host and must be a valid JS identifier, because it is reused as the AbortController signal name and the morph-target id of the content slot. URL is the Datastar action POSTed on every open. Loading renders inside the content slot while the request is in flight; Failed renders when Datastar dispatches `retries-failed` or finishes the action after at least one `error` event. Pass nil for a built-in fallback. Header and Footer render in the sidebar's [data-neo-sidebar-header] / [data-neo-sidebar-footer] slots; pass nil to omit.

On a successful response the server is expected to morph `<div id="<ID>-body">` with the rendered content. ExtraPostOpts is a JS expression body merged into the @post call, typically retry knobs. The embedded neo.SidebarOpts carries every base sidebar option (side, overlay, breakpoint, ...); set it as SidebarOpts: neo.SidebarOpts{...}. Set SidebarOpts.Manual so a wide-viewport auto-open doesn't POST before the user asks. The trigger lives outside the wrapper. Wire a button to `document.getElementById('<ID>').toggle()`.

Jump to

Keyboard shortcuts

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