Files
nebula/pkg/wa/switch.templ

257 lines
6.6 KiB
Plaintext

// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-switch
package wa
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
templ Switch(props SwitchProps) {
<wa-switch
if props.Name != "" {
name={ props.Name }
}
if props.Value != "" {
value={ props.Value }
}
if props.Size != "" {
size={ props.Size }
}
if props.Disabled {
disabled
}
if props.Checked {
checked
}
if props.Required {
required
}
if props.Hint != "" {
hint={ props.Hint }
}
if props.WithHint {
with-hint
}
if props.OnChange != "" {
x-on:change={ props.OnChange }
}
if props.OnInput != "" {
x-on:input={ props.OnInput }
}
if props.OnBlur != "" {
x-on:blur={ props.OnBlur }
}
if props.OnFocus != "" {
x-on:focus={ props.OnFocus }
}
if props.OnInvalid != "" {
x-on:wa-invalid={ props.OnInvalid }
}
{ props.Attrs... }
>
if props.Slots.Hint != nil {
<div slot="hint">
@props.Slots.Hint
</div>
}
{ children... }
</wa-switch>
}
// SwitchFunc renders with a builder function for inline configuration
templ SwitchFunc(fn func(*SwitchBuilder)) {
{{ b := NewSwitch(); fn(b) }}
@Switch(b.Props()) {
{ children... }
}
}