feat: Working vendor views, does need some tweeks to user experience.

This commit is contained in:
2025-01-16 11:09:35 -05:00
parent d4a8444700
commit 51124205b8
7 changed files with 155 additions and 91 deletions

View File

@@ -1,29 +1,29 @@
import Elementary
struct Float<C: HTML>: HTML {
struct Float<C: HTML, B: HTML>: HTML {
let id: String
let shouldDisplay: Bool
let body: C?
let resetURL: String?
let closeButton: B?
init(id: String = "float") {
self.id = id
self.shouldDisplay = false
self.resetURL = nil
self.body = nil
self.closeButton = nil
}
init(
id: String = "float",
shouldDisplay: Bool,
resetURL: String? = nil,
@HTMLBuilder body: () -> C
@HTMLBuilder body: () -> C,
@HTMLBuilder closeButton: () -> B
) {
self.id = id
self.shouldDisplay = shouldDisplay
self.resetURL = resetURL
self.body = body()
self.closeButton = closeButton()
}
private var classString: String {
@@ -37,8 +37,10 @@ struct Float<C: HTML>: HTML {
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)
if let closeButton {
div(.class("btn-row")) {
closeButton
}
}
body
}
@@ -46,4 +48,30 @@ struct Float<C: HTML>: HTML {
}
}
extension Float: Sendable where C: Sendable {}
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 {}