feat: Working on layout / css.

This commit is contained in:
2025-01-15 14:31:36 -05:00
parent cf28e52fa2
commit 24570e7191
15 changed files with 285 additions and 118 deletions

View File

@@ -5,12 +5,27 @@ struct UserForm: HTML, Sendable {
let context: Context
var content: some HTML {
if context == .create {
Float(shouldDisplay: true) {
makeForm()
}
} else {
makeForm()
}
}
private func makeForm() -> some HTML {
form(
.id("user-form"),
.class("user-form"),
.hx.post(context.targetURL),
.hx.pushURL(context.pushURL),
.custom(name: "hx-on::after-request", value: "if(event.detail.successful) this.reset(); toggleContent('form');")
.hx.target(context.target),
.hx.swap(.outerHTML),
.custom(
name: "hx-on::after-request",
value: "if(event.detail.successful) this.reset(); toggleContent('float');"
)
) {
input(.type(.text), .id("username"), .name("username"), .placeholder("Username"), .autofocus, .required)
br()
@@ -21,14 +36,20 @@ struct UserForm: HTML, Sendable {
input(.type(.password), .id("password"), .name("password"), .placeholder("Password"), .required)
br()
if context.showConfirmPassword {
input(.type(.password), .id("confirmPassword"), .name("confirmPassword"), .required)
input(
.type(.password),
.id("confirmPassword"),
.name("confirmPassword"),
.placeholder("Confirm Password"),
.required
)
br()
}
input(.type(.submit), .value(context.buttonLabel))
}
}
enum Context {
enum Context: Equatable {
case create
case login(next: String?)
@@ -62,6 +83,15 @@ struct UserForm: HTML, Sendable {
}
}
var target: String {
switch self {
case .create:
return "next table"
case .login:
return "body"
}
}
var targetURL: String {
switch self {
case .create: