htmgo/framework-ui/ui/button.go

42 lines
1,009 B
Go
Raw Normal View History

2024-09-11 00:52:18 +00:00
package ui
2024-09-14 00:05:55 +00:00
import "github.com/maddalax/htmgo/framework/h"
2024-09-11 00:52:18 +00:00
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
Children []h.Ren
2024-09-11 00:52:18 +00:00
}
func PrimaryButton(props ButtonProps) h.Ren {
2024-09-11 00:52:18 +00:00
props.Class = h.MergeClasses(props.Class, "border-blue-700 bg-blue-700 text-white")
return Button(props)
}
func SecondaryButton(props ButtonProps) h.Ren {
2024-09-11 00:52:18 +00:00
props.Class = h.MergeClasses(props.Class, "border-gray-700 bg-gray-700 text-white")
return Button(props)
}
func Button(props ButtonProps) h.Ren {
2024-09-11 00:52:18 +00:00
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...)),
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)),
2024-09-21 16:52:56 +00:00
h.If(props.Target != "", h.HxTarget(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
}