Files
vapor-po/Sources/App/Views/Utils/Float.swift

50 lines
971 B
Swift

import Elementary
struct Float<C: HTML>: HTML {
let id: String
let shouldDisplay: Bool
let body: C?
let resetURL: String?
init(id: String = "float") {
self.id = id
self.shouldDisplay = false
self.resetURL = nil
self.body = nil
}
init(
id: String = "float",
shouldDisplay: Bool,
resetURL: String? = nil,
@HTMLBuilder body: () -> C
) {
self.id = id
self.shouldDisplay = shouldDisplay
self.resetURL = resetURL
self.body = body()
}
private var classString: String {
shouldDisplay ? "float" : ""
}
private var display: String {
shouldDisplay ? "block" : "hidden"
}
var content: some HTML<HTMLTag.div> {
div(.id(id), .class(classString), .style("display: \(display);")) {
if let body, shouldDisplay {
div(.class("btn-row")) {
Button.close(id: id, resetURL: resetURL)
}
body
}
}
}
}
extension Float: Sendable where C: Sendable {}