import Elementary import SharedModels 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, Sendable { 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 {}