htmgo/ui/button.go

45 lines
1 KiB
Go
Raw Normal View History

2024-09-11 00:52:18 +00:00
package ui
import (
"mhtml/h"
)
type ButtonProps struct {
2024-09-11 17:31:40 +00:00
Id string
2024-09-11 00:52:18 +00:00
Text string
Target string
2024-09-11 18:09:55 +00:00
Type string
2024-09-11 17:31:40 +00:00
Trigger string
2024-09-11 00:52:18 +00:00
Get string
Class string
2024-09-11 17:31:40 +00:00
Children []*h.Node
2024-09-11 00:52:18 +00:00
}
func PrimaryButton(props ButtonProps) *h.Node {
props.Class = h.MergeClasses(props.Class, "border-blue-700 bg-blue-700 text-white")
return Button(props)
}
func SecondaryButton(props ButtonProps) *h.Node {
props.Class = h.MergeClasses(props.Class, "border-gray-700 bg-gray-700 text-white")
return Button(props)
}
func Button(props ButtonProps) *h.Node {
2024-09-11 17:31:40 +00:00
text := h.Text(props.Text)
2024-09-11 00:52:18 +00:00
button := h.Button(
2024-09-11 17:31:40 +00:00
h.If(props.Id != "", h.Id(props.Id)),
h.If(props.Children != nil, h.Children(props.Children)),
h.If(props.Trigger != "", h.Trigger(props.Trigger)),
2024-09-11 00:52:18 +00:00
h.Class("flex gap-1 items-center border p-4 rounded cursor-hover", props.Class),
h.If(props.Get != "", h.Get(props.Get)),
h.If(props.Target != "", h.Target(props.Target)),
2024-09-11 18:09:55 +00:00
h.IfElse(props.Type != "", h.Type(props.Type), h.Type("button")),
2024-09-11 00:52:18 +00:00
text,
)
return button
}