386 lines
11 KiB
Plaintext
386 lines
11 KiB
Plaintext
// Code generated by wa-generator. DO NOT EDIT.
|
|
// Source: Web Awesome wa-button
|
|
|
|
package wa
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// Buttons represent actions that are available to the user.
|
|
//
|
|
// Web Awesome component: <wa-button>
|
|
|
|
// ButtonProps holds all properties for the wa-button component
|
|
type ButtonProps struct {
|
|
// The button's theme variant. Defaults to neutral if not within another element with a variant.
|
|
// Valid values: "neutral", "brand", "success", "warning", "danger"
|
|
Variant string `attr:"variant"`
|
|
// The button's visual appearance.
|
|
// Valid values: "accent", "filled", "outlined", "filled-outlined", "plain"
|
|
Appearance string `attr:"appearance"`
|
|
// The button's size.
|
|
// Valid values: "small", "medium", "large"
|
|
Size string `attr:"size"`
|
|
// Draws the button with a caret. Used to indicate that the button triggers a dropdown menu or similar behavior.
|
|
WithCaret bool `attr:"with-caret"`
|
|
// Disables the button. Does not apply to link buttons.
|
|
Disabled bool `attr:"disabled"`
|
|
// Draws the button in a loading state.
|
|
Loading bool `attr:"loading"`
|
|
// Draws a pill-style button with rounded edges.
|
|
Pill bool `attr:"pill"`
|
|
// The type of button. Note that the default value is button instead of submit, which is opposite of how native
|
|
// Valid values: "button", "submit", "reset"
|
|
Type string `attr:"type"`
|
|
// The name of the button, submitted as a name/value pair with form data, but only when this button is the submitter.
|
|
Name string `attr:"name"`
|
|
// The value of the button, submitted as a pair with the button's name as part of the form data, but only when this
|
|
Value string `attr:"value"`
|
|
// When set, the underlying button will be rendered as an <a> with this href instead of a <button>.
|
|
Href string `attr:"href"`
|
|
// Tells the browser where to open the link. Only used when href is present.
|
|
// Valid values: "_blank", "_parent", "_self", "_top"
|
|
Target string `attr:"target"`
|
|
// When using href, this attribute will map to the underlying link's rel attribute.
|
|
Rel string `attr:"rel"`
|
|
// Tells the browser to download the linked file as this filename. Only used when href is present.
|
|
Download string `attr:"download"`
|
|
// Used to override the form owner's action attribute.
|
|
Formaction string `attr:"formaction"`
|
|
// Used to override the form owner's enctype attribute.
|
|
// Valid values: "application/x-www-form-urlencoded", "multipart/form-data", "text/plain"
|
|
Formenctype string `attr:"formenctype"`
|
|
// Used to override the form owner's method attribute.
|
|
// Valid values: "post", "get"
|
|
Formmethod string `attr:"formmethod"`
|
|
// Used to override the form owner's novalidate attribute.
|
|
Formnovalidate bool `attr:"formnovalidate"`
|
|
// Used to override the form owner's target attribute.
|
|
// Valid values: "_self", "_blank", "_parent", "_top"
|
|
Formtarget string `attr:"formtarget"`
|
|
|
|
// Events
|
|
// Emitted when the button loses focus.
|
|
OnBlur string `attr:"x-on:blur"`
|
|
// Emitted when the button gains focus.
|
|
OnFocus string `attr:"x-on:focus"`
|
|
// 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 ButtonSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// ButtonSlots holds named slot content for the component
|
|
type ButtonSlots struct {
|
|
// An element, such as <wa-icon>, placed before the label.
|
|
Start templ.Component
|
|
// An element, such as <wa-icon>, placed after the label.
|
|
End templ.Component
|
|
}
|
|
|
|
// ButtonBuilder provides a fluent API for constructing ButtonProps
|
|
type ButtonBuilder struct {
|
|
props ButtonProps
|
|
}
|
|
|
|
// NewButton creates a new builder for wa-button
|
|
func NewButton() *ButtonBuilder {
|
|
return &ButtonBuilder{}
|
|
}
|
|
|
|
// Variant sets the variant attribute
|
|
// The button's theme variant. Defaults to neutral if not within another element with a variant.
|
|
func (b *ButtonBuilder) Variant(v string) *ButtonBuilder {
|
|
b.props.Variant = v
|
|
return b
|
|
}
|
|
|
|
// Appearance sets the appearance attribute
|
|
// The button's visual appearance.
|
|
func (b *ButtonBuilder) Appearance(v string) *ButtonBuilder {
|
|
b.props.Appearance = v
|
|
return b
|
|
}
|
|
|
|
// Size sets the size attribute
|
|
// The button's size.
|
|
func (b *ButtonBuilder) Size(v string) *ButtonBuilder {
|
|
b.props.Size = v
|
|
return b
|
|
}
|
|
|
|
// WithCaret sets the with-caret attribute
|
|
// Draws the button with a caret. Used to indicate that the button triggers a dropdown menu or similar behavior.
|
|
func (b *ButtonBuilder) WithCaret(v bool) *ButtonBuilder {
|
|
b.props.WithCaret = v
|
|
return b
|
|
}
|
|
|
|
// Disabled sets the disabled attribute
|
|
// Disables the button. Does not apply to link buttons.
|
|
func (b *ButtonBuilder) Disabled(v bool) *ButtonBuilder {
|
|
b.props.Disabled = v
|
|
return b
|
|
}
|
|
|
|
// Loading sets the loading attribute
|
|
// Draws the button in a loading state.
|
|
func (b *ButtonBuilder) Loading(v bool) *ButtonBuilder {
|
|
b.props.Loading = v
|
|
return b
|
|
}
|
|
|
|
// Pill sets the pill attribute
|
|
// Draws a pill-style button with rounded edges.
|
|
func (b *ButtonBuilder) Pill(v bool) *ButtonBuilder {
|
|
b.props.Pill = v
|
|
return b
|
|
}
|
|
|
|
// Type sets the type attribute
|
|
// The type of button. Note that the default value is button instead of submit, which is opposite of how native
|
|
func (b *ButtonBuilder) Type(v string) *ButtonBuilder {
|
|
b.props.Type = v
|
|
return b
|
|
}
|
|
|
|
// Name sets the name attribute
|
|
// The name of the button, submitted as a name/value pair with form data, but only when this button is the submitter.
|
|
func (b *ButtonBuilder) Name(v string) *ButtonBuilder {
|
|
b.props.Name = v
|
|
return b
|
|
}
|
|
|
|
// Value sets the value attribute
|
|
// The value of the button, submitted as a pair with the button's name as part of the form data, but only when this
|
|
func (b *ButtonBuilder) Value(v string) *ButtonBuilder {
|
|
b.props.Value = v
|
|
return b
|
|
}
|
|
|
|
// Href sets the href attribute
|
|
// When set, the underlying button will be rendered as an <a> with this href instead of a <button>.
|
|
func (b *ButtonBuilder) Href(v string) *ButtonBuilder {
|
|
b.props.Href = v
|
|
return b
|
|
}
|
|
|
|
// Target sets the target attribute
|
|
// Tells the browser where to open the link. Only used when href is present.
|
|
func (b *ButtonBuilder) Target(v string) *ButtonBuilder {
|
|
b.props.Target = v
|
|
return b
|
|
}
|
|
|
|
// Rel sets the rel attribute
|
|
// When using href, this attribute will map to the underlying link's rel attribute.
|
|
func (b *ButtonBuilder) Rel(v string) *ButtonBuilder {
|
|
b.props.Rel = v
|
|
return b
|
|
}
|
|
|
|
// Download sets the download attribute
|
|
// Tells the browser to download the linked file as this filename. Only used when href is present.
|
|
func (b *ButtonBuilder) Download(v string) *ButtonBuilder {
|
|
b.props.Download = v
|
|
return b
|
|
}
|
|
|
|
// Formaction sets the formaction attribute
|
|
// Used to override the form owner's action attribute.
|
|
func (b *ButtonBuilder) Formaction(v string) *ButtonBuilder {
|
|
b.props.Formaction = v
|
|
return b
|
|
}
|
|
|
|
// Formenctype sets the formenctype attribute
|
|
// Used to override the form owner's enctype attribute.
|
|
func (b *ButtonBuilder) Formenctype(v string) *ButtonBuilder {
|
|
b.props.Formenctype = v
|
|
return b
|
|
}
|
|
|
|
// Formmethod sets the formmethod attribute
|
|
// Used to override the form owner's method attribute.
|
|
func (b *ButtonBuilder) Formmethod(v string) *ButtonBuilder {
|
|
b.props.Formmethod = v
|
|
return b
|
|
}
|
|
|
|
// Formnovalidate sets the formnovalidate attribute
|
|
// Used to override the form owner's novalidate attribute.
|
|
func (b *ButtonBuilder) Formnovalidate(v bool) *ButtonBuilder {
|
|
b.props.Formnovalidate = v
|
|
return b
|
|
}
|
|
|
|
// Formtarget sets the formtarget attribute
|
|
// Used to override the form owner's target attribute.
|
|
func (b *ButtonBuilder) Formtarget(v string) *ButtonBuilder {
|
|
b.props.Formtarget = v
|
|
return b
|
|
}
|
|
|
|
// OnBlur sets the handler for blur event
|
|
// Emitted when the button loses focus.
|
|
func (b *ButtonBuilder) OnBlur(handler string) *ButtonBuilder {
|
|
b.props.OnBlur = handler
|
|
return b
|
|
}
|
|
|
|
// OnFocus sets the handler for focus event
|
|
// Emitted when the button gains focus.
|
|
func (b *ButtonBuilder) OnFocus(handler string) *ButtonBuilder {
|
|
b.props.OnFocus = 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 *ButtonBuilder) OnInvalid(handler string) *ButtonBuilder {
|
|
b.props.OnInvalid = handler
|
|
return b
|
|
}
|
|
|
|
// StartSlot sets the start slot content
|
|
// An element, such as <wa-icon>, placed before the label.
|
|
func (b *ButtonBuilder) StartSlot(c templ.Component) *ButtonBuilder {
|
|
b.props.Slots.Start = c
|
|
return b
|
|
}
|
|
|
|
// EndSlot sets the end slot content
|
|
// An element, such as <wa-icon>, placed after the label.
|
|
func (b *ButtonBuilder) EndSlot(c templ.Component) *ButtonBuilder {
|
|
b.props.Slots.End = c
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *ButtonBuilder) Attr(name, value string) *ButtonBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *ButtonBuilder) Attrs(attrs templ.Attributes) *ButtonBuilder {
|
|
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 *ButtonBuilder) Props() ButtonProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *ButtonBuilder) Build() ButtonProps {
|
|
return b.props
|
|
}
|
|
|
|
// Button renders the wa-button component
|
|
templ Button(props ButtonProps) {
|
|
<wa-button
|
|
if props.Variant != "" {
|
|
variant={ props.Variant }
|
|
}
|
|
if props.Appearance != "" {
|
|
appearance={ props.Appearance }
|
|
}
|
|
if props.Size != "" {
|
|
size={ props.Size }
|
|
}
|
|
if props.WithCaret {
|
|
with-caret
|
|
}
|
|
if props.Disabled {
|
|
disabled
|
|
}
|
|
if props.Loading {
|
|
loading
|
|
}
|
|
if props.Pill {
|
|
pill
|
|
}
|
|
if props.Type != "" {
|
|
type={ props.Type }
|
|
}
|
|
if props.Name != "" {
|
|
name={ props.Name }
|
|
}
|
|
if props.Value != "" {
|
|
value={ props.Value }
|
|
}
|
|
if props.Href != "" {
|
|
href={ props.Href }
|
|
}
|
|
if props.Target != "" {
|
|
target={ props.Target }
|
|
}
|
|
if props.Rel != "" {
|
|
rel={ props.Rel }
|
|
}
|
|
if props.Download != "" {
|
|
download={ props.Download }
|
|
}
|
|
if props.Formaction != "" {
|
|
formaction={ props.Formaction }
|
|
}
|
|
if props.Formenctype != "" {
|
|
formenctype={ props.Formenctype }
|
|
}
|
|
if props.Formmethod != "" {
|
|
formmethod={ props.Formmethod }
|
|
}
|
|
if props.Formnovalidate {
|
|
formnovalidate
|
|
}
|
|
if props.Formtarget != "" {
|
|
formtarget={ props.Formtarget }
|
|
}
|
|
if props.OnBlur != "" {
|
|
x-on:blur={ props.OnBlur }
|
|
}
|
|
if props.OnFocus != "" {
|
|
x-on:focus={ props.OnFocus }
|
|
}
|
|
if props.OnInvalid != "" {
|
|
x-on:wa-invalid={ props.OnInvalid }
|
|
}
|
|
{ props.Attrs... }
|
|
>
|
|
if props.Slots.Start != nil {
|
|
<div slot="start">
|
|
@props.Slots.Start
|
|
</div>
|
|
}
|
|
if props.Slots.End != nil {
|
|
<div slot="end">
|
|
@props.Slots.End
|
|
</div>
|
|
}
|
|
{ children... }
|
|
</wa-button>
|
|
}
|
|
|
|
// ButtonFunc renders with a builder function for inline configuration
|
|
templ ButtonFunc(fn func(*ButtonBuilder)) {
|
|
{{ b := NewButton(); fn(b) }}
|
|
@Button(b.Props()) {
|
|
{ children... }
|
|
}
|
|
}
|