Documentation
ΒΆ
Index ΒΆ
- func Append(parentID string, component Component) error
- func GetHash() string
- func Hydrate(parentID string, component Component) error
- func Log(v ...any)
- func OnHashChange(handler func(hash string))
- func Render(parentID string, component Component) error
- func SetHash(hash string)
- func SetLog(log func(v ...any))
- func Unmount(component Component)
- func Update(component Component) error
- type CSSProvider
- type Component
- type DOM
- type Element
- func (b *Element) Add(children ...any) *Element
- func (b *Element) Append(child any) *Element
- func (b *Element) Attr(key, val string) *Element
- func (b *Element) Children() []Component
- func (b *Element) Class(class ...string) *Element
- func (b *Element) GetID() string
- func (b *Element) ID(id string) *Element
- func (b *Element) OnChange(handler func(Event)) *Element
- func (b *Element) OnClick(handler func(Event)) *Element
- func (b *Element) OnInput(handler func(Event)) *Element
- func (b *Element) Render(parentID string) error
- func (b *Element) RenderHTML() string
- func (b *Element) SetID(id string)
- func (b *Element) Text(text string) *Element
- func (b *Element) Unmount()
- func (b *Element) Update() error
- type Event
- type EventHandler
- type IconSvgProvider
- type JSProvider
- type Mountable
- type Reference
- type Unmountable
- type Updatable
- type ViewRenderer
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Append ΒΆ added in v0.2.0
Append injects a component AFTER the last child of the parent element.
func OnHashChange ΒΆ added in v0.0.11
func OnHashChange(handler func(hash string))
OnHashChange registers a hash change listener.
Types ΒΆ
type CSSProvider ΒΆ added in v0.0.13
type CSSProvider interface {
RenderCSS() string
}
CSSProvider is an optional interface for components that need to inject CSS.
type Component ΒΆ
type Component interface {
GetID() string
SetID(id string)
RenderHTML() string
Children() []Component
}
Component is the minimal interface for components. All components must implement this for both SSR (backend) and WASM (frontend).
type DOM ΒΆ
type DOM interface {
// Get retrieves an element by its ID.
// It uses an internal cache to avoid repeated DOM lookups.
// Returns the element and a boolean indicating if it was found.
Get(id string) (Reference, bool)
// Render injects a component into a parent element.
// 1. It calls component.Render() (if ViewRenderer) or component.RenderHTML()
// 2. It sets the content of the parent element (found by parentID)
// 3. It calls component.OnMount() to bind events
Render(parentID string, component Component) error
// Append injects a component AFTER the last child of the parent element.
// Useful for dynamic lists.
Append(parentID string, component Component) error
// Hydrate attaches event listeners to existing HTML without re-rendering it.
Hydrate(parentID string, component Component) error
// OnHashChange registers a listener for URL hash changes.
OnHashChange(handler func(hash string))
// GetHash returns the current URL hash (e.g., "#help").
GetHash() string
// SetHash updates the URL hash.
SetHash(hash string)
// QueryAll finds all elements matching a CSS selector.
QueryAll(selector string) []Reference
// Unmount removes a component from the DOM (by clearing the parent's HTML or removing the node)
// and cleans up any event listeners registered via the Element interface.
Unmount(component Component)
// Update re-renders the component in its current position in the DOM.
Update(component Component) error
// Log provides logging functionality using the log function passed to New.
Log(v ...any)
}
DOM is the main entry point for interacting with the browser. It is designed to be injected into your components.
type Element ΒΆ
type Element struct {
// contains filtered or unexported fields
}
Element represents a DOM element in the fluent Element API.
func (*Element) Add ΒΆ added in v0.2.3
Add adds one or more children to the element. Children can be *Element, Node, Component, or string.
func (*Element) Append ΒΆ added in v0.2.3
Append adds a child to the element. Deprecated: use Add instead.
func (*Element) Children ΒΆ added in v0.2.3
Children returns the component's children (components only).
func (*Element) Render ΒΆ added in v0.2.3
Render renders the element to the parent. This is a terminal operation.
func (*Element) RenderHTML ΒΆ added in v0.2.3
RenderHTML renders the element to HTML string.
type Event ΒΆ
type Event interface {
// PreventDefault prevents the default action of the event.
PreventDefault()
// StopPropagation stops the event from bubbling up the DOM tree.
StopPropagation()
// TargetValue returns the value of the event's target element.
// Useful for input, textarea, and select elements.
TargetValue() string
// TargetID returns the ID of the event's target element.
TargetID() string
}
Event represents a DOM event.
type EventHandler ΒΆ added in v0.2.0
EventHandler represents a DOM event handler in the declarative builder.
type IconSvgProvider ΒΆ added in v0.0.13
IconSvgProvider is an optional interface for components that provide SVG icons.
type JSProvider ΒΆ added in v0.0.13
type JSProvider interface {
RenderJS() string
}
JSProvider is an optional interface for components that need to inject JS.
type Mountable ΒΆ added in v0.2.0
type Mountable interface {
OnMount()
}
Mountable is an optional interface for components that need initialization logic.
type Reference ΒΆ added in v0.2.3
type Reference interface {
// GetAttr retrieves an attribute value.
GetAttr(key string) string
// Value returns the current value of an input/textarea/select.
Value() string
// Checked returns the current checked state of a checkbox or radio button.
Checked() bool
// On registers a generic event handler (e.g., "click", "change", "input", "keydown").
On(eventType string, handler func(event Event))
// Focus sets focus to the element.
Focus()
}
Reference represents a reference to a DOM node. It provides methods for reading and interaction.
type Unmountable ΒΆ added in v0.2.0
type Unmountable interface {
OnUnmount()
}
Unmountable is an optional interface for components that need cleanup logic.
type Updatable ΒΆ added in v0.2.0
type Updatable interface {
OnUpdate()
}
Updatable is an optional interface for components that need update logic.
type ViewRenderer ΒΆ added in v0.2.0
type ViewRenderer interface {
Render() *Element
}
ViewRenderer returns a Node tree for declarative UI.