203 lines
5.1 KiB
Plaintext
203 lines
5.1 KiB
Plaintext
|
|
// Code generated by wa-generator. DO NOT EDIT.
|
||
|
|
// Source: Web Awesome wa-rating
|
||
|
|
|
||
|
|
package wa
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/a-h/templ"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Ratings give users a way to quickly view and provide feedback.
|
||
|
|
//
|
||
|
|
// Web Awesome component: <wa-rating>
|
||
|
|
|
||
|
|
// RatingProps holds all properties for the wa-rating component
|
||
|
|
type RatingProps struct {
|
||
|
|
// A label that describes the rating to assistive devices.
|
||
|
|
Label string `attr:"label"`
|
||
|
|
// The current rating.
|
||
|
|
Value float64 `attr:"value"`
|
||
|
|
// The highest rating to show.
|
||
|
|
Max float64 `attr:"max"`
|
||
|
|
// The precision at which the rating will increase and decrease. For example, to allow half-star ratings, set this
|
||
|
|
Precision float64 `attr:"precision"`
|
||
|
|
// Makes the rating readonly.
|
||
|
|
Readonly bool `attr:"readonly"`
|
||
|
|
// Disables the rating.
|
||
|
|
Disabled bool `attr:"disabled"`
|
||
|
|
// A function that customizes the symbol to be rendered. The first and only argument is the rating's current value.
|
||
|
|
GetSymbol string `attr:"getSymbol"`
|
||
|
|
// The component's size.
|
||
|
|
// Valid values: "small", "medium", "large"
|
||
|
|
Size string `attr:"size"`
|
||
|
|
|
||
|
|
// Events
|
||
|
|
// Emitted when the rating's value changes.
|
||
|
|
OnChange string `attr:"x-on:change"`
|
||
|
|
// Emitted when the user hovers over a value. The phase property indicates when hovering starts, moves to a new value, o...
|
||
|
|
OnHover string `attr:"x-on:wa-hover"`
|
||
|
|
|
||
|
|
// Slots contains named slot content
|
||
|
|
Slots RatingSlots
|
||
|
|
|
||
|
|
// Attrs contains additional HTML attributes
|
||
|
|
Attrs templ.Attributes
|
||
|
|
}
|
||
|
|
|
||
|
|
// RatingBuilder provides a fluent API for constructing RatingProps
|
||
|
|
type RatingBuilder struct {
|
||
|
|
props RatingProps
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewRating creates a new builder for wa-rating
|
||
|
|
func NewRating() *RatingBuilder {
|
||
|
|
return &RatingBuilder{}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Label sets the label attribute
|
||
|
|
// A label that describes the rating to assistive devices.
|
||
|
|
func (b *RatingBuilder) Label(v string) *RatingBuilder {
|
||
|
|
b.props.Label = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Value sets the value attribute
|
||
|
|
// The current rating.
|
||
|
|
func (b *RatingBuilder) Value(v float64) *RatingBuilder {
|
||
|
|
b.props.Value = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Max sets the max attribute
|
||
|
|
// The highest rating to show.
|
||
|
|
func (b *RatingBuilder) Max(v float64) *RatingBuilder {
|
||
|
|
b.props.Max = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Precision sets the precision attribute
|
||
|
|
// The precision at which the rating will increase and decrease. For example, to allow half-star ratings, set this
|
||
|
|
func (b *RatingBuilder) Precision(v float64) *RatingBuilder {
|
||
|
|
b.props.Precision = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Readonly sets the readonly attribute
|
||
|
|
// Makes the rating readonly.
|
||
|
|
func (b *RatingBuilder) Readonly(v bool) *RatingBuilder {
|
||
|
|
b.props.Readonly = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Disabled sets the disabled attribute
|
||
|
|
// Disables the rating.
|
||
|
|
func (b *RatingBuilder) Disabled(v bool) *RatingBuilder {
|
||
|
|
b.props.Disabled = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// GetSymbol sets the getSymbol attribute
|
||
|
|
// A function that customizes the symbol to be rendered. The first and only argument is the rating's current value.
|
||
|
|
func (b *RatingBuilder) GetSymbol(v string) *RatingBuilder {
|
||
|
|
b.props.GetSymbol = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Size sets the size attribute
|
||
|
|
// The component's size.
|
||
|
|
func (b *RatingBuilder) Size(v string) *RatingBuilder {
|
||
|
|
b.props.Size = v
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnChange sets the handler for change event
|
||
|
|
// Emitted when the rating's value changes.
|
||
|
|
func (b *RatingBuilder) OnChange(handler string) *RatingBuilder {
|
||
|
|
b.props.OnChange = handler
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnHover sets the handler for wa-hover event
|
||
|
|
// Emitted when the user hovers over a value. The phase property indicates when hovering starts, moves to a new value, o...
|
||
|
|
func (b *RatingBuilder) OnHover(handler string) *RatingBuilder {
|
||
|
|
b.props.OnHover = handler
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Attr adds a custom HTML attribute
|
||
|
|
func (b *RatingBuilder) Attr(name, value string) *RatingBuilder {
|
||
|
|
if b.props.Attrs == nil {
|
||
|
|
b.props.Attrs = templ.Attributes{}
|
||
|
|
}
|
||
|
|
b.props.Attrs[name] = value
|
||
|
|
return b
|
||
|
|
}
|
||
|
|
|
||
|
|
// Attrs merges multiple attributes
|
||
|
|
func (b *RatingBuilder) Attrs(attrs templ.Attributes) *RatingBuilder {
|
||
|
|
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 *RatingBuilder) Props() RatingProps {
|
||
|
|
return b.props
|
||
|
|
}
|
||
|
|
|
||
|
|
// Build returns the props (alias for Props for semantic clarity)
|
||
|
|
func (b *RatingBuilder) Build() RatingProps {
|
||
|
|
return b.props
|
||
|
|
}
|
||
|
|
|
||
|
|
// Rating renders the wa-rating component
|
||
|
|
templ Rating(props RatingProps) {
|
||
|
|
<wa-rating
|
||
|
|
if props.Label != "" {
|
||
|
|
label={ props.Label }
|
||
|
|
}
|
||
|
|
if props.Value != 0 {
|
||
|
|
value={ templ.Sprintf("%v", props.Value) }
|
||
|
|
}
|
||
|
|
if props.Max != 0 {
|
||
|
|
max={ templ.Sprintf("%v", props.Max) }
|
||
|
|
}
|
||
|
|
if props.Precision != 0 {
|
||
|
|
precision={ templ.Sprintf("%v", props.Precision) }
|
||
|
|
}
|
||
|
|
if props.Readonly {
|
||
|
|
readonly
|
||
|
|
}
|
||
|
|
if props.Disabled {
|
||
|
|
disabled
|
||
|
|
}
|
||
|
|
if props.GetSymbol {
|
||
|
|
getSymbol
|
||
|
|
}
|
||
|
|
if props.Size != "" {
|
||
|
|
size={ props.Size }
|
||
|
|
}
|
||
|
|
if props.OnChange != "" {
|
||
|
|
x-on:change={ props.OnChange }
|
||
|
|
}
|
||
|
|
if props.OnHover != "" {
|
||
|
|
x-on:wa-hover={ props.OnHover }
|
||
|
|
}
|
||
|
|
{ props.Attrs... }
|
||
|
|
>
|
||
|
|
{ children... }
|
||
|
|
</wa-rating>
|
||
|
|
}
|
||
|
|
|
||
|
|
// RatingFunc renders with a builder function for inline configuration
|
||
|
|
templ RatingFunc(fn func(*RatingBuilder)) {
|
||
|
|
{{ b := NewRating(); fn(b) }}
|
||
|
|
@Rating(b.Props()) {
|
||
|
|
{ children... }
|
||
|
|
}
|
||
|
|
}
|