ui

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-htmx-ui

Composable Go + templ + Tailwind UI components with embedded styles and optional charts. Designed to work with HTMX, server-rendered pages and application-owned SSE updates.

go get github.com/marcuoli/go-htmx-ui@v0.5.0

Render a widget

import ui "github.com/marcuoli/go-htmx-ui"

templ Summary() {
    @ui.Widget(ui.WidgetProps{}) {
        @ui.WidgetHeader(ui.WidgetHeaderProps{Title: "Requests", Count: "123456"})
        @ui.WidgetMetric("Input tokens", "682888", "Reported usage")
    }
}

Commit your generated templ Go files as usual. Ordinary Go consumers do not need Node or the templ generator.

Serve the assets

mux.Handle("GET /assets/ui/", http.StripPrefix("/assets/ui/",
    http.FileServer(http.FS(ui.Assets()))))
<link rel="stylesheet" href="/assets/ui/ui.css">
<!-- Optional, for charts only; keep this order. -->
<script src="/assets/ui/echarts.min.js" defer></script>
<script src="/assets/ui/charts.js" defer></script>

Choose any asset URL prefix. The library has no router, authentication, database, CDN, font or network transport dependency. Assets include the unmodified official Apache ECharts 6.1.0 full bundle and its required third-party notices.

Components

Widgets, widget headers, metrics, exact/compact values, chart canvases, empty states, data disclosures, page headers, action groups, tabs, buttons, link buttons, labeled fields, inputs, selects, dialog shells/headers/bodies, badges and version labels.

See component and integration guide for props, slots, theme tokens, chart lifecycle, accessibility and boundaries. Tables remain in go-htmx-table; compose them inside widgets rather than copying a table implementation.

Showcase

go run ./examples/showcase -listen 127.0.0.1:8099

Open http://127.0.0.1:8099 for synthetic dark/light widgets, forms, a modal, an updating chart and composition with published go-htmx-table v0.1.0. Example page layout and table styling belong to the example.

Application metadata uses go-versioning v0.1.1. Pass validated application build information to ui.VersionLabel; the component never probes Git, the working directory or the UI dependency's module version. An unversioned example correctly displays 0.0.0+unknown. Library releases use conventional Go module tags (v0.2.0), separate from consuming applications' date/PR build versions.

Repository layout

go-htmx-ui/
├── *.go, *.templ       # Public ui components and generated Go
├── web/
│   ├── assets/        # Embedded CSS, JavaScript and license notices
│   ├── styles/        # Canonical Tailwind sources
│   ├── scripts/       # Frontend build tooling
│   ├── tests/         # JavaScript contract tests
│   └── package*.json  # Frontend dependency manifest and lockfile
├── examples/showcase/
├── docs/
└── .github/workflows/

The public Go package stays at the module root. ui.Assets() returns the same asset filenames regardless of their source directory, so consumers keep their imports and asset URLs. Go tests remain beside their Go source files.

Compatibility

Tested with Go 1.27.3 and templ 0.3.1070. Generated files are included. The newer templ 0.3.1100 runtime removes APIs used by this generator and published go-htmx-table v0.1.0; upgrading that runtime requires compatible regenerated releases of both libraries. Do not assume arbitrary templ runtime versions are interchangeable.

Development

go run github.com/a-h/templ/cmd/templ@v0.3.1070 generate
npm --prefix web ci
npm --prefix web run build
npm --prefix web test
go test ./...
go vet ./...
go mod verify

web/styles/components.css is the canonical Tailwind source. web/assets/ui.css is generated without preflight, global body styles or fonts. The build scopes Tailwind fallback initialization and namespaces its internal custom properties. Applications can use the prebuilt CSS or adapt the source into their asset pipeline; preserve those isolation steps. App layout classes stay outside this library.

