47 lines
926 B
Swift
47 lines
926 B
Swift
public struct LabeledContent: NodeRepresentable {
|
|
|
|
@usableFromInline
|
|
let label: any NodeRepresentable
|
|
|
|
@usableFromInline
|
|
let content: any NodeRepresentable
|
|
|
|
@usableFromInline
|
|
let separator: any NodeRepresentable
|
|
|
|
@inlinable
|
|
public init(
|
|
separator: (any NodeRepresentable)? = nil,
|
|
@NodeBuilder label: () -> any NodeRepresentable,
|
|
@NodeBuilder content: () -> any NodeRepresentable
|
|
) {
|
|
self.separator = separator ?? "\n"
|
|
self.label = label()
|
|
self.content = content()
|
|
}
|
|
|
|
@inlinable
|
|
public func render() -> String {
|
|
Group(separator: separator) {
|
|
label
|
|
content
|
|
}.render()
|
|
}
|
|
}
|
|
|
|
public extension LabeledContent {
|
|
|
|
@inlinable
|
|
init(
|
|
_ label: String,
|
|
separator: (any NodeRepresentable)? = nil,
|
|
@NodeBuilder content: () -> any NodeRepresentable
|
|
) {
|
|
self.init(separator: separator) {
|
|
Text(label)
|
|
} content: {
|
|
content()
|
|
}
|
|
}
|
|
}
|