166 lines
5.0 KiB
Plaintext
166 lines
5.0 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-intersection-observer
|
|
|
|
package wa
|
|
|
|
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
|
|
templ IntersectionObserver(props IntersectionObserverProps) {
|
|
<wa-intersection-observer
|
|
if props.Root != "" {
|
|
root={ props.Root }
|
|
}
|
|
if props.RootMargin != "" {
|
|
root-margin={ props.RootMargin }
|
|
}
|
|
if props.Threshold != "" {
|
|
threshold={ props.Threshold }
|
|
}
|
|
if props.IntersectClass != "" {
|
|
intersect-class={ props.IntersectClass }
|
|
}
|
|
if props.Once {
|
|
once
|
|
}
|
|
if props.Disabled {
|
|
disabled
|
|
}
|
|
if props.OnIntersect != "" {
|
|
x-on:wa-intersect={ props.OnIntersect }
|
|
}
|
|
{ props.Attrs... }
|
|
>
|
|
{ children... }
|
|
</wa-intersection-observer>
|
|
}
|
|
|
|
// IntersectionObserverFunc renders with a builder function for inline configuration
|
|
templ IntersectionObserverFunc(fn func(*IntersectionObserverBuilder)) {
|
|
{{ b := NewIntersectionObserver(); fn(b) }}
|
|
@IntersectionObserver(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|