// Code generated by templ - DO NOT EDIT. // templ: version: v0.3.960 // 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: // 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, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if props.Slots.Hint != nil { templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "
") 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, "
") 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, "
") 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