Documentation
¶
Overview ¶
Package html provides typed HTML element builders plus additive authoring sugar for GoWebComponents.
The package is designed to pair with the ui package:
func Counter() ui.Node {
count := ui.UseState(0)
increment := ui.UseEvent(func() {
count.Update(func(v int) int { return v + 1 })
})
return html.Div(html.Props{},
html.H1(html.Props{}, html.Text("Counter")),
html.Button(html.Props{OnClick: increment}, html.Text("Increment")),
)
}
html.Props keeps common DOM metadata explicit while still exposing Raw for escape-hatch attributes that do not need first-class fields yet. Use CustomElement when a browser-defined custom element needs explicit attribute-versus-property mapping instead of a single Raw map. Small convenience builders such as HiddenInput help with repetitive form markup without changing the underlying explicit props model. The package also exposes explicit markdown rendering helpers through RenderMarkdown(...) when applications want semantic ui.Node output without adding a second templating runtime.
The additive sugar layer also lives here rather than in ui. The current supported first pass is intentionally conservative:
- existing typed builders such as Div, Button, P, Ul, and Input remain the stable host-element entrypoints
- the companion html/shorthand package exposes mixed-argument host-tag wrappers such as shorthand.Div(...) without changing the typed html.Div(...) signatures
- Children(...) handles mixed child normalization for shorthand composition
- PropsOf(...), WithProps(...), plus Option helpers such as Class(...), ID(...), OnClick(...), Attr(...), and Data(...) reduce repetitive literal Props construction
- Text(...), Textf(...), TextIf(...), When(...), ClassNames(...), If(...), IfElse(...), Unless(...), Map(...), MapKeyed(...), FlatMap(...), FilterMap(...), Join(...), Maybe(...), OrElse(...), Coalesce(...), Switch(...), Case(...), and Default(...) provide additive authoring sugar without introducing JSX, hidden reactivity, or a second runtime model
Children(...) currently accepts ui.Node, string, fmt.Stringer, func() string, nested []ui.Node, nested []string, nested []interface{}, and other slice or array values that recursively contain those forms. Nil values are skipped. Scalar fallbacks are stringified with fmt.Sprint(...).
False branches from If(...), IfElse(...), Unless(...), and TextIf(...) return nil rather than an empty fragment. ClassNames(...) recursively flattens nested class-part slices and drops empty fragments. Keyed list sugar is explicit: MapKeyed(...) writes the computed key onto each realized node rather than hiding reconciliation behavior behind cosmetic naming. Optional helpers stay pointer-based so zero values are not overloaded as absence.
The preferred happy-path import is an ordinary package import such as `html "github.com/monstercameron/GoWebComponents/v4/html"`. Dot-importing html is acceptable only in tiny example packages where collisions are tightly controlled. When one-call mixed props plus children is preferable, use the narrower companion package `github.com/monstercameron/GoWebComponents/html/shorthand`. Primitive DOM composition may use option-style helpers, but business components should continue to use explicit typed props structs.
Index ¶
- func A(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Abbr(parseProps Props, parseChildren ...ui.Node) ui.Node
- func ApplyPropOptions(parseProps *Props, parseOptions ...PropOption)
- func Article(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Aside(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Audio(parseProps Props, parseChildren ...ui.Node) ui.Node
- func B(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Blockquote(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Body(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Br(parseProps Props) ui.Node
- func Button(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Canvas(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Caption(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Children(parseValues ...any) []ui.Node
- func Circle(parseProps Props) ui.Node
- func ClassMap(parseValues map[string]bool) string
- func ClassNames(parseParts ...any) string
- func Coalesce[T any](parseValues ...*T) *T
- func Code(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Col(parseProps Props) ui.Node
- func Colgroup(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Cond(parseBranches ...CondBranch) ui.Node
- func CustomElement(parseName string, parseProps CustomElementProps, parseChildren ...ui.Node) ui.Node
- func DNSPrefetch(parseHref string) ui.Node
- func Datalist(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Debounce(parseDelay time.Duration, parseCallback any) any
- func Defs(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Del(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Details(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Dialog(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Div(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Em(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Fieldset(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Figcaption(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Figure(parseProps Props, parseChildren ...ui.Node) ui.Node
- func FilterMap[T any](parseItems []T, render func(T) (ui.Node, bool)) []ui.Node
- func FlatMap[T any](parseItems []T, render func(T) []ui.Node) []ui.Node
- func Footer(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Form(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Fragment(parseChildren ...ui.Node) ui.Node
- func G(parseProps Props, parseChildren ...ui.Node) ui.Node
- func H1(parseProps Props, parseChildren ...ui.Node) ui.Node
- func H2(parseProps Props, parseChildren ...ui.Node) ui.Node
- func H3(parseProps Props, parseChildren ...ui.Node) ui.Node
- func H4(parseProps Props, parseChildren ...ui.Node) ui.Node
- func H5(parseProps Props, parseChildren ...ui.Node) ui.Node
- func H6(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Head(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Header(parseProps Props, parseChildren ...ui.Node) ui.Node
- func HiddenInput(parseName string, parseValue string) ui.Node
- func Hr(parseProps Props) ui.Node
- func Html(parseProps Props, parseChildren ...ui.Node) ui.Node
- func I(parseProps Props, parseChildren ...ui.Node) ui.Node
- func If(isCondition bool, parseNode ui.Node) ui.Node
- func IfElse(isCondition bool, parseWhenTrue ui.Node, parseWhenFalse ui.Node) ui.Node
- func Iframe(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Img(parseProps Props) ui.Node
- func Input(parseProps Props) ui.Node
- func Ins(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Join(parseSeparator ui.Node, parseNodes ...ui.Node) []ui.Node
- func Kbd(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Label(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Legend(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Li(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Line(parseProps Props) ui.Node
- func Link(parseProps Props) ui.Node
- func Main(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Map[T any](parseItems []T, render func(T) ui.Node) []ui.Node
- func MapIndexed[T any](parseItems []T, render func(parseIndex int, parseItem T) ui.Node) []ui.Node
- func MapKeyed[T any](parseItems []T, parseKey func(T) any, render func(T) ui.Node) []ui.Node
- func MapKeyedComponent[T any](parseItems []T, parseKey func(T) any, render func(T) ui.Node) []ui.Node
- func MapKeyedIndexed[T any](parseItems []T, parseKey func(parseIndex int, parseItem T) any, ...) []ui.Node
- func MapKeyedOr[T any](parseItems []T, parseKey func(T) any, render func(T) ui.Node, ...) ui.Node
- func MapOr[T any](parseItems []T, render func(T) ui.Node, parseFallback ui.Node) ui.Node
- func Mark(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Markdown(parseSource string, parseOptions ...MarkdownRenderOptions) []ui.Node
- func Maybe[T any](parseValue *T, render func(T) ui.Node) ui.Node
- func MaybeOr[T any](parseValue *T, render func(T) ui.Node, parseFallback ui.Node) ui.Node
- func Meta(parseProps Props) ui.Node
- func Meter(parseProps Props, parseChildren ...ui.Node) ui.Node
- func ModulePreload(parseHref string) ui.Node
- func Nav(parseProps Props, parseChildren ...ui.Node) ui.Node
- func NoScript(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Ol(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Optgroup(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Option(parseProps Props, parseChildren ...ui.Node) ui.Node
- func OrElse[T any](parseValue *T, parseFallback T) T
- func Output(parseProps Props, parseChildren ...ui.Node) ui.Node
- func P(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Passive(parseCallback any) any
- func Path(parseProps Props) ui.Node
- func Picture(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Polygon(parseProps Props) ui.Node
- func Polyline(parseProps Props) ui.Node
- func Pre(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Preconnect(parseHref string) ui.Node
- func Prefetch(parseHref string) ui.Node
- func Preload(parseHref, parseAs string) ui.Node
- func Prevent(parseCallback any) any
- func Progress(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Range(parseCount int, render func(parseIndex int) ui.Node) []ui.Node
- func RawHTML(parseMarkup string) []ui.Node
- func RawHTMLUnsafe(parseMarkup string) []ui.Node
- func RawHTMLWith(parseMarkup string, parsePolicy sanitize.Policy) []ui.Node
- func Rect(parseProps Props) ui.Node
- func RenderMarkdown(parseMarkdown string, parseOptions ...MarkdownRenderOptions) []ui.Node
- func Repeat(parseCount int, parseNode ui.Node) []ui.Node
- func ResolveMarkdownHref(parseSourcePath, parseDestination string) string
- func SanitizeMarkdownHref(parseDestination string, parseAllowed []string) string
- func Script(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Section(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Select(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Show(isCondition bool, parseNode ui.Node) ui.Node
- func Small(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Source(parseProps Props) ui.Node
- func Span(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Stop(parseCallback any) any
- func Strong(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Sub(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Summary(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Sup(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Svg(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Switch(parseValue any, parseBranches ...SwitchBranch) ui.Node
- func Table(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Tag(parseName string, parseProps Props, parseChildren ...ui.Node) ui.Node
- func Tbody(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Td(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Text(parseContent any) ui.Node
- func TextIf(isCondition bool, parseContent any) ui.Node
- func TextLines(parseText string) []ui.Node
- func Textarea(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Textf(format string, parseArgs ...any) ui.Node
- func Tfoot(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Th(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Thead(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Throttle(parseInterval time.Duration, parseCallback any) any
- func Time(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Tr(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Track(parseProps Props) ui.Node
- func U(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Ul(parseProps Props, parseChildren ...ui.Node) ui.Node
- func Unless(isCondition bool, parseNode ui.Node) ui.Node
- func Use(parseProps Props) ui.Node
- func Video(parseProps Props, parseChildren ...ui.Node) ui.Node
- func When(isCondition bool, parseClassName string) string
- func WithChildren(parseNode ui.Node, parseChildren ...ui.Node) ui.Node
- func WithKey(parseNode ui.Node, parseKey any) ui.Node
- type Binding
- type CondBranch
- type CustomElementProps
- type DataAttribute
- type MarkdownClasses
- type MarkdownRenderOptions
- type PropOption
- func Accept(parseValue string) PropOption
- func Alt(parseValue string) PropOption
- func Aria(parseName string, parseValue string) PropOption
- func AriaSet(parseValues map[string]string) PropOption
- func Attr(parseKey string, parseValue any) PropOption
- func AttrIf(isCondition bool, parseKey string, parseValue any) PropOption
- func Attrs(parseValues map[string]any) PropOption
- func AutoComplete(parseValue string) PropOption
- func AutoFocus(parseValues ...bool) PropOption
- func Bind(parseState ui.State[string]) PropOption
- func BindFunc(parseGet func() string, parseSet func(string)) PropOption
- func BindTo(parseTarget Binding) PropOption
- func Checked(parseValues ...bool) PropOption
- func Class(parseValue string) PropOption
- func ClassIf(isCondition bool, parseClass string) PropOption
- func ColSpan(parseValue int) PropOption
- func Cols(parseValue int) PropOption
- func Data(parseName string, parseValue string) PropOption
- func Dataset(parseValues map[string]string) PropOption
- func Dir(parseValue string) PropOption
- func Disabled(parseValues ...bool) PropOption
- func DisabledIf(isCondition bool) PropOption
- func For(parseValue string) PropOption
- func Height(parseValue string) PropOption
- func Hidden(parseValues ...bool) PropOption
- func Href(parseValue string) PropOption
- func ID(parseValue string) PropOption
- func Lang(parseValue string) PropOption
- func Loading(parseValue string) PropOption
- func Max(parseValue string) PropOption
- func MaxLength(parseValue int) PropOption
- func Min(parseValue string) PropOption
- func MinLength(parseValue int) PropOption
- func Multiple(parseValues ...bool) PropOption
- func Name(parseValue string) PropOption
- func OnAnimationEnd(parseCallback any) PropOption
- func OnBlur(parseCallback any) PropOption
- func OnChange(parseCallback any) PropOption
- func OnClick(parseCallback any) PropOption
- func OnClickParallel(parseSlotID string, parseCallback any) PropOption
- func OnContextMenu(parseCallback any) PropOption
- func OnDoubleClick(parseCallback any) PropOption
- func OnDragEnd(parseCallback any) PropOption
- func OnDragOver(parseCallback any) PropOption
- func OnDragStart(parseCallback any) PropOption
- func OnDrop(parseCallback any) PropOption
- func OnError(parseCallback any) PropOption
- func OnFocus(parseCallback any) PropOption
- func OnInput(parseCallback any) PropOption
- func OnKeyDown(parseCallback any) PropOption
- func OnKeyUp(parseCallback any) PropOption
- func OnLoad(parseCallback any) PropOption
- func OnMouseDown(parseCallback any) PropOption
- func OnMouseEnter(parseCallback any) PropOption
- func OnMouseLeave(parseCallback any) PropOption
- func OnMouseUp(parseCallback any) PropOption
- func OnPointerDown(parseCallback any) PropOption
- func OnPointerMove(parseCallback any) PropOption
- func OnPointerUp(parseCallback any) PropOption
- func OnScroll(parseCallback any) PropOption
- func OnSubmit(parseCallback any) PropOption
- func OnTouchEnd(parseCallback any) PropOption
- func OnTouchMove(parseCallback any) PropOption
- func OnTouchStart(parseCallback any) PropOption
- func OnTransitionEnd(parseCallback any) PropOption
- func OnWheel(parseCallback any) PropOption
- func Open(parseValues ...bool) PropOption
- func Pattern(parseValue string) PropOption
- func Placeholder(parseValue string) PropOption
- func ReadOnly(parseValues ...bool) PropOption
- func ReadOnlyIf(isCondition bool) PropOption
- func Ref(parseRef ui.DOMRef) PropOption
- func Rel(parseValue string) PropOption
- func Required(parseValues ...bool) PropOption
- func Role(parseValue string) PropOption
- func RowSpan(parseValue int) PropOption
- func Rows(parseValue int) PropOption
- func Selected(parseValues ...bool) PropOption
- func SelectedIf(isCondition bool) PropOption
- func Src(parseValue string) PropOption
- func Step(parseValue string) PropOption
- func Style(parseValues map[string]string) PropOption
- func StyleIf(isCondition bool, parseValues map[string]string) PropOption
- func StyleVar(parseName string, parseValue string) PropOption
- func TabIndex(parseValue int) PropOption
- func Target(parseValue string) PropOption
- func Title(parseValue string) PropOption
- func Type(parseValue string) PropOption
- func Value(parseValue string) PropOption
- func Width(parseValue string) PropOption
- type Props
- type SwitchBranch
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyPropOptions ¶
func ApplyPropOptions(parseProps *Props, parseOptions ...PropOption)
ApplyPropOptions applies options to parseProps in place, without the defensive clone WithProps performs. Callers must own parseProps (and any maps it references): accumulation loops that build one fresh Props per element use this to avoid paying a full Props clone per option argument.
func Blockquote ¶
Blockquote creates a blockquote element.
func Children ¶
Children normalizes mixed shorthand child inputs into the existing []ui.Node builder contract.
func ClassNames ¶
ClassNames joins class fragments while dropping empty values and normalizing whitespace.
func Coalesce ¶
func Coalesce[T any](parseValues ...*T) *T
Coalesce returns the first non-nil pointer in order.
func Cond ¶
func Cond(parseBranches ...CondBranch) ui.Node
Cond returns the node of the first branch whose condition is true, otherwise the Otherwise branch, otherwise nil. It fills the gap between IfElse (two-way) and Switch (value-equality) for three-or-more boolean conditions.
func CustomElement ¶
func CustomElement(parseName string, parseProps CustomElementProps, parseChildren ...ui.Node) ui.Node
CustomElement creates a browser-defined custom element with explicit attribute and property channels.
func DNSPrefetch ¶
DNSPrefetch creates a link[rel=dns-prefetch] element for the given href.
func Figcaption ¶
Figcaption creates a figcaption element.
func HiddenInput ¶
HiddenInput creates a hidden input element with the given name and value.
func MapIndexed ¶
MapIndexed renders a typed slice into ui.Node values with the element index, preserving order. It is Map with the index threaded into the render callback.
func MapKeyedComponent ¶
func MapKeyedComponent[T any](parseItems []T, parseKey func(T) any, render func(T) ui.Node) []ui.Node
MapKeyedComponent renders each item as its own keyed component (its own fiber), so the render func may legally use hooks and On* event handlers directly — including UseState/UseEvent — without the "no hooks in a variable-length loop" gotcha (G1). It is the sanctioned alternative to hand-extracting a row component: per-row hook state is isolated and persists across renders by key.
MapKeyedComponent(rows, func(r Row) any { return r.ID }, func(r Row) ui.Node {
open := ui.UseState(false) // legal: own fiber
return Button(OnClick(func() { open.Set(!open.Get()) }), r.Name)
})
func MapKeyedIndexed ¶
func MapKeyedIndexed[T any](parseItems []T, parseKey func(parseIndex int, parseItem T) any, render func(parseIndex int, parseItem T) ui.Node) []ui.Node
MapKeyedIndexed renders a typed slice into keyed ui.Node values with the element index threaded into both the key and the render callback.
func MapKeyedOr ¶
func MapKeyedOr[T any](parseItems []T, parseKey func(T) any, render func(T) ui.Node, parseFallback ui.Node) ui.Node
MapKeyedOr renders the keyed mapped slice as a fragment when items exist, otherwise the fallback node. It is MapOr with per-item reconciliation keys, for empty-state lists whose rows must keep identity across reorders and removals.
func MapOr ¶
MapOr renders the mapped slice as a fragment when items exist, otherwise the fallback node. It removes the hand-written IfElse(len==0, empty, Map(...)) empty-state idiom.
func Markdown ¶
func Markdown(parseSource string, parseOptions ...MarkdownRenderOptions) []ui.Node
Markdown renders Markdown source into nodes via RenderMarkdown, exposing it on the shorthand surface. Untrusted source is still scheme-sanitized; raw HTML is never emitted (route untrusted HTML through the sanitize package instead).
func MaybeOr ¶
MaybeOr renders from the pointed value when present, otherwise the fallback node. It is Maybe with an else branch.
func ModulePreload ¶
ModulePreload creates a link[rel=modulepreload] element for module scripts.
func OrElse ¶
func OrElse[T any](parseValue *T, parseFallback T) T
OrElse returns the pointed value when present, otherwise the fallback.
func Passive ¶
Passive marks an event callback to be attached as a passive listener when the runtime adapter supports listener options.
func Preconnect ¶
Preconnect creates a link[rel=preconnect] element for the given href.
func Prevent ¶
Prevent wraps a callback so the event default is prevented before callback execution.
func Range ¶
Range renders parseCount nodes, invoking render with each index from 0 to parseCount-1. A non-positive count renders nothing.
func RawHTML ¶
RawHTML parses sanitized markup into nodes. Safe for untrusted input.
Div(html.RawHTML(userSuppliedMarkdownHTML)...)
func RawHTMLUnsafe ¶
RawHTMLUnsafe parses markup WITHOUT sanitization. The content is still built as a real node tree (no innerHTML), but nothing is stripped — only pass markup you fully control (e.g. a bundled SVG icon). The name is intentionally alarming so its use is greppable in review.
func RawHTMLWith ¶
RawHTMLWith parses markup sanitized under a caller-provided policy.
func RenderMarkdown ¶
func RenderMarkdown(parseMarkdown string, parseOptions ...MarkdownRenderOptions) []ui.Node
RenderMarkdown parses markdown text and returns semantic ui.Node values.
func Repeat ¶
Repeat renders the same node parseCount times. A non-positive count renders nothing. Use Range when each instance must differ or carry a distinct key.
func ResolveMarkdownHref ¶
ResolveMarkdownHref resolves a markdown destination against the source document path.
func SanitizeMarkdownHref ¶
SanitizeMarkdownHref returns destination unchanged when it carries no scheme (relative, absolute-path, or fragment) or an allowed scheme, and returns "" otherwise. The allowed argument lists schemes without the trailing colon; a nil or empty list uses the default allowlist (http, https, mailto). Scheme detection tolerates the usual obfuscations - leading/embedded whitespace and control characters (java\tscript:), mixed case (JavaScript:), and a leading space ( javascript:) - by normalizing the scheme token before the check.
Example ¶
ExampleSanitizeMarkdownHref shows the URL-scheme allowlist used by RenderMarkdown: safe schemes pass through, dangerous ones are dropped to "".
package main
import (
"fmt"
"github.com/monstercameron/GoWebComponents/v4/html"
)
func main() {
fmt.Printf("%q\n", html.SanitizeMarkdownHref("https://example.test", nil))
fmt.Printf("%q\n", html.SanitizeMarkdownHref("guide.md#section", nil))
fmt.Printf("%q\n", html.SanitizeMarkdownHref("javascript:alert(1)", nil))
}
Output: "https://example.test" "guide.md#section" ""
func Show ¶
Show returns the node when the condition is true; otherwise it returns the same node with the hidden attribute set so it stays mounted but is not displayed. Use If/Unless instead when the node should be removed from the tree.
func Switch ¶
func Switch(parseValue any, parseBranches ...SwitchBranch) ui.Node
Switch selects the first matching branch and otherwise falls back to Default.
func TextLines ¶
TextLines splits text on newlines into text nodes separated by <br> elements, preserving blank lines. A string with no newline yields a single text node.
func Throttle ¶
Throttle invokes immediately and then at most once per interval with the latest pending event.
func WithChildren ¶
WithChildren appends children to an already-built node and returns it. Nil children are skipped.
Types ¶
type Binding ¶
Binding is a two-way-bindable string value: any handle with Get() string and Set(string). It lets BindTo wire the V4 reactive handles — state.Signal[string], state.GlobalAtom[string], a state.Atom[string] handle — to a controlled input with the same one-call ergonomics as Bind for ui.State.
type CondBranch ¶
type CondBranch struct {
// contains filtered or unexported fields
}
CondBranch describes one boolean branch in a Cond expression helper.
func Match ¶
func Match(isCondition bool, parseNode ui.Node) CondBranch
Match creates a boolean branch for Cond. The first branch whose condition is true wins.
func Otherwise ¶
func Otherwise(parseNode ui.Node) CondBranch
Otherwise creates the fallback branch for Cond, taken only when no Match condition is true. It is the boolean-chain analogue of Switch's Default.
type CustomElementProps ¶
type CustomElementProps struct {
Props Props
Attributes map[string]string
Presence map[string]bool
Properties map[string]any
}
CustomElementProps makes attribute-versus-property intent explicit for browser-defined custom elements and web components.
type DataAttribute ¶ added in v4.2.0
DataAttribute names one data-* attribute (Name is the suffix after "data-") for the zero-allocation Props.DataAttr field.
type MarkdownClasses ¶
type MarkdownClasses struct {
Heading1 string
Heading2 string
Heading3 string
Heading4 string
Heading5 string
Heading6 string
Paragraph string
Blockquote string
List string
OrderedList string
UnorderedList string
ListItem string
CodeBlockContainer string
CodeBlockLabel string
CodeBlockPre string
InlineCode string
Strong string
Emphasis string
Link string
HorizontalRule string
}
MarkdownClasses configures optional class names applied to rendered markdown nodes.
type MarkdownRenderOptions ¶
type MarkdownRenderOptions struct {
SourcePath string
ResolveHref func(sourcePath, destination string) string
Classes MarkdownClasses
CodeBlockLabel string
LinkTarget string
LinkRel string
// AllowedURLSchemes overrides the scheme allowlist applied to link, image,
// and autolink destinations. When nil the default allowlist is used
// (http, https, mailto); relative paths, absolute paths, and fragments
// carry no scheme and are always allowed. Any other scheme - notably
// javascript:, data:, and vbscript: - is dropped so user-supplied markdown
// cannot smuggle an executable URL into an href or src sink. Supply schemes
// without the trailing colon (for example []string{"http", "https",
// "mailto", "data"} to additionally permit inline data: images).
AllowedURLSchemes []string
}
MarkdownRenderOptions configures markdown rendering into ui.Node values.
type PropOption ¶
type PropOption interface {
// contains filtered or unexported methods
}
PropOption mutates Props through an explicit additive helper.
func Accept ¶
func Accept(parseValue string) PropOption
Accept sets the accept attribute on a Props.
func Aria ¶
func Aria(parseName string, parseValue string) PropOption
Aria sets a single aria-* attribute on the Props.
func AriaSet ¶
func AriaSet(parseValues map[string]string) PropOption
AriaSet merges multiple aria-* attributes into the Props.
func Attr ¶
func Attr(parseKey string, parseValue any) PropOption
Attr sets a single raw HTML attribute on the Props.
func AttrIf ¶
func AttrIf(isCondition bool, parseKey string, parseValue any) PropOption
AttrIf applies a raw attribute only when the condition is true, otherwise it is a no-op option (nil, which PropsOf/WithProps skip).
func Attrs ¶
func Attrs(parseValues map[string]any) PropOption
Attrs merges multiple raw HTML attributes into the Props.
func AutoComplete ¶
func AutoComplete(parseValue string) PropOption
AutoComplete sets the autocomplete attribute on a Props.
func AutoFocus ¶
func AutoFocus(parseValues ...bool) PropOption
AutoFocus sets the autofocus boolean on a Props; passes true when no argument is given.
func Bind ¶
func Bind(parseState ui.State[string]) PropOption
Bind wires a controlled input to a string State in one call (U6): it sets the element's value from the state and updates the state on input. Replaces the manual Value(s.Get()) + OnInput(func(v){ s.Set(v) }) pairing.
name := ui.UseState("")
html.Input(html.Bind(name))
func BindFunc ¶
func BindFunc(parseGet func() string, parseSet func(string)) PropOption
BindFunc is the general two-way binding: it sets the input value to get() and registers an oninput handler that calls set(value). Use it when the source is not a single handle (e.g. a struct field reached through a closure). A nil getter leaves the value unset; a nil setter makes input a no-op.
func BindTo ¶
func BindTo(parseTarget Binding) PropOption
BindTo two-way binds a text input to any Binding (e.g. a state.Signal[string]): it sets the input value to target.Get() and registers an oninput handler that writes target.Set(value). Like Bind, call it at a stable render position. A nil target is a no-op.
name := state.NewSignal("")
h.Input(h.Type("text"), h.BindTo(name))
func Checked ¶
func Checked(parseValues ...bool) PropOption
Checked sets the checked boolean on a Props; passes true when no argument is given.
func ClassIf ¶
func ClassIf(isCondition bool, parseClass string) PropOption
ClassIf sets the class attribute only when the condition is true, otherwise it is a no-op option. For composing one class string from many conditions use ClassNames with When instead.
func ColSpan ¶
func ColSpan(parseValue int) PropOption
ColSpan sets the colSpan property on a Props.
func Data ¶
func Data(parseName string, parseValue string) PropOption
Data sets a single data-* attribute on the Props.
func Dataset ¶
func Dataset(parseValues map[string]string) PropOption
Dataset merges multiple data-* attributes into the Props.
func Disabled ¶
func Disabled(parseValues ...bool) PropOption
Disabled sets the disabled boolean on a Props; passes true when no argument is given.
func DisabledIf ¶
func DisabledIf(isCondition bool) PropOption
DisabledIf sets the disabled boolean conditionally on a Props.
func Height ¶
func Height(parseValue string) PropOption
Height sets the height attribute on a Props.
func Hidden ¶
func Hidden(parseValues ...bool) PropOption
Hidden sets the hidden boolean on a Props; passes true when no argument is given.
func Loading ¶
func Loading(parseValue string) PropOption
Loading sets the loading attribute on a Props.
func MaxLength ¶
func MaxLength(parseValue int) PropOption
MaxLength sets the maxLength property on a Props.
func MinLength ¶
func MinLength(parseValue int) PropOption
MinLength sets the minLength property on a Props.
func Multiple ¶
func Multiple(parseValues ...bool) PropOption
Multiple sets the multiple boolean on a Props; passes true when no argument is given.
func OnAnimationEnd ¶
func OnAnimationEnd(parseCallback any) PropOption
OnAnimationEnd registers an onanimationend event handler on the Props.
func OnBlur ¶
func OnBlur(parseCallback any) PropOption
OnBlur registers an onblur event handler on the Props.
func OnChange ¶
func OnChange(parseCallback any) PropOption
OnChange registers an onchange event handler on the Props.
func OnClick ¶
func OnClick(parseCallback any) PropOption
OnClick registers an onclick event handler on the Props.
func OnClickParallel ¶
func OnClickParallel(parseSlotID string, parseCallback any) PropOption
OnClickParallel registers one local click handler and marks the node as a public parallel-region click slot.
func OnContextMenu ¶
func OnContextMenu(parseCallback any) PropOption
OnContextMenu registers an oncontextmenu event handler on the Props.
func OnDoubleClick ¶
func OnDoubleClick(parseCallback any) PropOption
OnDoubleClick registers an ondblclick event handler on the Props.
func OnDragEnd ¶
func OnDragEnd(parseCallback any) PropOption
OnDragEnd registers an ondragend event handler on the Props.
func OnDragOver ¶
func OnDragOver(parseCallback any) PropOption
OnDragOver registers an ondragover event handler on the Props.
func OnDragStart ¶
func OnDragStart(parseCallback any) PropOption
OnDragStart registers an ondragstart event handler on the Props.
func OnDrop ¶
func OnDrop(parseCallback any) PropOption
OnDrop registers an ondrop event handler on the Props.
func OnError ¶
func OnError(parseCallback any) PropOption
OnError registers an onerror event handler on the Props.
func OnFocus ¶
func OnFocus(parseCallback any) PropOption
OnFocus registers an onfocus event handler on the Props.
func OnInput ¶
func OnInput(parseCallback any) PropOption
OnInput registers an oninput event handler on the Props.
func OnKeyDown ¶
func OnKeyDown(parseCallback any) PropOption
OnKeyDown registers an onkeydown event handler on the Props.
func OnKeyUp ¶
func OnKeyUp(parseCallback any) PropOption
OnKeyUp registers an onkeyup event handler on the Props.
func OnLoad ¶
func OnLoad(parseCallback any) PropOption
OnLoad registers an onload event handler on the Props.
func OnMouseDown ¶
func OnMouseDown(parseCallback any) PropOption
OnMouseDown registers an onmousedown event handler on the Props.
func OnMouseEnter ¶
func OnMouseEnter(parseCallback any) PropOption
OnMouseEnter registers an onmouseenter event handler on the Props.
func OnMouseLeave ¶
func OnMouseLeave(parseCallback any) PropOption
OnMouseLeave registers an onmouseleave event handler on the Props.
func OnMouseUp ¶
func OnMouseUp(parseCallback any) PropOption
OnMouseUp registers an onmouseup event handler on the Props.
func OnPointerDown ¶
func OnPointerDown(parseCallback any) PropOption
OnPointerDown registers an onpointerdown event handler on the Props.
func OnPointerMove ¶
func OnPointerMove(parseCallback any) PropOption
OnPointerMove registers an onpointermove event handler on the Props.
func OnPointerUp ¶
func OnPointerUp(parseCallback any) PropOption
OnPointerUp registers an onpointerup event handler on the Props.
func OnScroll ¶
func OnScroll(parseCallback any) PropOption
OnScroll registers an onscroll event handler on the Props.
func OnSubmit ¶
func OnSubmit(parseCallback any) PropOption
OnSubmit registers an onsubmit event handler on the Props.
func OnTouchEnd ¶
func OnTouchEnd(parseCallback any) PropOption
OnTouchEnd registers an ontouchend event handler on the Props.
func OnTouchMove ¶
func OnTouchMove(parseCallback any) PropOption
OnTouchMove registers an ontouchmove event handler on the Props.
func OnTouchStart ¶
func OnTouchStart(parseCallback any) PropOption
OnTouchStart registers an ontouchstart event handler on the Props.
func OnTransitionEnd ¶
func OnTransitionEnd(parseCallback any) PropOption
OnTransitionEnd registers an ontransitionend event handler on the Props.
func OnWheel ¶
func OnWheel(parseCallback any) PropOption
OnWheel registers an onwheel event handler on the Props.
func Open ¶
func Open(parseValues ...bool) PropOption
Open sets the open boolean on a Props; passes true when no argument is given.
func Pattern ¶
func Pattern(parseValue string) PropOption
Pattern sets the pattern attribute on a Props.
func Placeholder ¶
func Placeholder(parseValue string) PropOption
Placeholder sets the placeholder attribute on a Props.
func ReadOnly ¶
func ReadOnly(parseValues ...bool) PropOption
ReadOnly sets the readonly boolean on a Props; passes true when no argument is given.
func ReadOnlyIf ¶
func ReadOnlyIf(isCondition bool) PropOption
ReadOnlyIf sets the readonly boolean conditionally on a Props.
func Ref ¶
func Ref(parseRef ui.DOMRef) PropOption
Ref binds a ui.DOMRef to the element so its live DOM node is published into the ref on mount (and cleared on unmount). It carries the ref's sink through the reserved props key, which the reconciler skips as a DOM attribute. Attach at most one Ref per element, and attach it at mount time.
r := ui.UseDOMRef() html.Input(html.Ref(r))
A zero-value DOMRef (not produced by UseDOMRef) yields a no-op.
func Required ¶
func Required(parseValues ...bool) PropOption
Required sets the required boolean on a Props; passes true when no argument is given.
func RowSpan ¶
func RowSpan(parseValue int) PropOption
RowSpan sets the rowSpan property on a Props.
func Selected ¶
func Selected(parseValues ...bool) PropOption
Selected sets the selected boolean on a Props; passes true when no argument is given.
func SelectedIf ¶
func SelectedIf(isCondition bool) PropOption
SelectedIf sets the selected boolean conditionally on a Props.
func Style ¶
func Style(parseValues map[string]string) PropOption
Style merges the given CSS style map into the Props Style field.
func StyleIf ¶
func StyleIf(isCondition bool, parseValues map[string]string) PropOption
StyleIf applies inline styles only when the condition is true, otherwise it is a no-op option.
func StyleVar ¶
func StyleVar(parseName string, parseValue string) PropOption
StyleVar sets a single inline style property, typically a CSS custom property such as "--accent". It is Style with one entry.
func TabIndex ¶
func TabIndex(parseValue int) PropOption
TabIndex sets the tabindex attribute on a Props.
When parseValue is 0 the key is written into Raw["tabIndex"] so that toRuntimeProps emits it explicitly. Props.TabIndex==0 is silently dropped by toRuntimeProps; prefer html.TabIndex(0) when tabindex=0 is intentional.
func Target ¶
func Target(parseValue string) PropOption
Target sets the target attribute on a Props.
func Value ¶
func Value(parseValue string) PropOption
Value sets the value attribute on a Props.
When parseValue is the empty string the key is written into Raw["value"] so that toRuntimeProps emits it even for an empty controlled input. Using Props.Value="" directly is silently dropped by toRuntimeProps; prefer html.Value("") or html.Attr("value","") when you need to clear a controlled input via the typed-builder path.
type Props ¶
type Props struct {
ID string
Class string
Key string
Slot string
Title string
Type string
Name string
// Value is the input/option value. An empty string is silently omitted by
// toRuntimeProps; use html.Value("") (the PropOption) or Raw["value"]="" to
// explicitly emit an empty controlled-input value.
Value string
Placeholder string
Accept string
Href string
Src string
Alt string
For string
Role string
Target string
Rel string
As string
Action string
Method string
EncType string
AutoComplete string
Min string
Max string
Step string
Pattern string
Lang string
Dir string
Width string
Height string
Loading string
Rows int
Cols int
// TabIndex of 0 is silently omitted by toRuntimeProps; use html.TabIndex(0)
// (the PropOption) or Raw["tabIndex"]=0 to make tabindex=0 explicit.
TabIndex int
MaxLength int
MinLength int
ColSpan int
RowSpan int
Checked bool
Disabled bool
Selected bool
Required bool
ReadOnly bool
Hidden bool
Multiple bool
AutoFocus bool
Open bool
Style map[string]string
Data map[string]string
Aria map[string]string
Raw map[string]any
// DataAttr sets one data-* attribute without allocating a Data map — the
// dominant single-attribute case (e.g. a per-row id) costs zero
// allocations this way. Name is the part after "data-". Combine with the
// Data map for additional attributes; both land in the same
// deterministically sorted segment.
DataAttr DataAttribute
// Text sets the element's entire text content directly. The equivalent
// html.Text(...) child form allocates a full throwaway Element that Tag
// discards after extracting the string — one of the highest-frequency
// allocation sites in text-heavy trees. Ignored when children are passed
// or when empty (use a Text child for explicit empty text).
Text string
OnClick ui.Handler
OnInput ui.Handler
OnChange ui.Handler
OnSubmit ui.Handler
OnKeyDown ui.Handler
OnKeyUp ui.Handler
OnMouseUp ui.Handler
OnMouseDown ui.Handler
OnMouseEnter ui.Handler
OnMouseLeave ui.Handler
OnDoubleClick ui.Handler
OnContextMenu ui.Handler
OnWheel ui.Handler
OnTransitionEnd ui.Handler
OnAnimationEnd ui.Handler
OnLoad ui.Handler
OnError ui.Handler
OnPointerDown ui.Handler
OnPointerMove ui.Handler
OnPointerUp ui.Handler
OnTouchStart ui.Handler
OnTouchMove ui.Handler
OnTouchEnd ui.Handler
OnDragStart ui.Handler
OnDragOver ui.Handler
OnDrop ui.Handler
OnDragEnd ui.Handler
OnFocus ui.Handler
OnBlur ui.Handler
OnScroll ui.Handler
}
Props contains the common HTML attributes and event handlers supported by the typed builders.
func DefaultProps ¶
DefaultProps returns parseProps with parseDefaults filling only the fields parseProps leaves zero. Explicit values in parseProps always win.
func MergeProps ¶
MergeProps overlays parseOverride onto parseBase: each non-zero scalar field of parseOverride wins, and the Style/Data/Aria/Raw maps are unioned with parseOverride taking precedence per key. Neither input is mutated. Use it to forward and override props through a wrapper component.
func PropsOf ¶
func PropsOf(parseOptions ...PropOption) Props
PropsOf builds Props from additive prop options using last-write-wins semantics.
func WithProps ¶
func WithProps(parseBase Props, parseOptions ...PropOption) Props
WithProps applies additive prop options onto an existing Props value.
type SwitchBranch ¶
type SwitchBranch struct {
// contains filtered or unexported fields
}
SwitchBranch describes one branch in a Switch expression helper.
func Case ¶
func Case(parseValue any, parseNode ui.Node) SwitchBranch
Case creates a value-matching branch for Switch.
func Default ¶
func Default(parseNode ui.Node) SwitchBranch
Default creates the fallback branch for Switch.