feat: Adds stack separators, removes some unused nodes from cli-doc module
All checks were successful
CI / Run tests. (push) Successful in 52s
All checks were successful
CI / Run tests. (push) Successful in 52s
This commit is contained in:
@@ -4,21 +4,53 @@ public struct HStack: TextNode {
|
||||
@usableFromInline
|
||||
let content: [any TextNode]
|
||||
|
||||
@usableFromInline
|
||||
let separator: Separator.Horizontal
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
separator: Separator.Horizontal = .space(count: 1),
|
||||
@TextBuilder content: () -> any TextNode
|
||||
) {
|
||||
self.content = array(from: content())
|
||||
self.separator = separator
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
content.removingEmptys()
|
||||
.joined(separator: separator.render())
|
||||
style(.separator(.space()))
|
||||
}
|
||||
}
|
||||
|
||||
public extension HStack {
|
||||
|
||||
func style<S: HStackStyle>(_ style: S) -> some TextNode {
|
||||
style.render(content: .init(content: content))
|
||||
}
|
||||
|
||||
func separator(_ separator: Separator.Horizontal) -> some TextNode {
|
||||
style(.separator(separator))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Style
|
||||
|
||||
public protocol HStackStyle: TextModifier where Content == StackConfiguration {}
|
||||
|
||||
public extension HStackStyle where Self == HStackSeparatorStyle {
|
||||
|
||||
static func separator(_ separator: Separator.Horizontal) -> Self {
|
||||
HStackSeparatorStyle(separator: separator)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct HStackSeparatorStyle: HStackStyle {
|
||||
@usableFromInline
|
||||
let separator: Separator.Horizontal
|
||||
|
||||
@usableFromInline
|
||||
init(separator: Separator.Horizontal) {
|
||||
self.separator = separator
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render(content: StackConfiguration) -> some TextNode {
|
||||
AnySeparatableStackNode(content: content, separator: separator)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user