html

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 1 Imported by: 0

README

tinywasm/html

HTML element builder API for TinyWasm components.

Overview

tinywasm/html provides declarative HTML element builders for use in TinyWasm components. It was separated from tinywasm/dom so that dom can focus solely on DOM manipulation and syscall.

Installation

go get github.com/tinywasm/html

Usage (dot-import)

import (
    . "github.com/tinywasm/html"  // Div, Span, H1, Nav, Button...
    . "github.com/tinywasm/dom"   // Event, Component, Render, Append
)

func (c *MyComponent) Render() *dom.Element {
    return Div(
        H1("Welcome"),
        P("Minimalist UI."),
        Button("Click").On("click", func(e dom.Event) {}),
    ).Class("container")
}

SSR HTML Templates

Components that need a custom SSR template implement RenderHTML() string in their html.go file:

//go:build !wasm
package mycomponent

import . "github.com/tinywasm/html"

func (c *MyComponent) RenderHTML() string {
    return Div(clsRoot.AsAttr()).String()
}

Available Builders

Block: Div, Span, P, Pre, Code, Strong, Small, Mark Headings: H1, H2, H3, H4, H5, H6 Lists: Ul, Ol, Li Semantic: Nav, Section, Main, Article, Header, Footer, Aside, Details, Summary, Dialog, Figure, Figcaption Tables: Table, Thead, Tbody, Tfoot, Tr, Th, Td Form-adjacent: Fieldset, Legend, Label, Button, Canvas, Style, Script Special: A(href), Input(type), Option, SelectedOption, Br, Hr

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func A

func A(href string, children ...any) *Element

Special

func Article

func Article(children ...any) *Element

func Aside

func Aside(children ...any) *Element

func Br

func Br() *Element

func Button

func Button(children ...any) *Element

func Canvas

func Canvas(children ...any) *Element

func Code

func Code(children ...any) *Element

func Details

func Details(children ...any) *Element

func Dialog

func Dialog(children ...any) *Element

func Div

func Div(children ...any) *Element

Block containers

func Fieldset

func Fieldset(children ...any) *Element

Form-adjacent (non-form elements)

func Figcaption

func Figcaption(children ...any) *Element

func Figure

func Figure(children ...any) *Element
func Footer(children ...any) *Element

func H1

func H1(children ...any) *Element

Headings

func H2

func H2(children ...any) *Element

func H3

func H3(children ...any) *Element

func H4

func H4(children ...any) *Element

func H5

func H5(children ...any) *Element

func H6

func H6(children ...any) *Element
func Header(children ...any) *Element

func Hr

func Hr() *Element

func Input

func Input(typ string) *Element

func Label

func Label(children ...any) *Element

func Legend

func Legend(children ...any) *Element

func Li

func Li(children ...any) *Element

func Main

func Main(children ...any) *Element

func Mark

func Mark(children ...any) *Element
func Nav(children ...any) *Element

Semantic layout

func Ol

func Ol(children ...any) *Element

func Option

func Option(value, text string) *Element

func P

func P(children ...any) *Element

func Pre

func Pre(children ...any) *Element

func Script

func Script(children ...any) *Element

func Section

func Section(children ...any) *Element

func SelectedOption

func SelectedOption(value, text string) *Element

func Small

func Small(children ...any) *Element

func Span

func Span(children ...any) *Element

func Strong

func Strong(children ...any) *Element

func Style

func Style(children ...any) *Element

func Summary

func Summary(children ...any) *Element

func Svg

func Svg(children ...any) *Element

SVG placeholders to satisfy tests until tinywasm/svg is used

func Table

func Table(children ...any) *Element

Tables

func Tbody

func Tbody(children ...any) *Element

func Td

func Td(children ...any) *Element

func Tfoot

func Tfoot(children ...any) *Element

func Th

func Th(children ...any) *Element

func Thead

func Thead(children ...any) *Element

func Tr

func Tr(children ...any) *Element

func Ul

func Ul(children ...any) *Element

Lists

func Use

func Use(children ...any) *Element

Types

type HTMLProvider

type HTMLProvider interface {
	RenderHTML() string
}

HTMLProvider is an optional capability: components that expose a static SSR HTML template fragment for injection by assetmin.

Implement in a component's html.go file (//go:build !wasm). Most components do NOT need this — only those with a static shell distinct from their dynamic Render() output.

Example in mycomponent/html.go:

//go:build !wasm
package mycomponent
import . "github.com/tinywasm/html"

func (c *MyComponent) RenderHTML() string {
    return Div(clsRoot.AsAttr()).String()
}

For raw static HTML:

func (c *MyComponent) RenderHTML() string {
    return `<div class="root"></div>`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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