Files
nebula/pkg/wa/slider.templ

443 lines
12 KiB
Plaintext
Raw Permalink Normal View History

2026-01-01 14:41:31 -05:00
// Code generated by wa-generator. DO NOT EDIT.
// Source: Web Awesome wa-slider
package wa
import (
"github.com/a-h/templ"
)
// Ranges allow the user to select a single value within a given range using a slider.
//
// Web Awesome component: <wa-slider>
// SliderProps holds all properties for the wa-slider component
type SliderProps struct {
// The slider's label. If you need to provide HTML in the label, use the label slot instead.
Label string `attr:"label"`
// The slider hint. If you need to display HTML, use the hint slot instead.
Hint string `attr:"hint"`
// The name of the slider. This will be submitted with the form as a name/value pair.
Name string `attr:"name"`
// The minimum value of a range selection. Used only when range attribute is set.
MinValue float64 `attr:"min-value"`
// The maximum value of a range selection. Used only when range attribute is set.
MaxValue float64 `attr:"max-value"`
// The default value of the form control. Primarily used for resetting the form control.
Value float64 `attr:"value"`
// Converts the slider to a range slider with two thumbs.
Range bool `attr:"range"`
// Disables the slider.
Disabled bool `attr:"disabled"`
// Makes the slider a read-only field.
Readonly bool `attr:"readonly"`
// The orientation of the slider.
// Valid values: "horizontal", "vertical"
Orientation string `attr:"orientation"`
// The slider's size.
// Valid values: "small", "medium", "large"
Size string `attr:"size"`
// The starting value from which to draw the slider's fill, which is based on its current value.
IndicatorOffset float64 `attr:"indicator-offset"`
// The minimum value allowed.
Min float64 `attr:"min"`
// The maximum value allowed.
Max float64 `attr:"max"`
// The granularity the value must adhere to when incrementing and decrementing.
Step float64 `attr:"step"`
// Makes the slider a required field.
Required bool `attr:"required"`
// Tells the browser to focus the slider when the page loads or a dialog is shown.
Autofocus bool `attr:"autofocus"`
// The distance of the tooltip from the slider's thumb.
TooltipDistance float64 `attr:"tooltip-distance"`
// The placement of the tooltip in reference to the slider's thumb.
// Valid values: "top", "right", "bottom", "left"
TooltipPlacement string `attr:"tooltip-placement"`
// Draws markers at each step along the slider.
WithMarkers bool `attr:"with-markers"`
// Draws a tooltip above the thumb when the control has focus or is dragged.
WithTooltip bool `attr:"with-tooltip"`
// Events
// Emitted when an alteration to the control's value is committed by the user.
OnChange string `attr:"x-on:change"`
// 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 control 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 SliderSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// SliderSlots holds named slot content for the component
type SliderSlots struct {
// The slider label. Alternatively, you can use the label attribute.
Label templ.Component
// Text that describes how to use the input. Alternatively, you can use the hint attribute. instead.
Hint templ.Component
// One or more reference labels to show visually below the slider.
Reference templ.Component
}
// SliderBuilder provides a fluent API for constructing SliderProps
type SliderBuilder struct {
props SliderProps
}
// NewSlider creates a new builder for wa-slider
func NewSlider() *SliderBuilder {
return &SliderBuilder{}
}
// Label sets the label attribute
// The slider's label. If you need to provide HTML in the label, use the label slot instead.
func (b *SliderBuilder) Label(v string) *SliderBuilder {
b.props.Label = v
return b
}
// Hint sets the hint attribute
// The slider hint. If you need to display HTML, use the hint slot instead.
func (b *SliderBuilder) Hint(v string) *SliderBuilder {
b.props.Hint = v
return b
}
// Name sets the name attribute
// The name of the slider. This will be submitted with the form as a name/value pair.
func (b *SliderBuilder) Name(v string) *SliderBuilder {
b.props.Name = v
return b
}
// MinValue sets the min-value attribute
// The minimum value of a range selection. Used only when range attribute is set.
func (b *SliderBuilder) MinValue(v float64) *SliderBuilder {
b.props.MinValue = v
return b
}
// MaxValue sets the max-value attribute
// The maximum value of a range selection. Used only when range attribute is set.
func (b *SliderBuilder) MaxValue(v float64) *SliderBuilder {
b.props.MaxValue = v
return b
}
// Value sets the value attribute
// The default value of the form control. Primarily used for resetting the form control.
func (b *SliderBuilder) Value(v float64) *SliderBuilder {
b.props.Value = v
return b
}
// Range sets the range attribute
// Converts the slider to a range slider with two thumbs.
func (b *SliderBuilder) Range(v bool) *SliderBuilder {
b.props.Range = v
return b
}
// Disabled sets the disabled attribute
// Disables the slider.
func (b *SliderBuilder) Disabled(v bool) *SliderBuilder {
b.props.Disabled = v
return b
}
// Readonly sets the readonly attribute
// Makes the slider a read-only field.
func (b *SliderBuilder) Readonly(v bool) *SliderBuilder {
b.props.Readonly = v
return b
}
// Orientation sets the orientation attribute
// The orientation of the slider.
func (b *SliderBuilder) Orientation(v string) *SliderBuilder {
b.props.Orientation = v
return b
}
// Size sets the size attribute
// The slider's size.
func (b *SliderBuilder) Size(v string) *SliderBuilder {
b.props.Size = v
return b
}
// IndicatorOffset sets the indicator-offset attribute
// The starting value from which to draw the slider's fill, which is based on its current value.
func (b *SliderBuilder) IndicatorOffset(v float64) *SliderBuilder {
b.props.IndicatorOffset = v
return b
}
// Min sets the min attribute
// The minimum value allowed.
func (b *SliderBuilder) Min(v float64) *SliderBuilder {
b.props.Min = v
return b
}
// Max sets the max attribute
// The maximum value allowed.
func (b *SliderBuilder) Max(v float64) *SliderBuilder {
b.props.Max = v
return b
}
// Step sets the step attribute
// The granularity the value must adhere to when incrementing and decrementing.
func (b *SliderBuilder) Step(v float64) *SliderBuilder {
b.props.Step = v
return b
}
// Required sets the required attribute
// Makes the slider a required field.
func (b *SliderBuilder) Required(v bool) *SliderBuilder {
b.props.Required = v
return b
}
// Autofocus sets the autofocus attribute
// Tells the browser to focus the slider when the page loads or a dialog is shown.
func (b *SliderBuilder) Autofocus(v bool) *SliderBuilder {
b.props.Autofocus = v
return b
}
// TooltipDistance sets the tooltip-distance attribute
// The distance of the tooltip from the slider's thumb.
func (b *SliderBuilder) TooltipDistance(v float64) *SliderBuilder {
b.props.TooltipDistance = v
return b
}
// TooltipPlacement sets the tooltip-placement attribute
// The placement of the tooltip in reference to the slider's thumb.
func (b *SliderBuilder) TooltipPlacement(v string) *SliderBuilder {
b.props.TooltipPlacement = v
return b
}
// WithMarkers sets the with-markers attribute
// Draws markers at each step along the slider.
func (b *SliderBuilder) WithMarkers(v bool) *SliderBuilder {
b.props.WithMarkers = v
return b
}
// WithTooltip sets the with-tooltip attribute
// Draws a tooltip above the thumb when the control has focus or is dragged.
func (b *SliderBuilder) WithTooltip(v bool) *SliderBuilder {
b.props.WithTooltip = v
return b
}
// OnChange sets the handler for change event
// Emitted when an alteration to the control's value is committed by the user.
func (b *SliderBuilder) OnChange(handler string) *SliderBuilder {
b.props.OnChange = handler
return b
}
// OnBlur sets the handler for blur event
// Emitted when the control loses focus.
func (b *SliderBuilder) OnBlur(handler string) *SliderBuilder {
b.props.OnBlur = handler
return b
}
// OnFocus sets the handler for focus event
// Emitted when the control gains focus.
func (b *SliderBuilder) OnFocus(handler string) *SliderBuilder {
b.props.OnFocus = handler
return b
}
// OnInput sets the handler for input event
// Emitted when the control receives input.
func (b *SliderBuilder) OnInput(handler string) *SliderBuilder {
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 *SliderBuilder) OnInvalid(handler string) *SliderBuilder {
b.props.OnInvalid = handler
return b
}
// LabelSlot sets the label slot content
// The slider label. Alternatively, you can use the label attribute.
func (b *SliderBuilder) LabelSlot(c templ.Component) *SliderBuilder {
b.props.Slots.Label = c
return b
}
// HintSlot sets the hint slot content
// Text that describes how to use the input. Alternatively, you can use the hint attribute. instead.
func (b *SliderBuilder) HintSlot(c templ.Component) *SliderBuilder {
b.props.Slots.Hint = c
return b
}
// ReferenceSlot sets the reference slot content
// One or more reference labels to show visually below the slider.
func (b *SliderBuilder) ReferenceSlot(c templ.Component) *SliderBuilder {
b.props.Slots.Reference = c
return b
}
// Attr adds a custom HTML attribute
func (b *SliderBuilder) Attr(name, value string) *SliderBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *SliderBuilder) Attrs(attrs templ.Attributes) *SliderBuilder {
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 *SliderBuilder) Props() SliderProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *SliderBuilder) Build() SliderProps {
return b.props
}
// Slider renders the wa-slider component
templ Slider(props SliderProps) {
<wa-slider
if props.Label != "" {
label={ props.Label }
}
if props.Hint != "" {
hint={ props.Hint }
}
if props.Name != "" {
name={ props.Name }
}
if props.MinValue != 0 {
min-value={ templ.Sprintf("%v", props.MinValue) }
}
if props.MaxValue != 0 {
max-value={ templ.Sprintf("%v", props.MaxValue) }
}
if props.Value != 0 {
value={ templ.Sprintf("%v", props.Value) }
}
if props.Range {
range
}
if props.Disabled {
disabled
}
if props.Readonly {
readonly
}
if props.Orientation != "" {
orientation={ props.Orientation }
}
if props.Size != "" {
size={ props.Size }
}
if props.IndicatorOffset != 0 {
indicator-offset={ templ.Sprintf("%v", props.IndicatorOffset) }
}
if props.Min != 0 {
min={ templ.Sprintf("%v", props.Min) }
}
if props.Max != 0 {
max={ templ.Sprintf("%v", props.Max) }
}
if props.Step != 0 {
step={ templ.Sprintf("%v", props.Step) }
}
if props.Required {
required
}
if props.Autofocus {
autofocus
}
if props.TooltipDistance != 0 {
tooltip-distance={ templ.Sprintf("%v", props.TooltipDistance) }
}
if props.TooltipPlacement != "" {
tooltip-placement={ props.TooltipPlacement }
}
if props.WithMarkers {
with-markers
}
if props.WithTooltip {
with-tooltip
}
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.Label != nil {
<div slot="label">
@props.Slots.Label
</div>
}
if props.Slots.Hint != nil {
<div slot="hint">
@props.Slots.Hint
</div>
}
if props.Slots.Reference != nil {
<div slot="reference">
@props.Slots.Reference
</div>
}
{ children... }
</wa-slider>
}
// SliderFunc renders with a builder function for inline configuration
templ SliderFunc(fn func(*SliderBuilder)) {
{{ b := NewSlider(); fn(b) }}
@Slider(b.Props()) {
{ children... }
}
}