Files
nebula/pkg/wa/animation.templ

250 lines
7.6 KiB
Plaintext
Raw Permalink Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-animation
package wa
import (
"github.com/a-h/templ"
)
// Animate elements declaratively with nearly 100 baked-in presets, or roll your own with custom keyframes. Powered by t...
//
// Web Awesome component: <wa-animation>
// AnimationProps holds all properties for the wa-animation component
type AnimationProps struct {
// The name of the built-in animation to use. For custom animations, use the keyframes prop.
Name string `attr:"name"`
// Plays the animation. When omitted, the animation will be paused. This attribute will be automatically removed when
Play bool `attr:"play"`
// The number of milliseconds to delay the start of the animation.
Delay float64 `attr:"delay"`
// Determines the direction of playback as well as the behavior when reaching the end of an iteration.
Direction string `attr:"direction"`
// The number of milliseconds each iteration of the animation takes to complete.
Duration float64 `attr:"duration"`
// The easing function to use for the animation. This can be a Web Awesome easing function or a custom easing function
Easing string `attr:"easing"`
// The number of milliseconds to delay after the active period of an animation sequence.
EndDelay float64 `attr:"end-delay"`
// Sets how the animation applies styles to its target before and after its execution.
Fill string `attr:"fill"`
// The number of iterations to run before the animation completes. Defaults to Infinity, which loops.
Iterations float64 `attr:"iterations"`
// The offset at which to start the animation, usually between 0 (start) and 1 (end).
IterationStart float64 `attr:"iteration-start"`
// Sets the animation's playback rate. The default is 1, which plays the animation at a normal speed. Setting this
PlaybackRate float64 `attr:"playback-rate"`
// Events
// Emitted when the animation is canceled.
OnCancel string `attr:"x-on:wa-cancel"`
// Emitted when the animation finishes.
OnFinish string `attr:"x-on:wa-finish"`
// Emitted when the animation starts or restarts.
OnStart string `attr:"x-on:wa-start"`
// Slots contains named slot content
Slots AnimationSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// AnimationBuilder provides a fluent API for constructing AnimationProps
type AnimationBuilder struct {
props AnimationProps
}
// NewAnimation creates a new builder for wa-animation
func NewAnimation() *AnimationBuilder {
return &AnimationBuilder{}
}
// Name sets the name attribute
// The name of the built-in animation to use. For custom animations, use the keyframes prop.
func (b *AnimationBuilder) Name(v string) *AnimationBuilder {
b.props.Name = v
return b
}
// Play sets the play attribute
// Plays the animation. When omitted, the animation will be paused. This attribute will be automatically removed when
func (b *AnimationBuilder) Play(v bool) *AnimationBuilder {
b.props.Play = v
return b
}
// Delay sets the delay attribute
// The number of milliseconds to delay the start of the animation.
func (b *AnimationBuilder) Delay(v float64) *AnimationBuilder {
b.props.Delay = v
return b
}
// Direction sets the direction attribute
// Determines the direction of playback as well as the behavior when reaching the end of an iteration.
func (b *AnimationBuilder) Direction(v string) *AnimationBuilder {
b.props.Direction = v
return b
}
// Duration sets the duration attribute
// The number of milliseconds each iteration of the animation takes to complete.
func (b *AnimationBuilder) Duration(v float64) *AnimationBuilder {
b.props.Duration = v
return b
}
// Easing sets the easing attribute
// The easing function to use for the animation. This can be a Web Awesome easing function or a custom easing function
func (b *AnimationBuilder) Easing(v string) *AnimationBuilder {
b.props.Easing = v
return b
}
// EndDelay sets the end-delay attribute
// The number of milliseconds to delay after the active period of an animation sequence.
func (b *AnimationBuilder) EndDelay(v float64) *AnimationBuilder {
b.props.EndDelay = v
return b
}
// Fill sets the fill attribute
// Sets how the animation applies styles to its target before and after its execution.
func (b *AnimationBuilder) Fill(v string) *AnimationBuilder {
b.props.Fill = v
return b
}
// Iterations sets the iterations attribute
// The number of iterations to run before the animation completes. Defaults to Infinity, which loops.
func (b *AnimationBuilder) Iterations(v float64) *AnimationBuilder {
b.props.Iterations = v
return b
}
// IterationStart sets the iteration-start attribute
// The offset at which to start the animation, usually between 0 (start) and 1 (end).
func (b *AnimationBuilder) IterationStart(v float64) *AnimationBuilder {
b.props.IterationStart = v
return b
}
// PlaybackRate sets the playback-rate attribute
// Sets the animation's playback rate. The default is 1, which plays the animation at a normal speed. Setting this
func (b *AnimationBuilder) PlaybackRate(v float64) *AnimationBuilder {
b.props.PlaybackRate = v
return b
}
// OnCancel sets the handler for wa-cancel event
// Emitted when the animation is canceled.
func (b *AnimationBuilder) OnCancel(handler string) *AnimationBuilder {
b.props.OnCancel = handler
return b
}
// OnFinish sets the handler for wa-finish event
// Emitted when the animation finishes.
func (b *AnimationBuilder) OnFinish(handler string) *AnimationBuilder {
b.props.OnFinish = handler
return b
}
// OnStart sets the handler for wa-start event
// Emitted when the animation starts or restarts.
func (b *AnimationBuilder) OnStart(handler string) *AnimationBuilder {
b.props.OnStart = handler
return b
}
// Attr adds a custom HTML attribute
func (b *AnimationBuilder) Attr(name, value string) *AnimationBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *AnimationBuilder) Attrs(attrs templ.Attributes) *AnimationBuilder {
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 *AnimationBuilder) Props() AnimationProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *AnimationBuilder) Build() AnimationProps {
return b.props
}
// Animation renders the wa-animation component
templ Animation(props AnimationProps) {
<wa-animation
if props.Name != "" {
name={ props.Name }
}
if props.Play {
play
}
if props.Delay != 0 {
delay={ templ.Sprintf("%v", props.Delay) }
}
if props.Direction != "" {
direction={ props.Direction }
}
if props.Duration != 0 {
duration={ templ.Sprintf("%v", props.Duration) }
}
if props.Easing != "" {
easing={ props.Easing }
}
if props.EndDelay != 0 {
end-delay={ templ.Sprintf("%v", props.EndDelay) }
}
if props.Fill != "" {
fill={ props.Fill }
}
if props.Iterations != 0 {
iterations={ templ.Sprintf("%v", props.Iterations) }
}
if props.IterationStart != 0 {
iteration-start={ templ.Sprintf("%v", props.IterationStart) }
}
if props.PlaybackRate != 0 {
playback-rate={ templ.Sprintf("%v", props.PlaybackRate) }
}
if props.OnCancel != "" {
x-on:wa-cancel={ props.OnCancel }
}
if props.OnFinish != "" {
x-on:wa-finish={ props.OnFinish }
}
if props.OnStart != "" {
x-on:wa-start={ props.OnStart }
}
{ props.Attrs... }
>
{ children... }
</wa-animation>
}
// AnimationFunc renders with a builder function for inline configuration
templ AnimationFunc(fn func(*AnimationBuilder)) {
{{ b := NewAnimation(); fn(b) }}
@Animation(b.Props()) {
{ children... }
}
}