Migrate from templates to Gomponents (#103)
This commit is contained in:
parent
0bf9ab7189
commit
051d032038
104 changed files with 2768 additions and 2824 deletions
53
pkg/ui/forms/cache.go
Normal file
53
pkg/ui/forms/cache.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
CurrentValue string
|
||||
Value string `form:"value"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *Cache) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("cache"),
|
||||
Method(http.MethodPost),
|
||||
Attr("hx-post", r.Path(routenames.CacheSubmit)),
|
||||
Message(
|
||||
"is-info",
|
||||
"Test the cache",
|
||||
Group{
|
||||
P(Text("This route handler shows how the default in-memory cache works. Try updating the value using the form below and see how it persists after you reload the page.")),
|
||||
P(Text("HTMX makes it easy to re-render the cached value after the form is submitted.")),
|
||||
},
|
||||
),
|
||||
Label(
|
||||
For("value"),
|
||||
Class("value"),
|
||||
Text("Value in cache: "),
|
||||
),
|
||||
If(f.CurrentValue != "", Span(Class("tag is-success"), Text(f.CurrentValue))),
|
||||
If(f.CurrentValue == "", I(Text("(empty)"))),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Value",
|
||||
Name: "value",
|
||||
InputType: "text",
|
||||
Label: "Value",
|
||||
Value: f.Value,
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-link", "Update cache"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
58
pkg/ui/forms/contact.go
Normal file
58
pkg/ui/forms/contact.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type Contact struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Department string `form:"department" validate:"required,oneof=sales marketing hr"`
|
||||
Message string `form:"message" validate:"required"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *Contact) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("contact"),
|
||||
Method(http.MethodPost),
|
||||
Attr("hx-post", r.Path(routenames.ContactSubmit)),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Email",
|
||||
Name: "email",
|
||||
InputType: "email",
|
||||
Label: "Email address",
|
||||
Value: f.Email,
|
||||
}),
|
||||
Radios(RadiosParams{
|
||||
Form: f,
|
||||
FormField: "Department",
|
||||
Name: "department",
|
||||
Label: "Department",
|
||||
Value: f.Department,
|
||||
Options: []Radio{
|
||||
{Value: "sales", Label: "Sales"},
|
||||
{Value: "marketing", Label: "Marketing"},
|
||||
{Value: "hr", Label: "HR"},
|
||||
},
|
||||
}),
|
||||
TextareaField(TextareaFieldParams{
|
||||
Form: f,
|
||||
FormField: "Message",
|
||||
Name: "message",
|
||||
Label: "Message",
|
||||
Value: f.Message,
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-link", "Submit"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
27
pkg/ui/forms/file.go
Normal file
27
pkg/ui/forms/file.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type File struct{}
|
||||
|
||||
func (f File) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("files"),
|
||||
Method(http.MethodPost),
|
||||
Action(r.Path(routenames.FilesSubmit)),
|
||||
EncType("multipart/form-data"),
|
||||
FileField("file", "Choose a file.. "),
|
||||
ControlGroup(
|
||||
FormButton("is-link", "Upload"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
39
pkg/ui/forms/forgot_password.go
Normal file
39
pkg/ui/forms/forgot_password.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type ForgotPassword struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *ForgotPassword) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("forgot-password"),
|
||||
Method(http.MethodPost),
|
||||
HxBoost(),
|
||||
Action(r.Path(routenames.ForgotPasswordSubmit)),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Email",
|
||||
Name: "email",
|
||||
InputType: "email",
|
||||
Label: "Email address",
|
||||
Value: f.Email,
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-primary", "Reset password"),
|
||||
ButtonLink(r.Path(routenames.Home), "is-light", "Cancel"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
49
pkg/ui/forms/login.go
Normal file
49
pkg/ui/forms/login.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type Login struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Password string `form:"password" validate:"required"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *Login) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("login"),
|
||||
Method(http.MethodPost),
|
||||
HxBoost(),
|
||||
Action(r.Path(routenames.LoginSubmit)),
|
||||
FlashMessages(r),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Email",
|
||||
Name: "email",
|
||||
InputType: "email",
|
||||
Label: "Email address",
|
||||
Value: f.Email,
|
||||
}),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Password",
|
||||
Name: "password",
|
||||
InputType: "password",
|
||||
Label: "Password",
|
||||
Placeholder: "******",
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-link", "Login"),
|
||||
ButtonLink(r.Path(routenames.Home), "is-light", "Cancel"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
66
pkg/ui/forms/register.go
Normal file
66
pkg/ui/forms/register.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type Register struct {
|
||||
Name string `form:"name" validate:"required"`
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Password string `form:"password" validate:"required"`
|
||||
ConfirmPassword string `form:"password-confirm" validate:"required,eqfield=Password"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *Register) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("register"),
|
||||
Method(http.MethodPost),
|
||||
HxBoost(),
|
||||
Action(r.Path(routenames.RegisterSubmit)),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Name",
|
||||
Name: "name",
|
||||
InputType: "text",
|
||||
Label: "Name",
|
||||
Value: f.Name,
|
||||
}),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Email",
|
||||
Name: "email",
|
||||
InputType: "email",
|
||||
Label: "Email address",
|
||||
Value: f.Email,
|
||||
}),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Password",
|
||||
Name: "password",
|
||||
InputType: "password",
|
||||
Label: "Password",
|
||||
Placeholder: "******",
|
||||
}),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "PasswordConfirm",
|
||||
Name: "password-confirm",
|
||||
InputType: "password",
|
||||
Label: "Confirm password",
|
||||
Placeholder: "******",
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-primary", "Register"),
|
||||
ButtonLink(r.Path(routenames.Home), "is-light", "Cancel"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
46
pkg/ui/forms/reset_password.go
Normal file
46
pkg/ui/forms/reset_password.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type ResetPassword struct {
|
||||
Password string `form:"password" validate:"required"`
|
||||
ConfirmPassword string `form:"password-confirm" validate:"required,eqfield=Password"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *ResetPassword) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("reset-password"),
|
||||
Method(http.MethodPost),
|
||||
HxBoost(),
|
||||
Action(r.CurrentPath),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Password",
|
||||
Name: "password",
|
||||
InputType: "password",
|
||||
Label: "Password",
|
||||
Placeholder: "******",
|
||||
}),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "PasswordConfirm",
|
||||
Name: "password-confirm",
|
||||
InputType: "password",
|
||||
Label: "Confirm password",
|
||||
Placeholder: "******",
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-primary", "Update password"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
49
pkg/ui/forms/task.go
Normal file
49
pkg/ui/forms/task.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package forms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/mikestefanello/pagoda/pkg/form"
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
Delay int `form:"delay" validate:"gte=0"`
|
||||
Message string `form:"message" validate:"required"`
|
||||
form.Submission
|
||||
}
|
||||
|
||||
func (f *Task) Render(r *ui.Request) Node {
|
||||
return Form(
|
||||
ID("task"),
|
||||
Method(http.MethodPost),
|
||||
Attr("hx-post", r.Path(routenames.TaskSubmit)),
|
||||
FlashMessages(r),
|
||||
InputField(InputFieldParams{
|
||||
Form: f,
|
||||
FormField: "Delay",
|
||||
Name: "delay",
|
||||
InputType: "number",
|
||||
Label: "Delay (in seconds)",
|
||||
Help: "How long to wait until the task is executed",
|
||||
Value: fmt.Sprint(f.Delay),
|
||||
}),
|
||||
TextareaField(TextareaFieldParams{
|
||||
Form: f,
|
||||
FormField: "Message",
|
||||
Name: "message",
|
||||
Label: "Message",
|
||||
Value: f.Message,
|
||||
Help: "The message the task will output to the log",
|
||||
}),
|
||||
ControlGroup(
|
||||
FormButton("is-link", "Add task to queue"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue