import SharedModels import Styleguide import SwiftUI /// Represents the message of a flagged value result, which is stylable using the /// `.flaggedMessageLabelStyle` modifier on a view. /// /// By default the status label is colored using the default status color. public struct FlaggedMessageLabel: View { @Environment(\.flaggedMessageLabelStyle) private var style let message: String? public init(message: String?) { self.message = message } public var body: some View { if let message { TextLabel(message) .textLabelStyle(style) } } } private struct FlaggedMessageLabelStyleKey: EnvironmentKey { static let defaultValue = MainActor.assumeIsolated { AnyTextLabelStyle(style: .font(.caption)) } } extension EnvironmentValues { var flaggedMessageLabelStyle: AnyTextLabelStyle { get { self[FlaggedMessageLabelStyleKey.self] } set { self[FlaggedMessageLabelStyleKey.self] = newValue } } } extension View { public func flaggedMessageLabelStyle(_ style: AnyTextLabelStyle) -> some View { environment(\.flaggedMessageLabelStyle, style) } public func flaggedMessageLabelStyle(_ style: S) -> some View { flaggedMessageLabelStyle(AnyTextLabelStyle(style: style)) } } #Preview { FlaggedStatusLabel(status: .warning) .flaggedStatusLabelStyle(.textLabel(.heavyTitle2)) }