feat: Adds styleguide, working on result view container.
This commit is contained in:
54
Sources/Styleguide/LabeledContent.swift
Normal file
54
Sources/Styleguide/LabeledContent.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
import Elementary
|
||||
|
||||
public struct LabeledContent<Label: HTML, Body: HTML>: HTML {
|
||||
|
||||
let body: Body
|
||||
let label: Label
|
||||
|
||||
public init(
|
||||
@HTMLBuilder body: () -> Body,
|
||||
@HTMLBuilder label: () -> Label
|
||||
) {
|
||||
self.body = body()
|
||||
self.label = label()
|
||||
}
|
||||
|
||||
public var content: some HTML<HTMLTag.div> {
|
||||
div {
|
||||
label
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension LabeledContent: Sendable where Label: Sendable, Body: Sendable {}
|
||||
|
||||
// MARK: - Forms
|
||||
|
||||
public extension LabeledContent where Label == InputLabel<HTMLText>, Body == Input {
|
||||
|
||||
init(
|
||||
label: String,
|
||||
input: () -> Body
|
||||
) {
|
||||
self.init {
|
||||
input()
|
||||
} label: {
|
||||
InputLabel(for: input().id) { HTMLText(label) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension LabeledContent where Label == InputLabel<HTMLText>, Body == _AttributedElement<Input> {
|
||||
|
||||
init(
|
||||
label: String,
|
||||
input: () -> Body
|
||||
) {
|
||||
self.init {
|
||||
input()
|
||||
} label: {
|
||||
InputLabel(for: input().content.id) { HTMLText(label) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user