Files
nebula/pkg/wa/switch_templ.go

512 lines
17 KiB
Go
Raw Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by templ - DO NOT EDIT.
2026-01-01 20:49:44 -05:00
// templ: version: v0.3.960
2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-switch
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"
)
// Switches allow the user to toggle an option on or off.
//
// Web Awesome component: <wa-switch>
// SwitchProps holds all properties for the wa-switch component
type SwitchProps struct {
// The name of the switch, submitted as a name/value pair with form data.
Name string `attr:"name"`
// The value of the switch, submitted as a name/value pair with form data.
Value string `attr:"value"`
// The switch's size.
// Valid values: "small", "medium", "large"
Size string `attr:"size"`
// Disables the switch.
Disabled bool `attr:"disabled"`
// The default value of the form control. Primarily used for resetting the form control.
Checked bool `attr:"checked"`
// Makes the switch a required field.
Required bool `attr:"required"`
// The switch's hint. If you need to display HTML, use the hint slot instead.
Hint string `attr:"hint"`
// Used for SSR. If you slot in hint, make sure to add with-hint to your component to get it to properly render with SSR.
WithHint bool `attr:"with-hint"`
// Events
// Emitted when the control's checked state changes.
OnChange string `attr:"x-on:change"`
// Emitted when the control receives input.
OnInput string `attr:"x-on:input"`
// Emitted when the control loses focus.
OnBlur string `attr:"x-on:blur"`
// Emitted when the control gains focus.
OnFocus string `attr:"x-on:focus"`
// Emitted when the form control has been checked for validity and its constraints aren't satisfied.
OnInvalid string `attr:"x-on:wa-invalid"`
// Slots contains named slot content
Slots SwitchSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// SwitchSlots holds named slot content for the component
type SwitchSlots struct {
// Text that describes how to use the switch. Alternatively, you can use the hint attribute.
Hint templ.Component
}
// SwitchBuilder provides a fluent API for constructing SwitchProps
type SwitchBuilder struct {
props SwitchProps
}
// NewSwitch creates a new builder for wa-switch
func NewSwitch() *SwitchBuilder {
return &SwitchBuilder{}
}
// Name sets the name attribute
// The name of the switch, submitted as a name/value pair with form data.
func (b *SwitchBuilder) Name(v string) *SwitchBuilder {
b.props.Name = v
return b
}
// Value sets the value attribute
// The value of the switch, submitted as a name/value pair with form data.
func (b *SwitchBuilder) Value(v string) *SwitchBuilder {
b.props.Value = v
return b
}
// Size sets the size attribute
// The switch's size.
func (b *SwitchBuilder) Size(v string) *SwitchBuilder {
b.props.Size = v
return b
}
// Disabled sets the disabled attribute
// Disables the switch.
func (b *SwitchBuilder) Disabled(v bool) *SwitchBuilder {
b.props.Disabled = v
return b
}
// Checked sets the checked attribute
// The default value of the form control. Primarily used for resetting the form control.
func (b *SwitchBuilder) Checked(v bool) *SwitchBuilder {
b.props.Checked = v
return b
}
// Required sets the required attribute
// Makes the switch a required field.
func (b *SwitchBuilder) Required(v bool) *SwitchBuilder {
b.props.Required = v
return b
}
// Hint sets the hint attribute
// The switch's hint. If you need to display HTML, use the hint slot instead.
func (b *SwitchBuilder) Hint(v string) *SwitchBuilder {
b.props.Hint = v
return b
}
// WithHint sets the with-hint attribute
// Used for SSR. If you slot in hint, make sure to add with-hint to your component to get it to properly render with SSR.
func (b *SwitchBuilder) WithHint(v bool) *SwitchBuilder {
b.props.WithHint = v
return b
}
// OnChange sets the handler for change event
// Emitted when the control's checked state changes.
func (b *SwitchBuilder) OnChange(handler string) *SwitchBuilder {
b.props.OnChange = handler
return b
}
// OnInput sets the handler for input event
// Emitted when the control receives input.
func (b *SwitchBuilder) OnInput(handler string) *SwitchBuilder {
b.props.OnInput = handler
return b
}
// OnBlur sets the handler for blur event
// Emitted when the control loses focus.
func (b *SwitchBuilder) OnBlur(handler string) *SwitchBuilder {
b.props.OnBlur = handler
return b
}
// OnFocus sets the handler for focus event
// Emitted when the control gains focus.
func (b *SwitchBuilder) OnFocus(handler string) *SwitchBuilder {
b.props.OnFocus = handler
return b
}
// OnInvalid sets the handler for wa-invalid event
// Emitted when the form control has been checked for validity and its constraints aren't satisfied.
func (b *SwitchBuilder) OnInvalid(handler string) *SwitchBuilder {
b.props.OnInvalid = handler
return b
}
// HintSlot sets the hint slot content
// Text that describes how to use the switch. Alternatively, you can use the hint attribute.
func (b *SwitchBuilder) HintSlot(c templ.Component) *SwitchBuilder {
b.props.Slots.Hint = c
return b
}
// Attr adds a custom HTML attribute
func (b *SwitchBuilder) Attr(name, value string) *SwitchBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *SwitchBuilder) Attrs(attrs templ.Attributes) *SwitchBuilder {
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 *SwitchBuilder) Props() SwitchProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *SwitchBuilder) Build() SwitchProps {
return b.props
}
// Switch renders the wa-switch component
func Switch(props SwitchProps) 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-switch")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if props.Name != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " name=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(props.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 201, 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.Value != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(props.Value)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 204, Col: 22}
}
_, 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.Size != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " size=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(props.Size)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 207, Col: 20}
}
_, 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.Disabled {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " disabled")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.Checked {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, " checked")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.Required {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, " required")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.Hint != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " hint=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(props.Hint)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 219, Col: 20}
}
_, 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, 12, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.WithHint {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " with-hint")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.OnChange != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, " x-on:change=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnChange)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 225, Col: 31}
}
_, 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, 15, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.OnInput != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, " x-on:input=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnInput)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 228, Col: 29}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.OnBlur != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, " x-on:blur=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnBlur)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 231, Col: 27}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.OnFocus != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " x-on:focus=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnFocus)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 234, Col: 29}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if props.OnInvalid != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, " x-on:wa-invalid=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnInvalid)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/switch.templ`, Line: 237, Col: 36}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\"")
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, 24, ">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if props.Slots.Hint != nil {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<div slot=\"hint\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = props.Slots.Hint.Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</div>")
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, 27, "</wa-switch>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
// SwitchFunc renders with a builder function for inline configuration
func SwitchFunc(fn func(*SwitchBuilder)) 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_Var11 := templ.GetChildren(ctx)
if templ_7745c5c3_Var11 == nil {
templ_7745c5c3_Var11 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
b := NewSwitch()
fn(b)
templ_7745c5c3_Var12 := 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_Var11.Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = Switch(b.Props()).Render(templ.WithChildren(ctx, templ_7745c5c3_Var12), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate