49 lines
1.1 KiB
Swift
49 lines
1.1 KiB
Swift
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
|
|
}
|
|
}
|