webx

package module
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 12 Imported by: 0

README

webx

Beautiful, accessible UI components built with Go, Templ, Tailwind CSS, DaisyUI, and Datastar.

Philosophy

webx is inspired by daisyui. Like daisyui, this is a component library you install as a dependency. Fork it and own it.

  • You own the code. Need to change something? Just edit it.
  • No versioning conflicts or breaking changes to worry about.
  • Zero configuration complexity. Customize by changing the code.
  • Server-side rendering with Go/templ — no Node.js build step for components.
  • ~15KB of JavaScript total (the Datastar library) for all frontend interactivity.

Component structure

Each component lives in its own directory under ui/ and follows a consistent pattern:

ui/button/
  button.templ       # Component template (Props struct, variants, rendering)
  button_templ.go    # Generated Go code (do not edit)

Interactive components that need a server-side handler add extra files:

ui/form/
  form.templ         # Component template
  form_templ.go      # Generated Go code
  handler.go         # SSE handler for Datastar interactivity

Components use DaisyUI classes for styling and Datastar attributes for interactivity:

package button

type Props struct {
    ID         string
    Class      string
    Attributes templ.Attributes
    Variant    Variant           // btn-primary, btn-secondary, etc.
    Size       Size              // btn-lg, btn-sm, btn-xs
    Disabled   bool
    OnClick    string            // Datastar action expression
}

templ Button(props ...Props) {
    // Optional variadic props — sensible zero-value defaults
    // DaisyUI classes merged with utils.TwMerge()
    // Datastar attributes spread via ds.* helpers
}

Import and use in your templ files:

import "github.com/plaenen/webx/ui/button"

@button.Button(button.Props{Variant: button.VariantPrimary}) {
    Click me
}

Prerequisites

  • Go 1.24+

Getting started

# Install dependencies (downloads DaisyUI, Datastar, tidies modules)
go tool task install:all

# Generate templ + build Tailwind
go tool templ generate
go tool gotailwind

# Run the showcase (uses open-source Datastar)
go run ./cmd/showcase serve

The showcase starts at http://localhost:3000.

Datastar Pro (optional)

The showcase supports both open-source Datastar and Datastar Pro. Open-source is the default and requires no license.

To use Datastar Pro, purchase a license from data-star.dev and place the files in the byol/ directory (gitignored):

byol/
  datastar/
    datastar-pro.js
    datastar-inspector.js
    datastar-pro-rocket.js    # optional

Then start the showcase with the --pro flag:

go run ./cmd/showcase serve --pro

Pro mode enables the Datastar inspector and loads from your local BYOL files.

Documentation

Overview

Provides context for webx templates

Index

Constants

This section is empty.

Variables

View Source
var Static embed.FS

Functions

func Middleware added in v0.0.30

func Middleware(cfg MiddlewareConfig) func(http.Handler) http.Handler

Middleware reads or creates session/CSRF/theme cookies and populates Context on each request. On mutating methods it validates the signed double-submit CSRF token.

func Post

func Post(url string) string

Post returns a Datastar expression that performs a POST request to the given URL.

func SecurityHeadersMiddleware

func SecurityHeadersMiddleware(secure ...bool) func(http.Handler) http.Handler

SecurityHeadersMiddleware sets common security response headers. When secure is true (i.e. HTTPS / production), HSTS is also added.

Types

type Context added in v0.0.30

type Context struct {
	SessionID string
	CSRFToken string
	Theme     string
	BasePath  string    // prefix for all SSE handler routes (e.g. "/showcase")
	StreamURL string    // URL for the reactive SSE stream endpoint (e.g. "/showcase/stream")
	Watchers  []Watcher // reactive scope watchers accumulated during render
	// contains filtered or unexported fields
}

Context carries request-scoped state through the middleware chain and into templ components. Retrieve it with FromContext.

func FromContext

func FromContext(ctx context.Context) *Context

FromContext extracts the webx Context from a context.Context. If none is present, a new empty Context is returned.

