props

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Copyright 2025 Deirror. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 Deirror. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Package props provides helper types and functions to manage HTML attributes in templ. It includes the Attrs type, which wraps templ.Attributes and provides convenient methods for chaining, merging, and manipulating attributes.

Copyright 2025 Deirror. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 Deirror. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 Deirror. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstOrDefault added in v0.2.0

func FirstOrDefault[T any](def T, props ...T) T

FirstOrDefault returns the first value from props if any are provided. Otherwise, it returns the default value def.

Types

type Attrs

type Attrs struct {
	templ.Attributes
}

Attrs wraps templ.Attributes and adds helper functions.

func (Attrs) AsTemplAttrs

func (a Attrs) AsTemplAttrs() templ.Attributes

AsTemplAttrs flattens all nested Props (Aria, Hx, Data, Attrs) into a single set of templ.Attributes.

func (Attrs) Merge

func (a Attrs) Merge(other Attrs) Attrs

Merge merges another Attrs into this one.

func (Attrs) With

func (a Attrs) With(key, val string) Attrs

With sets given key attribute with string val.

func (Attrs) WithClass

func (a Attrs) WithClass(class string) Attrs

WithClass sets or appends a class.

func (Attrs) WithID

func (a Attrs) WithID(id string) Attrs

WithID sets the id attribute.

func (Attrs) WithStyle added in v0.3.0

func (a Attrs) WithStyle(style string) Attrs

WithStyle sets or appends a style attribute.

type AttrsProvider added in v0.5.0

type AttrsProvider interface {
	AsTemplAttrs() templ.Attributes
}

AttrsProvider prepares all attributes into one merged templ.Attributes which is used in the html tags.

type EmptyAttrsProvider added in v0.5.0

type EmptyAttrsProvider struct{}

EmptyAttrsProvider is a no-op AttrsProvider. It can be used when you want to render an element without any attributes.

func (EmptyAttrsProvider) AsTemplAttrs added in v0.5.0

func (e EmptyAttrsProvider) AsTemplAttrs() templ.Attributes

AsTemplAttrs returns an empty templ.Attributes map.

type Key added in v0.5.0

type Key = string
const (
	ID    Key = "id"
	Class Key = "class"
	Style Key = "style"

	Disabled    Key = "disabled"
	Type        Key = "type"
	Href        Key = "href"
	Name        Key = "name"
	Multiple    Key = "multiple"
	Required    Key = "required"
	Value       Key = "value"
	Selected    Key = "selected"
	Method      Key = "method"
	EncType     Key = "enctype"
	Target      Key = "target"
	NoValidate  Key = "novalidate"
	Placeholder Key = "placeholder"
	ReadOnly    Key = "readonly"
	Checked     Key = "checked"
	For         Key = "for"
	Min         Key = "min"
	Max         Key = "max"
	Low         Key = "low"
	High        Key = "high"
	Optimum     Key = "optimum"
	AriaLabel   Key = "aria-label"
	Src         Key = "src"
	Alt         Key = "alt"
	Controls    Key = "controls"
	Autoplay    Key = "autoplay"
	Loop        Key = "loop"
	Muted       Key = "muted"
	Width       Key = "width"
	Height      Key = "height"
	PlaysInline Key = "playsinline"
	Cols        Key = "cols"
	Rows        Key = "rows"
	Role        Key = "role"
)

Directories

Path Synopsis
Package aria provides helpers for building ARIA (Accessible Rich Internet Applications) attributes in HTML elements using the templ system.
Package aria provides helpers for building ARIA (Accessible Rich Internet Applications) attributes in HTML elements using the templ system.
Package data provides helpers for building HTML data-* attributes in templ components.
Package data provides helpers for building HTML data-* attributes in templ components.
Package hx provides helpers for building htmx (hx-*) attributes in templ components.
Package hx provides helpers for building htmx (hx-*) attributes in templ components.

Jump to

Keyboard shortcuts

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