257 lines
6.8 KiB
Plaintext
257 lines
6.8 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-checkbox
|
|
|
|
package wa
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Checkboxes allow the user to toggle an option on or off.
|
|
//
|
|
// Web Awesome component: <wa-checkbox>
|
|
|
|
// CheckboxProps holds all properties for the wa-checkbox component
|
|
type CheckboxProps struct {
|
|
// The name of the checkbox, submitted as a name/value pair with form data.
|
|
Name string `attr:"name"`
|
|
// The value of the checkbox, submitted as a name/value pair with form data.
|
|
Value string `attr:"value"`
|
|
// The checkbox's size.
|
|
// Valid values: "small", "medium", "large"
|
|
Size string `attr:"size"`
|
|
// Disables the checkbox.
|
|
Disabled bool `attr:"disabled"`
|
|
// Draws the checkbox in an indeterminate state. This is usually applied to checkboxes that represents a "select
|
|
Indeterminate bool `attr:"indeterminate"`
|
|
// The default value of the form control. Primarily used for resetting the form control.
|
|
Checked bool `attr:"checked"`
|
|
// Makes the checkbox a required field.
|
|
Required bool `attr:"required"`
|
|
// The checkbox's hint. If you need to display HTML, use the hint slot instead.
|
|
Hint string `attr:"hint"`
|
|
|
|
// Events
|
|
// Emitted when the checked state changes.
|
|
OnChange string `attr:"x-on:change"`
|
|
// Emitted when the checkbox loses focus.
|
|
OnBlur string `attr:"x-on:blur"`
|
|
// Emitted when the checkbox gains focus.
|
|
OnFocus string `attr:"x-on:focus"`
|
|
// Emitted when the checkbox receives input.
|
|
OnInput string `attr:"x-on:input"`
|
|
// 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 CheckboxSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// CheckboxSlots holds named slot content for the component
|
|
type CheckboxSlots struct {
|
|
// Text that describes how to use the checkbox. Alternatively, you can use the hint attribute.
|
|
Hint templ.Component
|
|
}
|
|
|
|
// CheckboxBuilder provides a fluent API for constructing CheckboxProps
|
|
type CheckboxBuilder struct {
|
|
props CheckboxProps
|
|
}
|
|
|
|
// NewCheckbox creates a new builder for wa-checkbox
|
|
func NewCheckbox() *CheckboxBuilder {
|
|
return &CheckboxBuilder{}
|
|
}
|
|
|
|
// Name sets the name attribute
|
|
// The name of the checkbox, submitted as a name/value pair with form data.
|
|
func (b *CheckboxBuilder) Name(v string) *CheckboxBuilder {
|
|
b.props.Name = v
|
|
return b
|
|
}
|
|
|
|
// Value sets the value attribute
|
|
// The value of the checkbox, submitted as a name/value pair with form data.
|
|
func (b *CheckboxBuilder) Value(v string) *CheckboxBuilder {
|
|
b.props.Value = v
|
|
return b
|
|
}
|
|
|
|
// Size sets the size attribute
|
|
// The checkbox's size.
|
|
func (b *CheckboxBuilder) Size(v string) *CheckboxBuilder {
|
|
b.props.Size = v
|
|
return b
|
|
}
|
|
|
|
// Disabled sets the disabled attribute
|
|
// Disables the checkbox.
|
|
func (b *CheckboxBuilder) Disabled(v bool) *CheckboxBuilder {
|
|
b.props.Disabled = v
|
|
return b
|
|
}
|
|
|
|
// Indeterminate sets the indeterminate attribute
|
|
// Draws the checkbox in an indeterminate state. This is usually applied to checkboxes that represents a "select
|
|
func (b *CheckboxBuilder) Indeterminate(v bool) *CheckboxBuilder {
|
|
b.props.Indeterminate = v
|
|
return b
|
|
}
|
|
|
|
// Checked sets the checked attribute
|
|
// The default value of the form control. Primarily used for resetting the form control.
|
|
func (b *CheckboxBuilder) Checked(v bool) *CheckboxBuilder {
|
|
b.props.Checked = v
|
|
return b
|
|
}
|
|
|
|
// Required sets the required attribute
|
|
// Makes the checkbox a required field.
|
|
func (b *CheckboxBuilder) Required(v bool) *CheckboxBuilder {
|
|
b.props.Required = v
|
|
return b
|
|
}
|
|
|
|
// Hint sets the hint attribute
|
|
// The checkbox's hint. If you need to display HTML, use the hint slot instead.
|
|
func (b *CheckboxBuilder) Hint(v string) *CheckboxBuilder {
|
|
b.props.Hint = v
|
|
return b
|
|
}
|
|
|
|
// OnChange sets the handler for change event
|
|
// Emitted when the checked state changes.
|
|
func (b *CheckboxBuilder) OnChange(handler string) *CheckboxBuilder {
|
|
b.props.OnChange = handler
|
|
return b
|
|
}
|
|
|
|
// OnBlur sets the handler for blur event
|
|
// Emitted when the checkbox loses focus.
|
|
func (b *CheckboxBuilder) OnBlur(handler string) *CheckboxBuilder {
|
|
b.props.OnBlur = handler
|
|
return b
|
|
}
|
|
|
|
// OnFocus sets the handler for focus event
|
|
// Emitted when the checkbox gains focus.
|
|
func (b *CheckboxBuilder) OnFocus(handler string) *CheckboxBuilder {
|
|
b.props.OnFocus = handler
|
|
return b
|
|
}
|
|
|
|
// OnInput sets the handler for input event
|
|
// Emitted when the checkbox receives input.
|
|
func (b *CheckboxBuilder) OnInput(handler string) *CheckboxBuilder {
|
|
b.props.OnInput = 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 *CheckboxBuilder) OnInvalid(handler string) *CheckboxBuilder {
|
|
b.props.OnInvalid = handler
|
|
return b
|
|
}
|
|
|
|
// HintSlot sets the hint slot content
|
|
// Text that describes how to use the checkbox. Alternatively, you can use the hint attribute.
|
|
func (b *CheckboxBuilder) HintSlot(c templ.Component) *CheckboxBuilder {
|
|
b.props.Slots.Hint = c
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *CheckboxBuilder) Attr(name, value string) *CheckboxBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *CheckboxBuilder) Attrs(attrs templ.Attributes) *CheckboxBuilder {
|
|
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 *CheckboxBuilder) Props() CheckboxProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *CheckboxBuilder) Build() CheckboxProps {
|
|
return b.props
|
|
}
|
|
|
|
// Checkbox renders the wa-checkbox component
|
|
templ Checkbox(props CheckboxProps) {
|
|
<wa-checkbox
|
|
if props.Name != "" {
|
|
name={ props.Name }
|
|
}
|
|
if props.Value != "" {
|
|
value={ props.Value }
|
|
}
|
|
if props.Size != "" {
|
|
size={ props.Size }
|
|
}
|
|
if props.Disabled {
|
|
disabled
|
|
}
|
|
if props.Indeterminate {
|
|
indeterminate
|
|
}
|
|
if props.Checked {
|
|
checked
|
|
}
|
|
if props.Required {
|
|
required
|
|
}
|
|
if props.Hint != "" {
|
|
hint={ props.Hint }
|
|
}
|
|
if props.OnChange != "" {
|
|
x-on:change={ props.OnChange }
|
|
}
|
|
if props.OnBlur != "" {
|
|
x-on:blur={ props.OnBlur }
|
|
}
|
|
if props.OnFocus != "" {
|
|
x-on:focus={ props.OnFocus }
|
|
}
|
|
if props.OnInput != "" {
|
|
x-on:input={ props.OnInput }
|
|
}
|
|
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-checkbox>
|
|
}
|
|
|
|
// CheckboxFunc renders with a builder function for inline configuration
|
|
templ CheckboxFunc(fn func(*CheckboxBuilder)) {
|
|
{{ b := NewCheckbox(); fn(b) }}
|
|
@Checkbox(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|