ui

package
v0.0.0-...-603d8dc Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ui provides the GoWave virtual DOM.

ui.Node is a lightweight tree of elements that:

  • Renders to HTML strings on the server (SSR)
  • Compiles to WASM on the client and diffs against the live DOM

All builder functions (Div, Span, Button, etc.) return a Node. Modifiers (Class, Text, OnClick, etc.) are applied as NodeOptions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearHandlers

func ClearHandlers()

ClearHandlers resets the registry between render cycles.

func Dispatch

func Dispatch(event, id, value string)

Dispatch is called by the WASM bridge to invoke a handler by ID.

func RenderHTML

func RenderHTML(n Node) string

RenderHTML renders a Node tree to an HTML string. Called on the server for SSR; not used in the WASM binary.

Types

type Attr

type Attr struct {
	Key       string
	Value     string
	HandlerID string // non-empty → event binding, not a plain attribute
}

Attr is a key-value HTML attribute pair. HandlerID is set for event attributes (onclick, oninput).

type Node

type Node struct {
	Type     NodeType
	Tag      string
	Attrs    []Attr
	Children []Node
	Text     string
	Key      string // for list reconciliation
}

Node is a virtual DOM node. Zero value is a valid empty fragment.

func A

func A(opts ...Option) Node

func Article

func Article(opts ...Option) Node

func Body

func Body(opts ...Option) Node

func Button

func Button(opts ...Option) Node

func Code

func Code(opts ...Option) Node

func Div

func Div(opts ...Option) Node
func Footer(opts ...Option) Node

func Form

func Form(opts ...Option) Node

func Fragment

func Fragment(children ...Node) Node

Fragment wraps multiple nodes with no wrapping element.

func H1

func H1(opts ...Option) Node

func H2

func H2(opts ...Option) Node

func H3

func H3(opts ...Option) Node
func Head(opts ...Option) Node
func Header(opts ...Option) Node

func Html

func Html(opts ...Option) Node

func If

func If(cond bool, then, otherwise Node) Node

If conditionally returns one of two nodes.

func Img

func Img(opts ...Option) Node

func Input

func Input(opts ...Option) Node

func Label

func Label(opts ...Option) Node

func Li

func Li(opts ...Option) Node
func Link(rel, href string) Node

func Main

func Main(opts ...Option) Node

func Map

func Map[T any](items []T, fn func(int, T) Node) []Node

Map converts a slice to a slice of Nodes.

func Meta

func Meta(name, content string) Node

Void elements (self-closing)

func Nav(opts ...Option) Node

func Ol

func Ol(opts ...Option) Node

func P

func P(opts ...Option) Node

func Pre

func Pre(opts ...Option) Node

func Script

func Script(src string) Node

func Section

func Section(opts ...Option) Node

func Select

func Select(opts ...Option) Node

func SelectOption

func SelectOption(opts ...Option) Node

func Span

func Span(opts ...Option) Node

func Table

func Table(opts ...Option) Node

func Tbody

func Tbody(opts ...Option) Node

func Td

func Td(opts ...Option) Node

func Textarea

func Textarea(opts ...Option) Node

func Th

func Th(opts ...Option) Node

func Thead

func Thead(opts ...Option) Node

func Title

func Title(text string) Node

func Tr

func Tr(opts ...Option) Node

func Ul

func Ul(opts ...Option) Node

type NodeType

type NodeType uint8

NodeType classifies a Node.

const (
	ElementNode NodeType = iota
	TextNode
	FragmentNode
	RawNode // raw unescaped content for inline <script>/<style>
)

type Option

type Option func(*Node)

Option is a functional modifier applied to a Node during construction.

func Alt

func Alt(alt string) Option

Alt sets the alt attribute.

func Attr2

func Attr2(key, value string) Option

Attr2 adds a raw key=value attribute.

func Checked

func Checked(c bool) Option

Checked sets the checked attribute.

func Child

func Child(child Node) Option

Child appends a child Node.

func Children

func Children(children ...Node) Option

Children appends multiple child Nodes.

func Class

func Class(c string) Option

Class sets the CSS class.

func DataAttr

func DataAttr(key, value string) Option

DataAttr adds a data-* attribute.

func Disabled

func Disabled(d bool) Option

Disabled sets the disabled attribute.

func Href

func Href(href string) Option

Href sets the href attribute.

func ID

func ID(id string) Option

ID sets the element id.

func KeyAttr

func KeyAttr(k string) Option

KeyAttr sets the reconciliation key (used for list diffing).

func OnChange

func OnChange(fn func()) Option

OnChange registers a change handler.

func OnClick

func OnClick(fn func()) Option

OnClick registers a click handler.

func OnEnter

func OnEnter(fn func()) Option

OnEnter registers an Enter-key handler on an input.

func OnInput

func OnInput(fn func(string)) Option

OnInput registers an input handler that receives the current value.

func Placeholder

func Placeholder(p string) Option

Placeholder sets the placeholder attribute.

func Src

func Src(src string) Option

Src sets the src attribute.

func Text

func Text(s string) Option

Text creates a text node.

func Textf

func Textf(format string, args ...any) Option

Textf creates a formatted text node.

func Value

func Value(v string) Option

Value sets the value attribute.

type Page

type Page interface {
	Render() Node
}

Page is the interface every GoWave page component must satisfy. Defined here so both the SSR renderer and the WASM runtime can use it without importing each other.

Jump to

Keyboard shortcuts

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