Files
nebula/pkg/wa/intersection-observer_templ.go

342 lines
12 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.960
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-intersection-observer
package wa
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
import (
"github.com/a-h/templ"
)
// Tracks immediate child elements and fires events as they move in and out of view.
//
// Web Awesome component: <wa-intersection-observer>
// IntersectionObserverProps holds all properties for the wa-intersection-observer component
type IntersectionObserverProps struct {
// Element ID to define the viewport boundaries for tracked targets.
Root string `attr:"root"`
// Offset space around the root boundary. Accepts values like CSS margin syntax.
RootMargin string `attr:"root-margin"`
// One or more space-separated values representing visibility percentages that trigger the observer callback.
Threshold string `attr:"threshold"`
// CSS class applied to elements during intersection. Automatically removed when elements leave
IntersectClass string `attr:"intersect-class"`
// If enabled, observation ceases after initial intersection.
Once bool `attr:"once"`
// Deactivates the intersection observer functionality.
Disabled bool `attr:"disabled"`
// Events
// Fired when a tracked element begins or ceases intersecting.
OnIntersect string `attr:"x-on:wa-intersect"`
// Slots contains named slot content
Slots IntersectionObserverSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// IntersectionObserverBuilder provides a fluent API for constructing IntersectionObserverProps
type IntersectionObserverBuilder struct {
props IntersectionObserverProps
}
// NewIntersectionObserver creates a new builder for wa-intersection-observer
func NewIntersectionObserver() *IntersectionObserverBuilder {
return &IntersectionObserverBuilder{}
}
// Root sets the root attribute
// Element ID to define the viewport boundaries for tracked targets.
func (b *IntersectionObserverBuilder) Root(v string) *IntersectionObserverBuilder {
b.props.Root = v
return b
}
// RootMargin sets the root-margin attribute
// Offset space around the root boundary. Accepts values like CSS margin syntax.
func (b *IntersectionObserverBuilder) RootMargin(v string) *IntersectionObserverBuilder {
b.props.RootMargin = v
return b
}
// Threshold sets the threshold attribute
// One or more space-separated values representing visibility percentages that trigger the observer callback.
func (b *IntersectionObserverBuilder) Threshold(v string) *IntersectionObserverBuilder {
b.props.Threshold = v
return b
}
// IntersectClass sets the intersect-class attribute
// CSS class applied to elements during intersection. Automatically removed when elements leave
func (b *IntersectionObserverBuilder) IntersectClass(v string) *IntersectionObserverBuilder {
b.props.IntersectClass = v
return b
}
// Once sets the once attribute
// If enabled, observation ceases after initial intersection.
func (b *IntersectionObserverBuilder) Once(v bool) *IntersectionObserverBuilder {
b.props.Once = v
return b
}
// Disabled sets the disabled attribute
// Deactivates the intersection observer functionality.
func (b *IntersectionObserverBuilder) Disabled(v bool) *IntersectionObserverBuilder {
b.props.Disabled = v
return b
}
// OnIntersect sets the handler for wa-intersect event
// Fired when a tracked element begins or ceases intersecting.
func (b *IntersectionObserverBuilder) OnIntersect(handler string) *IntersectionObserverBuilder {
b.props.OnIntersect = handler
return b
}
// Attr adds a custom HTML attribute
func (b *IntersectionObserverBuilder) Attr(name, value string) *IntersectionObserverBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *IntersectionObserverBuilder) Attrs(attrs templ.Attributes) *IntersectionObserverBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
for k, v := range attrs {
b.props.Attrs[k] = v
}
return b
}
// Props returns the built properties
func (b *IntersectionObserverBuilder) Props() IntersectionObserverProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *IntersectionObserverBuilder) Build() IntersectionObserverProps {
return b.props
}
// IntersectionObserver renders the wa-intersection-observer component
func IntersectionObserver(props IntersectionObserverProps) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<wa-intersection-observer")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if props.Root != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " root=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(props.Root)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/intersection-observer.templ`, Line: 133, Col: 20}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.RootMargin != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " root-margin=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(props.RootMargin)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/intersection-observer.templ`, Line: 136, Col: 33}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.Threshold != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " threshold=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(props.Threshold)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/intersection-observer.templ`, Line: 139, Col: 30}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.IntersectClass != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " intersect-class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(props.IntersectClass)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/intersection-observer.templ`, Line: 142, Col: 41}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.Once {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, " once")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.Disabled {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " disabled")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.OnIntersect != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, " x-on:wa-intersect=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnIntersect)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/intersection-observer.templ`, Line: 151, Col: 40}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, props.Attrs)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, ">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</wa-intersection-observer>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
// IntersectionObserverFunc renders with a builder function for inline configuration
func IntersectionObserverFunc(fn func(*IntersectionObserverBuilder)) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var7 := templ.GetChildren(ctx)
if templ_7745c5c3_Var7 == nil {
templ_7745c5c3_Var7 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
b := NewIntersectionObserver()
fn(b)
templ_7745c5c3_Var8 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templ_7745c5c3_Var7.Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = IntersectionObserver(b.Props()).Render(templ.WithChildren(ctx, templ_7745c5c3_Var8), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate