htmgo/sandbox/partials/sheet/sheet.go

48 lines
968 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-17 17:13:22 +00:00
"github.com/labstack/echo/v4"
2024-09-14 00:05:55 +00:00
"github.com/maddalax/htmgo/framework/h"
2024-09-11 17:31:40 +00:00
)
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
}
2024-09-17 17:13:22 +00:00
func Close(ctx echo.Context) *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"),
),
)
}