feat: Adds section and section style, needs tests

This commit is contained in:
2024-12-04 17:03:28 -05:00
parent 2a9b350b26
commit b0b218e047
9 changed files with 89 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
import Rainbow
public struct ExampleSection<Header: TextNode, Label: TextNode>: TextNode {
public typealias Example = (label: String, example: String)
@usableFromInline
let examples: [Example]
@usableFromInline
let header: Header
@usableFromInline
let label: Label
@inlinable
public init(
examples: [Example],
@TextBuilder header: () -> Header,
@TextBuilder label: () -> Label
) {
self.examples = examples
self.header = header()
self.label = label()
}
@inlinable
public var body: some TextNode {
style(.default())
}
}
public extension ExampleSection where Header == String, Label == String {
@inlinable
init(
header: String = "Examples:".yellow.bold,
label: String = "Some common usage examples.",
examples: [Example]
) {
self.init(examples: examples) { header } label: { label }
}
@inlinable
init(
header: String = "Examples:".yellow.bold,
label: String = "Some common usage examples.",
examples: Example...
) {
self.init(header: header, label: label, examples: examples)
}
}