This repository has been archived on 2026-02-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
swift-duct-calc/Sources/Styleguide/ElementaryExtensions.swift

57 lines
1.4 KiB
Swift

import Elementary
import Foundation
import ManualDCore
extension HTMLAttribute where Tag: HTMLTrait.Attributes.href {
public static func href(route: SiteRoute.View) -> Self {
href(SiteRoute.View.router.path(for: route))
}
}
extension HTMLAttribute where Tag == HTMLTag.form {
public static func action(route: SiteRoute.View) -> Self {
action(SiteRoute.View.router.path(for: route))
}
}
extension HTMLAttribute where Tag == HTMLTag.input {
public static func value(_ string: String?) -> Self {
value(string ?? "")
}
public static func value(_ int: Int?) -> Self {
value(int == nil ? "" : "\(int!)")
}
public static func value(_ double: Double?) -> Self {
value(double == nil ? "" : "\(double!)")
}
public static func value(_ uuid: UUID?) -> Self {
value(uuid?.uuidString ?? "")
}
}
extension HTMLAttribute where Tag == HTMLTag.button {
public static func showModal(id: String) -> Self {
.on(.click, "\(id).showModal()")
}
}
extension HTML where Tag: HTMLTrait.Attributes.Global {
public func badge() -> _AttributedElement<Self> {
attributes(.class("badge badge-lg badge-outline"))
}
public func hidden(when shouldHide: Bool) -> _AttributedElement<Self> {
attributes(.class("hidden"), when: shouldHide)
}
public func bold(when shouldBeBold: Bool = true) -> _AttributedElement<Self> {
attributes(.class("font-bold"), when: shouldBeBold)
}
}