htmgo/partials/sheet/sheet.go

48 lines
936 B
Go
Raw Normal View History

2024-09-11 17:31:40 +00:00
package sheet
import (
2024-09-12 02:06:34 +00:00
"fmt"
2024-09-11 17:31:40 +00:00
"github.com/gofiber/fiber/v2"
"mhtml/h"
)
2024-09-11 18:09:55 +00:00
type Props struct {
2024-09-12 02:06:34 +00:00
ClassName string
Root h.Renderable
OnClosePath string
2024-09-11 18:09:55 +00:00
}
var Id = "#active-modal"
func Opened(props Props) h.Renderable {
2024-09-11 17:31:40 +00:00
return h.Fragment(h.Div(
2024-09-11 18:09:55 +00:00
h.Class(`fixed top-0 right-0 h-full shadow-lg z-50`,
h.Ternary(props.ClassName != "", props.ClassName, "w-96 bg-gray-100")),
2024-09-12 02:06:34 +00:00
closeButton(props),
2024-09-11 17:31:40 +00:00
h.Div(
2024-09-11 18:09:55 +00:00
props.Root,
2024-09-11 17:31:40 +00:00
)))
}
func Closed() h.Renderable {
2024-09-11 18:09:55 +00:00
return h.Div(h.Id(Id))
2024-09-11 17:31:40 +00:00
}
func Close(ctx *fiber.Ctx) *h.Partial {
2024-09-12 02:06:34 +00:00
return h.NewPartialWithHeaders(
h.Ternary(ctx.Query("path") != "", h.ReplaceUrlHeader(ctx.Query("path")), h.NewHeaders()),
2024-09-11 17:31:40 +00:00
h.Swap(ctx, Closed()),
)
}
2024-09-12 02:06:34 +00:00
func closeButton(props Props) h.Renderable {
2024-09-11 17:31:40 +00:00
return h.Div(
h.Class("absolute top-0 right-0 p-3"),
h.Button(
h.Class("text-gray-500"),
2024-09-12 02:06:34 +00:00
h.GetPartialWithQs(Close, fmt.Sprintf("path=%s", props.OnClosePath)),
2024-09-11 17:31:40 +00:00
h.Text("X"),
),
)
}