152 lines
3.7 KiB
Plaintext
152 lines
3.7 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-comparison
|
|
|
|
package wa
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Compare visual differences between similar content with a sliding panel.
|
|
//
|
|
// Web Awesome component: <wa-comparison>
|
|
|
|
// ComparisonProps holds all properties for the wa-comparison component
|
|
type ComparisonProps struct {
|
|
// The position of the divider as a percentage.
|
|
Position float64 `attr:"position"`
|
|
|
|
// Events
|
|
// Emitted when the position changes.
|
|
OnChange string `attr:"x-on:change"`
|
|
|
|
// Slots contains named slot content
|
|
Slots ComparisonSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// ComparisonSlots holds named slot content for the component
|
|
type ComparisonSlots struct {
|
|
// The before content, often an <img> or <svg> element.
|
|
Before templ.Component
|
|
// The after content, often an <img> or <svg> element.
|
|
After templ.Component
|
|
// The icon used inside the handle.
|
|
Handle templ.Component
|
|
}
|
|
|
|
// ComparisonBuilder provides a fluent API for constructing ComparisonProps
|
|
type ComparisonBuilder struct {
|
|
props ComparisonProps
|
|
}
|
|
|
|
// NewComparison creates a new builder for wa-comparison
|
|
func NewComparison() *ComparisonBuilder {
|
|
return &ComparisonBuilder{}
|
|
}
|
|
|
|
// Position sets the position attribute
|
|
// The position of the divider as a percentage.
|
|
func (b *ComparisonBuilder) Position(v float64) *ComparisonBuilder {
|
|
b.props.Position = v
|
|
return b
|
|
}
|
|
|
|
// OnChange sets the handler for change event
|
|
// Emitted when the position changes.
|
|
func (b *ComparisonBuilder) OnChange(handler string) *ComparisonBuilder {
|
|
b.props.OnChange = handler
|
|
return b
|
|
}
|
|
|
|
// BeforeSlot sets the before slot content
|
|
// The before content, often an <img> or <svg> element.
|
|
func (b *ComparisonBuilder) BeforeSlot(c templ.Component) *ComparisonBuilder {
|
|
b.props.Slots.Before = c
|
|
return b
|
|
}
|
|
|
|
// AfterSlot sets the after slot content
|
|
// The after content, often an <img> or <svg> element.
|
|
func (b *ComparisonBuilder) AfterSlot(c templ.Component) *ComparisonBuilder {
|
|
b.props.Slots.After = c
|
|
return b
|
|
}
|
|
|
|
// HandleSlot sets the handle slot content
|
|
// The icon used inside the handle.
|
|
func (b *ComparisonBuilder) HandleSlot(c templ.Component) *ComparisonBuilder {
|
|
b.props.Slots.Handle = c
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *ComparisonBuilder) Attr(name, value string) *ComparisonBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *ComparisonBuilder) Attrs(attrs templ.Attributes) *ComparisonBuilder {
|
|
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 *ComparisonBuilder) Props() ComparisonProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *ComparisonBuilder) Build() ComparisonProps {
|
|
return b.props
|
|
}
|
|
|
|
// Comparison renders the wa-comparison component
|
|
templ Comparison(props ComparisonProps) {
|
|
<wa-comparison
|
|
if props.Position != 0 {
|
|
position={ templ.Sprintf("%v", props.Position) }
|
|
}
|
|
if props.OnChange != "" {
|
|
x-on:change={ props.OnChange }
|
|
}
|
|
{ props.Attrs... }
|
|
>
|
|
if props.Slots.Before != nil {
|
|
<div slot="before">
|
|
@props.Slots.Before
|
|
</div>
|
|
}
|
|
if props.Slots.After != nil {
|
|
<div slot="after">
|
|
@props.Slots.After
|
|
</div>
|
|
}
|
|
if props.Slots.Handle != nil {
|
|
<div slot="handle">
|
|
@props.Slots.Handle
|
|
</div>
|
|
}
|
|
{ children... }
|
|
</wa-comparison>
|
|
}
|
|
|
|
// ComparisonFunc renders with a builder function for inline configuration
|
|
templ ComparisonFunc(fn func(*ComparisonBuilder)) {
|
|
{{ b := NewComparison(); fn(b) }}
|
|
@Comparison(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|