62 lines
1.4 KiB
Swift
62 lines
1.4 KiB
Swift
import Elementary
|
|
import SharedModels
|
|
import URLRouting
|
|
|
|
// TODO: Remove.
|
|
struct ToggleFormButton: HTML, Sendable {
|
|
var content: some HTML<HTMLTag.a> {
|
|
a(.href("javascript:void(0)"), .on(.click, "toggleContent('form')"), .class("btn-add")) {
|
|
"+"
|
|
}
|
|
}
|
|
}
|
|
|
|
enum Button {
|
|
|
|
@Sendable
|
|
static func add() -> some HTML<HTMLTag.button> {
|
|
button(.class("btn btn-add")) { "+" }
|
|
}
|
|
|
|
@Sendable
|
|
static func danger<C: HTML>(@HTMLBuilder body: () -> C) -> some HTML<HTMLTag.button> {
|
|
button(.class("danger")) { body() }
|
|
}
|
|
|
|
@Sendable
|
|
static func close(id: String, resetURL: String? = nil) -> some HTML<HTMLTag.button> {
|
|
button(.class("btn-close"), .on(.click, makeOnClick(id, resetURL))) {
|
|
"x"
|
|
}
|
|
}
|
|
|
|
@Sendable
|
|
static func close(id: IDKey, resetURL route: ViewRoute? = nil) -> some HTML<HTMLTag.button> {
|
|
close(
|
|
id: id.description,
|
|
resetURL: route != nil ? ViewRoute.router.path(for: route!) : nil
|
|
)
|
|
}
|
|
|
|
@Sendable
|
|
static func update() -> some HTML<HTMLTag.button> {
|
|
button(.class("btn-update")) { "Update" }
|
|
}
|
|
|
|
@Sendable
|
|
static func detail() -> some HTML<HTMLTag.button> {
|
|
button(.class("btn-detail")) {
|
|
"〉"
|
|
}
|
|
}
|
|
|
|
@Sendable
|
|
private static func makeOnClick(_ id: String, _ resetURL: String?) -> String {
|
|
let output = "toggleContent('\(id)');"
|
|
if let resetURL {
|
|
return "\(output) window.location.href='\(resetURL)';"
|
|
}
|
|
return output
|
|
}
|
|
}
|