For dependencies outside the checkout, set GO_HTMX_UI_NODE_MODULES to an absolute node_modules directory containing the pinned frontend dependencies. The asset builder resolves sources relative to its own script and uses the OS temporary directory selected by the caller (for example, TEMP/TMPDIR). Generated assets are always written to web/assets/.

MIT license. See third-party notices.

ECharts migration

Version0.2.0 uses Apache ECharts while preserving Go widget props, the canvas host, GoHTMXUI.charts.render/destroy, and the existing core JSON chart spec. New layouts load echarts.min.js before charts.js; the old chart.umd.js URL remains a virtual alias to that same bundle. No window.Chart implementation is provided. Arbitrary Chart.js plugin/options APIs are outside the shared spec.

The adapter supports line/bar/doughnut, mixed line/bar series, independent value axes and units, real timestamp axes, explicit ranges/null gaps, grouped legends, pre-binned histograms, currency and safe text tooltips. See the declarative spec and synthetic showcase. Consumer data collection, transport, permissions and preferences remain outside the library. Canvas is the supported host/renderer in this release.

Preserve _echarts_instance_, data-zr-dom-id, canvas dimensions/styles and all engine-owned children during live DOM patches. The showcase exercises resize, hidden recovery, mode/theme changes and grouped legends. Real-engine SVG tests verify option translation; browser checks separately cover the Canvas lifecycle.

For retained build evidence, pass --output-dir /absolute/artifact/directory and --write-source to the asset builder. With no arguments it stages in the caller's temporary directory and deliberately promotes checked-in assets for normal builds/CI. The builder verifies the exact locked official npm distribution and copies its bytes/notices unchanged; echarts.provenance.json records hashes.

Monitoring charts support explicit IEC/decimal byte and throughput conversions, locale/timezone and translated fallbacks, and optional axis labels/point markers. See the shared contract and JavaScript-only integration. The synthetic showcase includes130px charts with1800 samples; applications keep ownership of collection, transport, history and business calculations.

The general chart support matrix documents line/area/bar, pie/ring, scatter/bubble, heatmap, radar, gauge and microchart usage; zoom/pan, safe DOM events, loading and JS-only integration are part of the shared contract.

Metric units cover case-sensitive bits/bytes, SI/IEC prefixes, /s/min/h/d time bases, matching named rates and explicit custom conversion rules. Applications can switch display units live while raw samples remain unchanged.

Documentation

Overview

templ: version: v0.3.1070

Package ui provides composable templ components, Tailwind styles and optional chart rendering. Applications retain their routes, permissions and live transport.

templ: version: v0.3.1070

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Actions

func Actions() templ.Component

func Assets

func Assets() fs.FS

Assets hides the repository layout: consumers continue to see ui.css, charts.js and vendor filenames without a web/assets prefix. Serve with http.FileServer and http.StripPrefix at the application's chosen URL; no router is required.

func Badge

func Badge() templ.Component

func Button

func Button(props ButtonProps) templ.Component

func Dialog

func Dialog(props DialogProps) templ.Component

Dialog supplies the native shell; apps explicitly open it and own close/focus behavior, form submission and authorization. No content is moved or fetched here.

func DialogBody

func DialogBody() templ.Component

func DialogHeader

func DialogHeader(props DialogHeaderProps) templ.Component

func Field

func Field(props FieldProps) templ.Component

func Input

func Input(props InputProps) templ.Component

func LinkButton

func LinkButton(props LinkButtonProps) templ.Component

func MetricText

func MetricText(value string) string

Format only numeric metric labels. Keep units, unavailable values, small precise costs and partial-coverage qualifiers in their original form.

func PageHeader(props PageHeaderProps) templ.Component

func Select

func Select(props SelectProps) templ.Component

func Tab

func Tab(props TabProps) templ.Component

func Tabs

func Tabs(label string) templ.Component

func VersionLabel

func VersionLabel(info versioning.Info) templ.Component

func Widget

func Widget(props WidgetProps) templ.Component