func NewContext

func NewContext() *Context

NewContext returns an empty Context.

func (*Context) APIPath added in v0.0.30

func (c *Context) APIPath(path string) string

APIPath returns the full path for a component SSE handler by prepending the BasePath. For example, with BasePath "/showcase" and path "/calendar/navigate", it returns "/showcase/calendar/navigate".

func (*Context) WatchScope added in v0.0.30

func (ctx *Context) WatchScope(scope string, baseKey string) string

WatchScope registers a scope watcher and returns its unique signal key. Multiple components can watch the same scope — each gets a distinct key so their data-effects don't interfere with each other.

func (*Context) WithContext added in v0.0.30

func (c *Context) WithContext(ctx context.Context) context.Context

WithContext stores the webx Context into a context.Context.

type MiddlewareConfig added in v0.0.30

type MiddlewareConfig struct {
	Secret []byte // HMAC-SHA256 key, minimum 32 bytes — panics if shorter
	Secure bool   // Secure flag on cookies (true for HTTPS / production)
}

MiddlewareConfig configures the webx middleware.

type Watcher added in v0.0.35

type Watcher struct {
	Scope string // e.g. "customers:*"
	Key   string // unique signal key, e.g. "customers_WILD", "customers_WILD_2"
}

Watcher pairs a scope with a unique signal key for that watcher. Multiple components can watch the same scope, each with its own key.

Directories

