Documentation
¶
Overview ¶
Package utils provides shared types, Tailwind class merging, and generic helpers used across all templ-components packages.
BaseProps is embedded by every component props struct for consistent ID, Class, Attrs, AriaLabel, and Nonce propagation. Class() merges Tailwind classes with conflict resolution via tailwind-merge-go.
Package utils provides shared utilities for templ components including Tailwind class merging, attribute helpers, and test rendering utilities.
Index ¶
- func AssertContains(t *testing.T, output, want string)
- func AssertContainsClass(t *testing.T, output, class string)
- func AssertEqual[T comparable](t *testing.T, context string, got, want T)
- func AssertNotContains(t *testing.T, output, notWant string)
- func Class(classes ...string) string
- func CurrentYear() string
- func DismissScript() string
- func MapEnum[T ~string](m map[string]T, fallback T, key string) T
- func Render(t *testing.T, c templ.Component) string
- func Ternary[T any](condition bool, a, b T) T
- type BaseProps
- type ComponentProps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
AssertContains checks that the rendered output contains a substring
func AssertContainsClass ¶
AssertContainsClass checks that the rendered output contains a CSS class in a class attribute. Handles classes embedded in larger class strings.
func AssertEqual ¶
func AssertEqual[T comparable](t *testing.T, context string, got, want T)
AssertEqual checks that got equals want, reporting a test error with context if not
func AssertNotContains ¶
AssertNotContains checks that the rendered output does not contain a substring
func Class ¶
Class merges Tailwind classes intelligently using tailwind-merge-go. Conflicting classes are resolved with later arguments overriding earlier ones. Thread-safe via sync.Mutex to protect the shared LRU cache.
func DismissScript ¶
func DismissScript() string
DismissScript returns shared JavaScript for dismissing elements via [data-dismiss] click delegation. Used by Alert, Toast, and ErrorAlert components.
func MapEnum ¶
MapEnum looks up a string key in a map and returns the corresponding enum value, or the fallback if the key is not found.
Types ¶
type BaseProps ¶
type BaseProps struct {
ID string
Class string
Attrs templ.Attributes
AriaLabel string
Nonce string
}
BaseProps provides common configurable attributes for all components
func (*BaseProps) GetBaseProps ¶
GetBaseProps returns the embedded BaseProps. This method is promoted to all structs that embed BaseProps, satisfying the ComponentProps interface.
func (*BaseProps) SetBaseProps ¶
SetBaseProps updates the embedded BaseProps. This method is promoted to all structs that embed BaseProps, satisfying the ComponentProps interface.
type ComponentProps ¶
ComponentProps is the interface implemented by all component props structs that embed BaseProps. It enables generic component composition, validation, and wrapper functions across the entire component library.