import Elementary import SharedModels import URLRouting struct ToggleFormButton: HTML { var content: some HTML { a(.href("javascript:void(0)"), .on(.click, "toggleContent('form')"), .class("btn-add")) { "+" } } } enum Button { static func add() -> some HTML { button(.class("btn btn-add")) { "+" } } static func danger(@HTMLBuilder body: () -> C) -> some HTML { button(.class("danger")) { body() } } static func close(id: String, resetURL: String? = nil) -> some HTML { button(.class("btn-close"), .on(.click, makeOnClick(id, resetURL))) { "x" } } static func close(id: IDKey, resetURL route: ViewRoute? = nil) -> some HTML { close( id: id.description, resetURL: route != nil ? ViewRoute.router.path(for: route!) : nil ) } static func update() -> some HTML { button(.class("btn-update")) { "Update" } } static func detail() -> some HTML { 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 } }