Path Synopsis
cmd
icongen command
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
showcase command
showcase/internal/components
templ: version: v0.3.977
templ: version: v0.3.977
showcase/internal/handlers
templ: version: v0.3.977
templ: version: v0.3.977
showcase/internal/layouts
templ: version: v0.3.977
templ: version: v0.3.977
showcase/internal/pages
templ: version: v0.3.977
templ: version: v0.3.977
Package ds provides typed helpers for Datastar HTML attributes.
Package ds provides typed helpers for Datastar HTML attributes.
templ: version: v0.3.977
templ: version: v0.3.977
Package pubsub defines the interface for publish/subscribe messaging used by the stream package.
Package pubsub defines the interface for publish/subscribe messaging used by the stream package.
chanpubsub
Package chanpubsub provides an in-process PubSub implementation backed by Go channels.
Package chanpubsub provides an in-process PubSub implementation backed by Go channels.
natspubsub
Package natspubsub adapts a *nats.Conn to the pubsub.PubSub interface.
Package natspubsub adapts a *nats.Conn to the pubsub.PubSub interface.
pubsubtest
Package pubsubtest provides a conformance test suite for PubSub implementations.
Package pubsubtest provides a conformance test suite for PubSub implementations.
redispubsub
Package redispubsub adapts a Redis client to the pubsub.PubSub interface using PUBLISH / SUBSCRIBE / PSUBSCRIBE.
Package redispubsub adapts a Redis client to the pubsub.PubSub interface using PUBLISH / SUBSCRIBE / PSUBSCRIBE.
templ: version: v0.3.977
templ: version: v0.3.977
ui
accordion
templ: version: v0.3.977
templ: version: v0.3.977
aichat
templ: version: v0.3.977
templ: version: v0.3.977
alert
templ: version: v0.3.977
templ: version: v0.3.977
avatar
templ: version: v0.3.977
templ: version: v0.3.977
badge
templ: version: v0.3.977
templ: version: v0.3.977
breadcrumbs
templ: version: v0.3.977
templ: version: v0.3.977
briefing
templ: version: v0.3.977
templ: version: v0.3.977
button
templ: version: v0.3.977
templ: version: v0.3.977
calendar
templ: version: v0.3.977
templ: version: v0.3.977
card
templ: version: v0.3.977
templ: version: v0.3.977
carousel
templ: version: v0.3.977
templ: version: v0.3.977
chat
templ: version: v0.3.977
templ: version: v0.3.977
codeview
templ: version: v0.3.977
templ: version: v0.3.977
commandbar
templ: version: v0.3.977
templ: version: v0.3.977
dock
templ: version: v0.3.977
templ: version: v0.3.977
drawer
templ: version: v0.3.977
templ: version: v0.3.977
dropdown
templ: version: v0.3.977
templ: version: v0.3.977
fab
templ: version: v0.3.977
templ: version: v0.3.977
feed
templ: version: v0.3.977
templ: version: v0.3.977
feeditem
templ: version: v0.3.977
templ: version: v0.3.977
fieldset
templ: version: v0.3.977
templ: version: v0.3.977
fileinput
templ: version: v0.3.977
templ: version: v0.3.977
fileupload
templ: version: v0.3.977
templ: version: v0.3.977
filter
templ: version: v0.3.977
templ: version: v0.3.977
footer
templ: version: v0.3.977
templ: version: v0.3.977
form
templ: version: v0.3.977
templ: version: v0.3.977
hovergallery
templ: version: v0.3.977
templ: version: v0.3.977
indicator
templ: version: v0.3.977
templ: version: v0.3.977
join
templ: version: v0.3.977
templ: version: v0.3.977
jsonview
templ: version: v0.3.977
templ: version: v0.3.977
kbd
templ: version: v0.3.977
templ: version: v0.3.977
label
templ: version: v0.3.977
templ: version: v0.3.977
link
templ: version: v0.3.977
templ: version: v0.3.977
list
templ: version: v0.3.977
templ: version: v0.3.977
loading
templ: version: v0.3.977
templ: version: v0.3.977
markdown
templ: version: v0.3.977
templ: version: v0.3.977
menu
templ: version: v0.3.977
templ: version: v0.3.977
mockupcode
templ: version: v0.3.977
templ: version: v0.3.977
modal
templ: version: v0.3.977
templ: version: v0.3.977
money
templ: version: v0.3.977
templ: version: v0.3.977
moneyinput
templ: version: v0.3.977
templ: version: v0.3.977
navbar
templ: version: v0.3.977
templ: version: v0.3.977
pagination
templ: version: v0.3.977
templ: version: v0.3.977
progress
templ: version: v0.3.977
templ: version: v0.3.977
radialprogress
templ: version: v0.3.977
templ: version: v0.3.977
radio
templ: version: v0.3.977
templ: version: v0.3.977
rangeinput
templ: version: v0.3.977
templ: version: v0.3.977
rating
templ: version: v0.3.977
templ: version: v0.3.977
scrollstrip
templ: version: v0.3.977
templ: version: v0.3.977
selectinput
templ: version: v0.3.977
templ: version: v0.3.977
separator
templ: version: v0.3.977
templ: version: v0.3.977
skeleton
templ: version: v0.3.977
templ: version: v0.3.977
sparkline
templ: version: v0.3.977
templ: version: v0.3.977
stack
templ: version: v0.3.977
templ: version: v0.3.977
stat
templ: version: v0.3.977
templ: version: v0.3.977
status
templ: version: v0.3.977
templ: version: v0.3.977
steps
templ: version: v0.3.977
templ: version: v0.3.977
tab
templ: version: v0.3.977
templ: version: v0.3.977
table
templ: version: v0.3.977
templ: version: v0.3.977
textarea
templ: version: v0.3.977
templ: version: v0.3.977
textrotate
templ: version: v0.3.977
templ: version: v0.3.977
themecontroller
templ: version: v0.3.977
templ: version: v0.3.977
timeline
templ: version: v0.3.977
templ: version: v0.3.977
toast
templ: version: v0.3.977
templ: version: v0.3.977
toggle
templ: version: v0.3.977
templ: version: v0.3.977
tooltip
templ: version: v0.3.977
templ: version: v0.3.977
validator
templ: version: v0.3.977
templ: version: v0.3.977
yamltree
templ: version: v0.3.977
templ: version: v0.3.977

Jump to

Keyboard shortcuts

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