webx

package module
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 8 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

View Source
const (
	ThemeSessionKey = "theme"
)

Variables

View Source
var Static embed.FS

Functions

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() func(http.Handler) http.Handler

SecurityHeadersMiddleware sets common security response headers.

func SessionMiddleware

func SessionMiddleware(store SessionStore) func(http.Handler) http.Handler

SessionMiddleware reads or creates a session cookie, then populates WebXContext with the session ID and CSRF token from the store.

Types

type BodyTag added in v0.0.3

type BodyTag struct {
	Tag string // e.g. "<datastar-inspector></datastar-inspector>"
}

BodyTag represents a custom element to inject at the end of <body>.

type Script added in v0.0.3

type Script struct {
	Src  string // script src attribute
	Type string // script type attribute (defaults to "module")
}

Script represents a <script> tag to inject in <head>.

type SessionStore

type SessionStore interface {
	Get(sessionID string, key string) (string, error)
	Set(sessionID string, key string, value string) error
	Delete(sessionID string) error
}

SessionStore provides session-scoped key/value storage. Implementations can back this with memory, NATS KV, Redis, etc.

type Stylesheet added in v0.0.3

type Stylesheet struct {
	Href string
}

Stylesheet represents a <link rel="stylesheet"> tag to inject in <head>.

type WebXContext

type WebXContext struct {
	CSRFToken   string
	DevMode     bool
	SessionID   string
	BasePath    string       // prefix for all SSE handler routes (e.g. "/showcase")
	Theme       string       // DaisyUI theme name applied via data-theme on <html>
	Store       SessionStore // session store for handlers that need to persist data
	StreamURL   string       // URL for the reactive SSE stream endpoint (e.g. "/showcase/stream")
	Stylesheets []Stylesheet
	Scripts     []Script
	BodyTags    []BodyTag
	Scopes      []string // reactive scopes accumulated during render by components
}

func FromContext

func FromContext(ctx context.Context) *WebXContext

func NewContext

func NewContext(ctx context.Context) *WebXContext

func (*WebXContext) APIPath

func (wctx *WebXContext) 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 "/api/calendar/navigate", it returns "/showcase/api/calendar/navigate".

func (*WebXContext) WatchScope added in v0.0.14

func (wctx *WebXContext) WatchScope(scope string)

WatchScope registers a scope to be watched by the stream SSE connection. Components call this during render to declare what data they depend on. Duplicates are ignored.

func (*WebXContext) WithContext

func (wctx *WebXContext) WithContext(ctx context.Context) context.Context

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
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

Jump to

Keyboard shortcuts

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