components

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 5 Imported by: 29

Documentation

Overview

Package components provides high-level components and helpers that are composed of low-level elements and attributes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTML5

func HTML5(p HTML5Props) g.Node

HTML5 document template.

func JoinAttrs added in v1.2.0

func JoinAttrs(name string, children ...g.Node) g.Node

JoinAttrs with the given name only on the first level of the given nodes. This means that attributes on non-direct descendants are ignored. Attribute values are joined by spaces. Note that this renders all first-level attributes to check whether they should be processed.

Example
danceButton := myPrimaryButton("Dance")
_ = danceButton.Render(os.Stdout)
Output:

<div class="primary button">Dance</div>

Types

type Classes

type Classes map[string]bool

Classes is a map of strings to booleans, which Renders to an attribute with name "class". The attribute value is a sorted, space-separated string of all the map keys, for which the corresponding map value is true.

Example
e := g.El("div", Classes{"party-hat": true, "boring-hat": false})
_ = e.Render(os.Stdout)
Output:

<div class="party-hat"></div>

func (Classes) Render

func (c Classes) Render(w io.Writer) error

Render satisfies g.Node.

func (Classes) String

func (c Classes) String() string

String satisfies fmt.Stringer.

func (Classes) Type

func (c Classes) Type() g.NodeType

type HTML5Props

type HTML5Props struct {
	Title       string
	Description string
	Language    string
	Head        []g.Node
	Body        []g.Node
	HTMLAttrs   []g.Node
}

HTML5Props for HTML5. Title is set no matter what, Description and Language elements only if the strings are non-empty.

Jump to

Keyboard shortcuts

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