feat: Initial view controller dependency and snapshot tests.
This commit is contained in:
81
Sources/ViewControllerLive/Views/Utils/Float.swift
Normal file
81
Sources/ViewControllerLive/Views/Utils/Float.swift
Normal file
@@ -0,0 +1,81 @@
|
||||
import Elementary
|
||||
import SharedModels
|
||||
|
||||
struct Float<C: HTML, B: HTML>: 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<HTMLTag.div> {
|
||||
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 route: ViewRoute? = nil,
|
||||
@HTMLBuilder body: () -> C
|
||||
) {
|
||||
self.init(
|
||||
id: id,
|
||||
shouldDisplay: shouldDisplay,
|
||||
body: body,
|
||||
closeButton: { DefaultCloseButton(
|
||||
id: id,
|
||||
resetURL: route != nil ? ViewRoute.router.path(for: route!) : nil
|
||||
) }
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Float: Sendable where C: Sendable, B: Sendable {}
|
||||
Reference in New Issue
Block a user