Keep the existing root element, classes and live attributes without adding a wrapper: table scrolling, semantic landmarks and DOM patch identity depend on them.

func WidgetChart

func WidgetChart(props WidgetChartProps) templ.Component

The stable canvas and fallback remain siblings. ECharts sizes its Canvas renderer from the parent frame and keeps one instance across live snapshots.

func WidgetData

func WidgetData(label string) templ.Component

func WidgetEmpty

func WidgetEmpty() templ.Component

func WidgetHeader

func WidgetHeader(props WidgetHeaderProps) templ.Component

The children slot holds the view's actions or badges. Counts retain exact tooltips while using the same compact formatter as other numeric widgets.

func WidgetMetric

func WidgetMetric(label, value, note string) templ.Component

func WidgetMetricFrame

func WidgetMetricFrame(props WidgetMetricProps) templ.Component

func WidgetMetricValue

func WidgetMetricValue(value, exact string) templ.Component

Types

type ButtonKind

type ButtonKind string
const (
	Primary   ButtonKind = "primary"
	Secondary ButtonKind = "secondary"
	Danger    ButtonKind = "danger"
)

type ButtonProps

type ButtonProps struct {
	Type, Class string
	Kind        ButtonKind
	Disabled    bool
	Attributes  templ.Attributes
}

type DialogHeaderProps

type DialogHeaderProps struct{ TitleID, Title, Description string }

type DialogProps

type DialogProps struct {
	ID, TitleID, Class string
	Attributes         templ.Attributes
}

type FieldProps

type FieldProps struct {
	For, Label, Hint, Class string
	Attributes              templ.Attributes
}

type InputProps

type InputProps struct {
	ID, Name, Value, Type, Placeholder, Class string
	Required, Disabled                        bool
	Attributes                                templ.Attributes
}

type LinkButtonProps

type LinkButtonProps struct {
	Href, Class string
	Kind        ButtonKind
	Attributes  templ.Attributes
}

type Option

type Option struct {
	Value, Label string
	Disabled     bool
}

type PageHeaderProps

type PageHeaderProps struct {
	Title, Description, Class string
	Attributes                templ.Attributes
}

Presentation props accept server-defined attributes for HTMX and other callers. Permissions, CSRF fields and event handlers remain the application's responsibility.

type SelectProps

type SelectProps struct {
	ID, Name, Value, Class string
	Options                []Option
	Required, Disabled     bool
	Attributes             templ.Attributes
}

type TabProps

type TabProps struct {
	Label, Href, Class string
	Active             bool
	Attributes         templ.Attributes
}

type WidgetChartProps

type WidgetChartProps struct {
	ID, Spec, Label            string
	EmptyMessage, NoScriptNote string
	// ErrorMessage also applies when malformed JSON cannot supply messages.error.
	ErrorMessage string
	Compact      bool
}

Spec is the feature's serialized chart configuration. It stays in an escaped attribute so the shared live renderer can reuse the existing canvas by ID. Specs use the documented shared core, not arbitrary renderer-specific options.

type WidgetElement

type WidgetElement uint8

WidgetElement preserves the semantic containers used by existing pages. A closed set prevents callers from constructing arbitrary HTML tag names.

const (
	WidgetSection WidgetElement = iota
	WidgetDiv
	WidgetAside
	WidgetNav
)

type WidgetHeaderProps

type WidgetHeaderProps struct {
	Title, Description, Count           string
	Class, TitleClass, DescriptionClass string
}

type WidgetMetricProps

type WidgetMetricProps struct {
	Label, Note string
	Heading     bool
}

type WidgetProps

type WidgetProps struct {
	Element    WidgetElement
	Class      string
	Attributes templ.Attributes
}

WidgetProps contains presentation and trusted, server-defined attributes. Feature views retain responsibility for permission checks, links and data.

Directories

Path Synopsis
examples
showcase command
templ: version: v0.3.1070
templ: version: v0.3.1070

Jump to

Keyboard shortcuts

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