feat: Initial view controller dependency and snapshot tests.
This commit is contained in:
53
Sources/ViewControllerLive/Views/Utils/Buttons.swift
Normal file
53
Sources/ViewControllerLive/Views/Utils/Buttons.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
import Elementary
|
||||
import SharedModels
|
||||
import URLRouting
|
||||
|
||||
struct ToggleFormButton: HTML {
|
||||
var content: some HTML<HTMLTag.a> {
|
||||
a(.href("javascript:void(0)"), .on(.click, "toggleContent('form')"), .class("btn-add")) {
|
||||
"+"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Button {
|
||||
|
||||
static func add() -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn btn-add")) { "+" }
|
||||
}
|
||||
|
||||
static func danger<C: HTML>(@HTMLBuilder body: () -> C) -> some HTML<HTMLTag.button> {
|
||||
button(.class("danger")) { body() }
|
||||
}
|
||||
|
||||
static func close(id: String, resetURL: String? = nil) -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn-close"), .on(.click, makeOnClick(id, resetURL))) {
|
||||
"x"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
static func update() -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn-update")) { "Update" }
|
||||
}
|
||||
|
||||
static func detail() -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn-detail")) {
|
||||
"〉"
|
||||
}
|
||||
}
|
||||
|
||||
private static func makeOnClick(_ id: String, _ resetURL: String?) -> String {
|
||||
let output = "toggleContent('\(id)');"
|
||||
if let resetURL {
|
||||
return "\(output) window.location.href='\(resetURL)';"
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user