import SwiftUI /// A view that can be styled view the `.textLabelStyle` modifier, generally they will be /// simple `Text` views, however it will accept any content view and will apply the style to. /// /// Custom styles can be created by conforming to the ``TextLabelStyle`` protocol. /// public struct TextLabel: View { @Environment(\.textLabelStyle) private var textLabelStyle private let content: () -> Content public init(@ViewBuilder content: @escaping () -> Content) { self.content = content } public var body: some View { textLabelStyle.makeBody( configuration: TextLabelConfiguration( label: TextLabelConfiguration.Label(content: content()) ) ) } } extension TextLabel where Content == Text { public init(_ text: S) where S: StringProtocol { self.init { Text(text) } } } #Preview { VStack { TextLabel("Automatic") TextLabel("Secondary-Bold") .textLabelStyle(AnyTextLabelStyle.boldSecondary) TextLabel("Secondary") .textLabelStyle(.secondary) .padding(.bottom) Group { TextLabel("One") TextLabel("Two") TextLabel("Three") } .font(.title) .textLabelStyle(.boldSecondary) } }