feat: Adds WarningBox to Styleguide
This commit is contained in:
63
Sources/Styleguide/WarningBox.swift
Normal file
63
Sources/Styleguide/WarningBox.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
import Elementary
|
||||
|
||||
/// A container for displaying warnings.
|
||||
public struct WarningBox<Header: HTML>: HTML, Sendable {
|
||||
|
||||
let warnings: [String]
|
||||
let header: @Sendable ([String]) -> Header
|
||||
|
||||
public init(
|
||||
warnings: [String],
|
||||
@HTMLBuilder header: @Sendable @escaping ([String]) -> Header
|
||||
) {
|
||||
self.warnings = warnings
|
||||
self.header = header
|
||||
}
|
||||
|
||||
public init(
|
||||
_ warnings: String...,
|
||||
@HTMLBuilder header: @Sendable @escaping ([String]) -> Header
|
||||
) {
|
||||
self.warnings = warnings
|
||||
self.header = header
|
||||
}
|
||||
|
||||
public var content: some HTML<HTMLTag.div> {
|
||||
div(.id("warnings")) {
|
||||
header(warnings)
|
||||
ul(.class("list-disc mx-10")) {
|
||||
for warning in warnings {
|
||||
li { warning }
|
||||
}
|
||||
}
|
||||
}
|
||||
.attributes(
|
||||
.class("""
|
||||
mt-6 p-4 rounded-lg shadow-lg
|
||||
text-amber-500
|
||||
bg-amber-100 dark:bg-amber-200
|
||||
border border-amber-500
|
||||
"""),
|
||||
when: warnings.count > 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public extension WarningBox where Header == HTMLElement<HTMLTag.span, HTMLText> {
|
||||
init(
|
||||
warnings: [String]
|
||||
) {
|
||||
self.init(
|
||||
warnings: warnings,
|
||||
header: { warnings in
|
||||
span(.class("font-semibold mb-4 border-b")) { "Warning\(warnings.count > 1 ? "s:" : ":")" }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
init(
|
||||
_ warnings: String...
|
||||
) {
|
||||
self.init(warnings: warnings)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user