feat: Working on node builder
This commit is contained in:
48
Sources/CliDoc/Modifiers/LabelStyle.swift
Normal file
48
Sources/CliDoc/Modifiers/LabelStyle.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import Rainbow
|
||||
|
||||
public extension NodeRepresentable {
|
||||
|
||||
@inlinable
|
||||
func labelStyle(_ style: any NodeModifier) -> any NodeRepresentable {
|
||||
return modifier(LabelStyleModifier(style))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func labelStyle(_ color: NamedColor) -> any NodeRepresentable {
|
||||
return modifier(LabelStyleModifier(.color(color)))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func labelStyle(_ style: Style) -> any NodeRepresentable {
|
||||
return modifier(LabelStyleModifier(.style(style)))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func labelStyle(_ styles: Style...) -> any NodeRepresentable {
|
||||
return modifier(LabelStyleModifier(.style(styles)))
|
||||
}
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
struct LabelStyleModifier: NodeModifier {
|
||||
|
||||
@usableFromInline
|
||||
let modifier: any NodeModifier
|
||||
|
||||
@usableFromInline
|
||||
init(_ modifier: any NodeModifier) {
|
||||
self.modifier = modifier
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
func render(_ node: any NodeRepresentable) -> any NodeRepresentable {
|
||||
if let node = node as? LabeledContent {
|
||||
return LabeledContent(separator: node.separator) {
|
||||
node.label.modifier(modifier)
|
||||
} content: {
|
||||
node.content
|
||||
}
|
||||
}
|
||||
return node
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user