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