Files
nebula/pkg/wa/copy-button.templ

249 lines
6.9 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-copy-button
package wa
import (
"github.com/a-h/templ"
)
// Copies text data to the clipboard when the user clicks the trigger.
//
// Web Awesome component: <wa-copy-button>
// CopyButtonProps holds all properties for the wa-copy-button component
type CopyButtonProps struct {
// The text value to copy.
Value string `attr:"value"`
// An id that references an element in the same document from which data will be copied. If both this and value are
From string `attr:"from"`
// Disables the copy button.
Disabled bool `attr:"disabled"`
// A custom label to show in the tooltip.
CopyLabel string `attr:"copy-label"`
// A custom label to show in the tooltip after copying.
SuccessLabel string `attr:"success-label"`
// A custom label to show in the tooltip when a copy error occurs.
ErrorLabel string `attr:"error-label"`
// The length of time to show feedback before restoring the default trigger.
FeedbackDuration float64 `attr:"feedback-duration"`
// The preferred placement of the tooltip.
// Valid values: "top", "right", "bottom", "left"
TooltipPlacement string `attr:"tooltip-placement"`
// Events
// Emitted when the data has been copied.
OnCopy string `attr:"x-on:wa-copy"`
// Emitted when the data could not be copied.
OnError string `attr:"x-on:wa-error"`
// Slots contains named slot content
Slots CopyButtonSlots
// Attrs contains additional HTML attributes
Attrs templ.Attributes
}
// CopyButtonSlots holds named slot content for the component
type CopyButtonSlots struct {
// The icon to show in the default copy state. Works best with <wa-icon>.
CopyIcon templ.Component
// The icon to show when the content is copied. Works best with <wa-icon>.
SuccessIcon templ.Component
// The icon to show when a copy error occurs. Works best with <wa-icon>.
ErrorIcon templ.Component
}
// CopyButtonBuilder provides a fluent API for constructing CopyButtonProps
type CopyButtonBuilder struct {
props CopyButtonProps
}
// NewCopyButton creates a new builder for wa-copy-button
func NewCopyButton() *CopyButtonBuilder {
return &CopyButtonBuilder{}
}
// Value sets the value attribute
// The text value to copy.
func (b *CopyButtonBuilder) Value(v string) *CopyButtonBuilder {
b.props.Value = v
return b
}
// From sets the from attribute
// An id that references an element in the same document from which data will be copied. If both this and value are
func (b *CopyButtonBuilder) From(v string) *CopyButtonBuilder {
b.props.From = v
return b
}
// Disabled sets the disabled attribute
// Disables the copy button.
func (b *CopyButtonBuilder) Disabled(v bool) *CopyButtonBuilder {
b.props.Disabled = v
return b
}
// CopyLabel sets the copy-label attribute
// A custom label to show in the tooltip.
func (b *CopyButtonBuilder) CopyLabel(v string) *CopyButtonBuilder {
b.props.CopyLabel = v
return b
}
// SuccessLabel sets the success-label attribute
// A custom label to show in the tooltip after copying.
func (b *CopyButtonBuilder) SuccessLabel(v string) *CopyButtonBuilder {
b.props.SuccessLabel = v
return b
}
// ErrorLabel sets the error-label attribute
// A custom label to show in the tooltip when a copy error occurs.
func (b *CopyButtonBuilder) ErrorLabel(v string) *CopyButtonBuilder {
b.props.ErrorLabel = v
return b
}
// FeedbackDuration sets the feedback-duration attribute
// The length of time to show feedback before restoring the default trigger.
func (b *CopyButtonBuilder) FeedbackDuration(v float64) *CopyButtonBuilder {
b.props.FeedbackDuration = v
return b
}
// TooltipPlacement sets the tooltip-placement attribute
// The preferred placement of the tooltip.
func (b *CopyButtonBuilder) TooltipPlacement(v string) *CopyButtonBuilder {
b.props.TooltipPlacement = v
return b
}
// OnCopy sets the handler for wa-copy event
// Emitted when the data has been copied.
func (b *CopyButtonBuilder) OnCopy(handler string) *CopyButtonBuilder {
b.props.OnCopy = handler
return b
}
// OnError sets the handler for wa-error event
// Emitted when the data could not be copied.
func (b *CopyButtonBuilder) OnError(handler string) *CopyButtonBuilder {
b.props.OnError = handler
return b
}
// CopyIconSlot sets the copy-icon slot content
// The icon to show in the default copy state. Works best with <wa-icon>.
func (b *CopyButtonBuilder) CopyIconSlot(c templ.Component) *CopyButtonBuilder {
b.props.Slots.CopyIcon = c
return b
}
// SuccessIconSlot sets the success-icon slot content
// The icon to show when the content is copied. Works best with <wa-icon>.
func (b *CopyButtonBuilder) SuccessIconSlot(c templ.Component) *CopyButtonBuilder {
b.props.Slots.SuccessIcon = c
return b
}
// ErrorIconSlot sets the error-icon slot content
// The icon to show when a copy error occurs. Works best with <wa-icon>.
func (b *CopyButtonBuilder) ErrorIconSlot(c templ.Component) *CopyButtonBuilder {
b.props.Slots.ErrorIcon = c
return b
}
// Attr adds a custom HTML attribute
func (b *CopyButtonBuilder) Attr(name, value string) *CopyButtonBuilder {
if b.props.Attrs == nil {
b.props.Attrs = templ.Attributes{}
}
b.props.Attrs[name] = value
return b
}
// Attrs merges multiple attributes
func (b *CopyButtonBuilder) Attrs(attrs templ.Attributes) *CopyButtonBuilder {
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 *CopyButtonBuilder) Props() CopyButtonProps {
return b.props
}
// Build returns the props (alias for Props for semantic clarity)
func (b *CopyButtonBuilder) Build() CopyButtonProps {
return b.props
}
// CopyButton renders the wa-copy-button component
templ CopyButton(props CopyButtonProps) {
<wa-copy-button
if props.Value != "" {
value={ props.Value }
}
if props.From != "" {
from={ props.From }
}
if props.Disabled {
disabled
}
if props.CopyLabel != "" {
copy-label={ props.CopyLabel }
}
if props.SuccessLabel != "" {
success-label={ props.SuccessLabel }
}
if props.ErrorLabel != "" {
error-label={ props.ErrorLabel }
}
if props.FeedbackDuration != 0 {
feedback-duration={ templ.Sprintf("%v", props.FeedbackDuration) }
}
if props.TooltipPlacement != "" {
tooltip-placement={ props.TooltipPlacement }
}
if props.OnCopy != "" {
x-on:wa-copy={ props.OnCopy }
}
if props.OnError != "" {
x-on:wa-error={ props.OnError }
}
{ props.Attrs... }
>
if props.Slots.CopyIcon != nil {
<div slot="copy-icon">
@props.Slots.CopyIcon
</div>
}
if props.Slots.SuccessIcon != nil {
<div slot="success-icon">
@props.Slots.SuccessIcon
</div>
}
if props.Slots.ErrorIcon != nil {
<div slot="error-icon">
@props.Slots.ErrorIcon
</div>
}
{ children... }
</wa-copy-button>
}
// CopyButtonFunc renders with a builder function for inline configuration
templ CopyButtonFunc(fn func(*CopyButtonBuilder)) {
{{ b := NewCopyButton(); fn(b) }}
@CopyButton(b.Props()) {
{ children... }
}
}