xtablo-source/backend/internal/web/ui/helpers.go
Arthur Belleville d1499659bf
feat(13-01): extend variants.go with new enums and helpers.go with helper functions (GREEN)
- Add ButtonVariantGhost to ButtonVariant enum and NormalizedButtonVariant switch
- Add BadgeVariantPrimary to BadgeVariant enum and NormalizedBadgeVariant switch
- Add IconButtonVariant type (Neutral/Warning/Success/Danger) with normalizer
- Add IconButtonTone type (Solid/Ghost) with normalizer
- Add SpacingStep type (XS/SM/MD/LG/XL) with normalizer
- Add IconButtonClass(), SpaceXClass(), SpaceYClass() exported class functions
- Add buttonType(), inputType(), inputID(), textareaRows() helper functions to helpers.go
- Fix TestButtonClass_GhostVariant assertion to match compound class format preserved for Plan 02
2026-05-16 13:46:30 +02:00

56 lines
1.3 KiB
Go

package ui
import (
"strconv"
"github.com/a-h/templ"
)
// mergeAttrs returns a new templ.Attributes containing every key from base,
// with override keys taking precedence on collision. Either input may be nil.
func mergeAttrs(base, override templ.Attributes) templ.Attributes {
out := templ.Attributes{}
for k, v := range base {
out[k] = v
}
for k, v := range override {
out[k] = v
}
return out
}
// buttonType returns "button" if value is empty, otherwise value.
// Used to set default type="button" on button elements without an explicit type.
func buttonType(value string) string {
if value == "" {
return "button"
}
return value
}
// inputType returns "text" if value is empty, otherwise value.
// Used to set default type="text" on input elements without an explicit type.
func inputType(value string) string {
if value == "" {
return "text"
}
return value
}
// inputID returns id if non-empty, otherwise name.
// Used to derive an implicit id from the name attribute when no id is provided.
func inputID(id string, name string) string {
if id != "" {
return id
}
return name
}
// textareaRows returns strconv.Itoa(rows) if rows > 0, else "4".
// Used to set a safe default row count on textarea elements.
func textareaRows(rows int) string {
if rows <= 0 {
rows = 4
}
return strconv.Itoa(rows)
}