feat: Initial filter pressure drop views, calculations need implemented.

This commit is contained in:
2025-03-02 21:51:52 -05:00
parent a8022ec80a
commit 67488e06a9
17 changed files with 610 additions and 97 deletions

View File

@@ -1,4 +1,5 @@
import Elementary
import Routes
public struct PrimaryButton: HTML, Sendable {
let label: String
@@ -75,3 +76,70 @@ public struct ResetButton: HTML, Sendable {
}
}
}
public struct Toggle: HTML {
let isOn: Bool
// Left hand side / 'on' label.
let onLabel: String
// Applied to the rhs when the toggle is consider 'off'.
let onAttributes: [HTMLAttribute<HTMLTag.button>]
// Right hand side / 'off' label.
let offLabel: String
// Applied to the left hand side when the toggle is consider 'on'.
let offAttributes: [HTMLAttribute<HTMLTag.button>]
public init(
isOn: Bool,
onLabel: String,
onAttributes: [HTMLAttribute<HTMLTag.button>],
offLabel: String,
offAttributes: [HTMLAttribute<HTMLTag.button>]
) {
self.isOn = isOn
self.onLabel = onLabel
self.onAttributes = onAttributes
self.offLabel = offLabel
self.offAttributes = offAttributes
}
public var content: some HTML<HTMLTag.div> {
div(.class("flex items-center gap-x-0")) {
switch isOn {
case true:
SecondaryButton(label: onLabel)
.attributes(.class("rounded-s-lg"), .disabled)
PrimaryButton(label: offLabel)
.attributes(contentsOf: offAttributes + [.class("rounded-e-lg")])
case false:
PrimaryButton(label: onLabel)
.attributes(contentsOf: onAttributes + [.class("rounded-s-lg")])
SecondaryButton(label: offLabel)
.attributes(.class("rounded-e-lg"), .disabled)
}
}
}
}
public extension Array where Element == HTMLAttribute<HTMLTag.button> {
static func hxDefaults(
_ attributes: HTMLAttribute<HTMLTag.button>...
) -> Self {
[
.hx.target("#content"),
.hx.pushURL(true)
] + attributes
}
static func hxDefaults(
get route: SiteRoute.View
) -> Self {
.hxDefaults(.hx.get(route: route))
}
}