272 lines
7.9 KiB
Plaintext
272 lines
7.9 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-radio-group
|
|
|
|
package wa
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Radio groups are used to group multiple radios so they function as a single form control.
|
|
//
|
|
// Web Awesome component: <wa-radio-group>
|
|
|
|
// RadioGroupProps holds all properties for the wa-radio-group component
|
|
type RadioGroupProps struct {
|
|
// The radio group's label. Required for proper accessibility. If you need to display HTML, use the label slot
|
|
Label string `attr:"label"`
|
|
// The radio groups's hint. If you need to display HTML, use the hint slot instead.
|
|
Hint string `attr:"hint"`
|
|
// The name of the radio group, submitted as a name/value pair with form data.
|
|
Name string `attr:"name"`
|
|
// Disables the radio group and all child radios.
|
|
Disabled bool `attr:"disabled"`
|
|
// The orientation in which to show radio items.
|
|
// Valid values: "horizontal", "vertical"
|
|
Orientation string `attr:"orientation"`
|
|
// The default value of the form control. Primarily used for resetting the form control.
|
|
Value string `attr:"value"`
|
|
// The radio group's size. This size will be applied to all child radios and radio buttons, except when explicitly overr...
|
|
// Valid values: "small", "medium", "large"
|
|
Size string `attr:"size"`
|
|
// Ensures a child radio is checked before allowing the containing form to submit.
|
|
Required bool `attr:"required"`
|
|
// Used for SSR. if true, will show slotted label on initial render.
|
|
WithLabel bool `attr:"with-label"`
|
|
// Used for SSR. if true, will show slotted hint on initial render.
|
|
WithHint bool `attr:"with-hint"`
|
|
|
|
// Events
|
|
// Emitted when the radio group receives user input.
|
|
OnInput string `attr:"x-on:input"`
|
|
// Emitted when the radio group's selected value changes.
|
|
OnChange string `attr:"x-on:change"`
|
|
// 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 RadioGroupSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// RadioGroupSlots holds named slot content for the component
|
|
type RadioGroupSlots struct {
|
|
// The radio group's label. Required for proper accessibility. Alternatively, you can use the label attribute.
|
|
Label templ.Component
|
|
// Text that describes how to use the radio group. Alternatively, you can use the hint attribute.
|
|
Hint templ.Component
|
|
}
|
|
|
|
// RadioGroupBuilder provides a fluent API for constructing RadioGroupProps
|
|
type RadioGroupBuilder struct {
|
|
props RadioGroupProps
|
|
}
|
|
|
|
// NewRadioGroup creates a new builder for wa-radio-group
|
|
func NewRadioGroup() *RadioGroupBuilder {
|
|
return &RadioGroupBuilder{}
|
|
}
|
|
|
|
// Label sets the label attribute
|
|
// The radio group's label. Required for proper accessibility. If you need to display HTML, use the label slot
|
|
func (b *RadioGroupBuilder) Label(v string) *RadioGroupBuilder {
|
|
b.props.Label = v
|
|
return b
|
|
}
|
|
|
|
// Hint sets the hint attribute
|
|
// The radio groups's hint. If you need to display HTML, use the hint slot instead.
|
|
func (b *RadioGroupBuilder) Hint(v string) *RadioGroupBuilder {
|
|
b.props.Hint = v
|
|
return b
|
|
}
|
|
|
|
// Name sets the name attribute
|
|
// The name of the radio group, submitted as a name/value pair with form data.
|
|
func (b *RadioGroupBuilder) Name(v string) *RadioGroupBuilder {
|
|
b.props.Name = v
|
|
return b
|
|
}
|
|
|
|
// Disabled sets the disabled attribute
|
|
// Disables the radio group and all child radios.
|
|
func (b *RadioGroupBuilder) Disabled(v bool) *RadioGroupBuilder {
|
|
b.props.Disabled = v
|
|
return b
|
|
}
|
|
|
|
// Orientation sets the orientation attribute
|
|
// The orientation in which to show radio items.
|
|
func (b *RadioGroupBuilder) Orientation(v string) *RadioGroupBuilder {
|
|
b.props.Orientation = v
|
|
return b
|
|
}
|
|
|
|
// Value sets the value attribute
|
|
// The default value of the form control. Primarily used for resetting the form control.
|
|
func (b *RadioGroupBuilder) Value(v string) *RadioGroupBuilder {
|
|
b.props.Value = v
|
|
return b
|
|
}
|
|
|
|
// Size sets the size attribute
|
|
// The radio group's size. This size will be applied to all child radios and radio buttons, except when explicitly overr...
|
|
func (b *RadioGroupBuilder) Size(v string) *RadioGroupBuilder {
|
|
b.props.Size = v
|
|
return b
|
|
}
|
|
|
|
// Required sets the required attribute
|
|
// Ensures a child radio is checked before allowing the containing form to submit.
|
|
func (b *RadioGroupBuilder) Required(v bool) *RadioGroupBuilder {
|
|
b.props.Required = v
|
|
return b
|
|
}
|
|
|
|
// WithLabel sets the with-label attribute
|
|
// Used for SSR. if true, will show slotted label on initial render.
|
|
func (b *RadioGroupBuilder) WithLabel(v bool) *RadioGroupBuilder {
|
|
b.props.WithLabel = v
|
|
return b
|
|
}
|
|
|
|
// WithHint sets the with-hint attribute
|
|
// Used for SSR. if true, will show slotted hint on initial render.
|
|
func (b *RadioGroupBuilder) WithHint(v bool) *RadioGroupBuilder {
|
|
b.props.WithHint = v
|
|
return b
|
|
}
|
|
|
|
// OnInput sets the handler for input event
|
|
// Emitted when the radio group receives user input.
|
|
func (b *RadioGroupBuilder) OnInput(handler string) *RadioGroupBuilder {
|
|
b.props.OnInput = handler
|
|
return b
|
|
}
|
|
|
|
// OnChange sets the handler for change event
|
|
// Emitted when the radio group's selected value changes.
|
|
func (b *RadioGroupBuilder) OnChange(handler string) *RadioGroupBuilder {
|
|
b.props.OnChange = 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 *RadioGroupBuilder) OnInvalid(handler string) *RadioGroupBuilder {
|
|
b.props.OnInvalid = handler
|
|
return b
|
|
}
|
|
|
|
// LabelSlot sets the label slot content
|
|
// The radio group's label. Required for proper accessibility. Alternatively, you can use the label attribute.
|
|
func (b *RadioGroupBuilder) LabelSlot(c templ.Component) *RadioGroupBuilder {
|
|
b.props.Slots.Label = c
|
|
return b
|
|
}
|
|
|
|
// HintSlot sets the hint slot content
|
|
// Text that describes how to use the radio group. Alternatively, you can use the hint attribute.
|
|
func (b *RadioGroupBuilder) HintSlot(c templ.Component) *RadioGroupBuilder {
|
|
b.props.Slots.Hint = c
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *RadioGroupBuilder) Attr(name, value string) *RadioGroupBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *RadioGroupBuilder) Attrs(attrs templ.Attributes) *RadioGroupBuilder {
|
|
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 *RadioGroupBuilder) Props() RadioGroupProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *RadioGroupBuilder) Build() RadioGroupProps {
|
|
return b.props
|
|
}
|
|
|
|
// RadioGroup renders the wa-radio-group component
|
|
templ RadioGroup(props RadioGroupProps) {
|
|
<wa-radio-group
|
|
if props.Label != "" {
|
|
label={ props.Label }
|
|
}
|
|
if props.Hint != "" {
|
|
hint={ props.Hint }
|
|
}
|
|
if props.Name != "" {
|
|
name={ props.Name }
|
|
}
|
|
if props.Disabled {
|
|
disabled
|
|
}
|
|
if props.Orientation != "" {
|
|
orientation={ props.Orientation }
|
|
}
|
|
if props.Value != "" {
|
|
value={ props.Value }
|
|
}
|
|
if props.Size != "" {
|
|
size={ props.Size }
|
|
}
|
|
if props.Required {
|
|
required
|
|
}
|
|
if props.WithLabel {
|
|
with-label
|
|
}
|
|
if props.WithHint {
|
|
with-hint
|
|
}
|
|
if props.OnInput != "" {
|
|
x-on:input={ props.OnInput }
|
|
}
|
|
if props.OnChange != "" {
|
|
x-on:change={ props.OnChange }
|
|
}
|
|
if props.OnInvalid != "" {
|
|
x-on:wa-invalid={ props.OnInvalid }
|
|
}
|
|
{ props.Attrs... }
|
|
>
|
|
if props.Slots.Label != nil {
|
|
<div slot="label">
|
|
@props.Slots.Label
|
|
</div>
|
|
}
|
|
if props.Slots.Hint != nil {
|
|
<div slot="hint">
|
|
@props.Slots.Hint
|
|
</div>
|
|
}
|
|
{ children... }
|
|
</wa-radio-group>
|
|
}
|
|
|
|
// RadioGroupFunc renders with a builder function for inline configuration
|
|
templ RadioGroupFunc(fn func(*RadioGroupBuilder)) {
|
|
{{ b := NewRadioGroup(); fn(b) }}
|
|
@RadioGroup(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|