htmgo/examples/chat/pages/index.go

88 lines
2.3 KiB
Go
Raw Normal View History

package pages
import (
2024-10-01 01:32:42 +00:00
"chat/components"
"chat/partials"
"github.com/maddalax/htmgo/framework/h"
)
2024-10-01 01:32:42 +00:00
func ChatAppFirstScreen(ctx *h.RequestContext) *h.Page {
return h.NewPage(
RootPage(
h.Div(
2024-10-01 01:32:42 +00:00
h.Class("flex flex-col items-center justify-center min-h-screen bg-neutral-100"),
h.Div(
2024-10-01 01:32:42 +00:00
h.Class("bg-white p-8 rounded-lg shadow-lg w-full max-w-md"),
h.H2F(
"htmgo chat",
h.Class("text-3xl font-bold text-center mb-6"),
),
2024-10-01 01:32:42 +00:00
h.Form(
h.Attribute("hx-swap", "none"),
h.PostPartial(partials.CreateOrJoinRoom),
2024-10-01 17:56:16 +00:00
h.Class("flex flex-col gap-6"),
// Username input at the top
2024-10-01 01:32:42 +00:00
components.Input(components.InputProps{
Id: "username",
Name: "username",
Label: "Username",
Required: true,
2024-10-01 17:42:01 +00:00
Children: []h.Ren{
h.Attribute("autocomplete", "off"),
h.MaxLength(15),
},
2024-10-01 01:32:42 +00:00
}),
2024-10-01 17:56:16 +00:00
// Single box for Create or Join a Chat Room
2024-10-01 01:32:42 +00:00
h.Div(
2024-10-01 17:56:16 +00:00
h.Class("p-4 border border-gray-300 rounded-md flex flex-col gap-6"),
// Create New Chat Room input
2024-10-01 01:32:42 +00:00
components.Input(components.InputProps{
Name: "new-chat-room",
2024-10-01 17:56:16 +00:00
Label: "Create a new chat room",
Placeholder: "Enter chat room name",
2024-10-01 17:42:01 +00:00
Children: []h.Ren{
h.Attribute("autocomplete", "off"),
h.MaxLength(20),
},
2024-10-01 01:32:42 +00:00
}),
2024-10-01 17:56:16 +00:00
// OR divider
2024-10-01 01:32:42 +00:00
h.Div(
h.Class("flex items-center justify-center gap-4"),
h.Div(
h.Class("border-t border-gray-300 flex-grow"),
),
h.P(
h.Text("OR"),
h.Class("text-gray-500"),
),
h.Div(
h.Class("border-t border-gray-300 flex-grow"),
),
2024-10-01 01:32:42 +00:00
),
2024-10-01 17:56:16 +00:00
// Join Chat Room input
2024-10-01 01:32:42 +00:00
components.Input(components.InputProps{
2024-10-01 17:56:16 +00:00
Id: "join-chat-room",
Name: "join-chat-room",
Label: "Join an existing chat room",
Placeholder: "Enter chat room ID",
DefaultValue: ctx.QueryParam("roomId"),
2024-10-01 17:42:01 +00:00
Children: []h.Ren{
h.Attribute("autocomplete", "off"),
h.MaxLength(100),
},
2024-10-01 01:32:42 +00:00
}),
),
2024-10-01 17:56:16 +00:00
// Error message
2024-10-01 01:32:42 +00:00
components.FormError(""),
2024-10-01 17:56:16 +00:00
// Submit button at the bottom
2024-10-01 01:32:42 +00:00
components.PrimaryButton(components.ButtonProps{
Type: "submit",
Text: "Submit",
}),
),
),
),
),
)
}