ui

package module
v0.0.0-...-73a5773 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 14 Imported by: 0

README

Kheeper UI

Tools for authoring server-side components in Go.

Component CSS & JS

The CSS for all registered components is bundled and served together. The bundle will be served at /css/<version>.css. The version is the first 7 characters of the sha256 hex digest of the bundle.

Likewise, JS for all components is bundled and served at /js/<version>.js.

A link to each bundle is injected into the head of every page. Additionally, a Link preload header is emitted in the response for every page to enable Early Hints.

Static

Recipes

Add

Tailwind

All components may use Tailwind classes. In development the Tailwind browser library provides support for all classes.

[!Important] If a component requires a Tailwind class then it must implement the Examples interface and use the class at least once in an example. The optimized release CSS will only include Tailwind classes that appear in an example.

Use air to watch and rebuild your project on any changes.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParsePage = html.Parse

Functions

func Clone

func Clone(n *html.Node) *html.Node

func Must

func Must(reg Registry, uifs fs.FS, opts Options) *http.ServeMux

func New

func New(reg Registry, uifs fs.FS, opts Options) (*http.ServeMux, error)

New creates a ServeMux with a handler for each page and each public file. The fs argument must contain directories named "public" and "pages".

func ParseComponent

func ParseComponent(r io.Reader) (*html.Node, error)

ParseComponent removes the doc, html, body wrapper added by net/html.Parse. If you call html.Parse("<MyComponent></MyComponent>") it will return "<doc><html><head></head><body><MyComponent></MyComponent></body></html>"

Types

type Attributes

type Attributes map[string][]string

Attributes represents the key-value pairs in an HTML element.

func (Attributes) Get

func (a Attributes) Get(key string) string

Get returns the last value associated with the key.

func (Attributes) GetHas

func (a Attributes) GetHas(key string) (string, bool)

GetHas returns the last value associated with the given key.

func (Attributes) GetOr

func (a Attributes) GetOr(key, def string) string

GetOr returns the attribute value if set, otherwise returns the default from the 2nd argument.

func (Attributes) Has

func (a Attributes) Has(key string) bool

Has is used with boolean attributes.

func (Attributes) Set

func (a Attributes) Set(key string, val string)

type CatalogOptions

type CatalogOptions struct {
	// Prefix is the path where the UI server is mounted if other than the root
	// path.
	Prefix string
	// Path is the path where the catalog is served. Do not include the Prefix.
	// Default is "/catalog".
	Path   string
	Logger *slog.Logger
}

type Class

type Class struct {
	Class string
	Test  bool
}

type Classes

type Classes []Class

func (Classes) String

func (classes Classes) String() string

type Component

type Component interface {
	Render(r *http.Request, attributes Attributes) (*html.Node, error)
}

type Examples

type Examples interface {
	Examples() embed.FS
}

Examples is an optional component interface used to add variants of the component to the catalog. It is also used to ensure that all classes the component makes use of are included in the Tailwind release build.

type Options

type Options struct {
	// The UI server will be mounted at this point
	Prefix string

	// Render and serve all files under this directory
	PagesRoot string
	// Serve all files under this directory unmodified
	PublicRoot string

	// Logger to use for messages and errors
	Logger *slog.Logger

	// Serve a component catalog at this path
	CatalogPath string

	// Reload browser when air restarts the app.
	LiveReload bool
}

type Registry

type Registry map[string]Component

func (Registry) Add

func (r Registry) Add(name string, c Component) error

func (Registry) CSS

func (reg Registry) CSS() ([]byte, error)

func (Registry) JS

func (reg Registry) JS() ([]byte, error)

func (Registry) Render

func (reg Registry) Render(r *http.Request, self *html.Node) (*html.Node, error)

type Scripted

type Scripted interface {
	JS() (string, error)
}

If a Component implements the Scripted interface then its JS will be added to the app's JS bundle served with every page.

type Styled

type Styled interface {
	CSS() (string, error)
}

If a Component implements the Styled interface then its CSS will be added to the app's CSS bundle served with every page.

Directories

Path Synopsis
components
neobrutal/button
build !release
build !release
neobrutal/card
build !release
build !release
neobrutal/checkbox
build !release
build !release
neobrutal/dialog
build !release
build !release
neobrutal/dropdown
build !release
build !release
neobrutal/leftsidebar
build !release
build !release

Jump to

Keyboard shortcuts

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