htmgo/partials/sheet/sheet.go

45 lines
736 B
Go
Raw Normal View History

2024-09-11 17:31:40 +00:00
package sheet
import (
"github.com/gofiber/fiber/v2"
"mhtml/h"
)
2024-09-11 18:09:55 +00:00
type Props struct {
ClassName string
Root h.Renderable
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")),
closeButton(),
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 {
return h.NewPartial(
h.Swap(ctx, Closed()),
)
}
func closeButton() 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"),
h.GetPartial(Close),
h.Text("X"),
),
)
}