components

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 4 Imported by: 0

README

TinyWasm Components

Project Badges

A catalog of reusable, efficient, and WebAssembly-ready UI components for the TinyWasm ecosystem.

Features

  • Zero Boilerplate: Components handle their own state, styling, and event binding.
  • SSR/CSR Split: CSS and heavy assets are server-side only; WASM binaries remain tiny.
  • Fluent API: Uses tinywasm/dom for type-safe, declarative UI construction.
  • Explicit Registration: Only pay for what you use (tree-shakeable).
  • No Magic: Standard Go structs and interfaces.

Installation

go get github.com/tinywasm/components

Quick Start

1. Import Components
import (
    "github.com/tinywasm/components/button"
    "github.com/tinywasm/components/card"
    "github.com/tinywasm/dom"
)
2. Instantiate and Render
func main() {
    // Create a button
    btn := &button.Button{
        Text: "Click Me",
        Variant: "primary",
        OnClick: func(e dom.Event) {
            println("Button clicked!")
        },
    }

    // Render to the DOM
    dom.Append("app", btn)
}

Available Components

See Component Catalog for full documentation.

  • Button: Primary/secondary actions with variants.
  • Card: Content container with header/body/footer.
  • Input: Text input with validation and labels.
  • Nav: Navigation menu with icon support.
  • Modal: Dialog overlays.
  • Table: Data tables.
  • Form: Form wrapper with submission handling.

Development

See Component Creation Guide to learn how to build your own components.

Prerequisites
  • Go 1.21+
  • TinyGo (for WASM compilation)
Running Tests
go test ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get added in v0.0.5

func Get(name string) dom.Component

Get retrieves a component by name.

func List added in v0.0.5

func List() []string

List returns a list of registered component names.

func Register added in v0.0.5

func Register(name string, factory func() dom.Component)

Register adds a component factory to the registry.

Types

type BaseComponent added in v0.0.5

type BaseComponent = dom.BaseComponent

BaseComponent provides common utilities for component authors (Currently just an alias, but can be extended later)

type CssVars added in v0.0.4

type CssVars struct {
	Primary            string `css:"--color-primary"`
	Secondary          string `css:"--color-secondary"`
	Tertiary           string `css:"--color-tertiary"`
	Quaternary         string `css:"--color-quaternary"`
	Gray               string `css:"--color-gray"`
	Selection          string `css:"--color-selection"`
	Hover              string `css:"--color-hover"`
	Success            string `css:"--color-success"`
	Error              string `css:"--color-error"`
	MenuWidthCollapsed string `css:"--menu-width-collapsed"`
	MenuWidthExpanded  string `css:"--menu-width-expanded"`
}

CssVars defines the structure for the site's CSS variables.

func GetDefaultCssVars added in v0.0.4

func GetDefaultCssVars() CssVars

GetDefaultCssVars returns the default CSS variables.

func (CssVars) Render added in v0.0.4

func (c CssVars) Render() string

Render returns the CSS variables as a string (e.g. key: value;).

type Props added in v0.0.5

type Props map[string]any

Props pattern (optional utility)

func (Props) Get added in v0.0.5

func (p Props) Get(key string) any

Get returns the value for a key as an interface{}.

func (Props) Int added in v0.0.5

func (p Props) Int(key string) int

Int returns the value for a key as an int, or 0 if not found or not an int.

func (Props) String added in v0.0.5

func (p Props) String(key string) string

String returns the value for a key as a string, or an empty string if not found or not a string.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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