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 23:41:21 +00:00
|
|
|
Children []h.Renderable
|
2024-09-11 00:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-11 23:41:21 +00:00
|
|
|
func PrimaryButton(props ButtonProps) h.Renderable {
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 23:41:21 +00:00
|
|
|
func SecondaryButton(props ButtonProps) h.Renderable {
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 23:41:21 +00:00
|
|
|
func Button(props ButtonProps) h.Renderable {
|
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)),
|
|
|
|
|
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-12 02:06:34 +00:00
|
|
|
//h.Attribute("hx-indicator", "#spinner"),
|
2024-09-11 18:09:55 +00:00
|
|
|
h.IfElse(props.Type != "", h.Type(props.Type), h.Type("button")),
|
2024-09-12 02:06:34 +00:00
|
|
|
h.BeforeRequestSetText("Loading..."),
|
|
|
|
|
h.AfterRequestSetText(props.Text),
|
2024-09-11 00:52:18 +00:00
|
|
|
text,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return button
|
|
|
|
|
}
|