feat: Adds more flagged view style options.
This commit is contained in:
28
Sources/FlaggedViews/FlaggedMessageLabel.swift
Normal file
28
Sources/FlaggedViews/FlaggedMessageLabel.swift
Normal file
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FlaggedStatusLabel(status: .warning)
|
||||
.flaggedStatusLabelStyle(.heavyTitle2)
|
||||
}
|
||||
@@ -26,7 +26,3 @@ extension FlaggedMessageView {
|
||||
self.init(message: flagged.message, status: flagged.status)
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// SwiftUIView()
|
||||
//}
|
||||
|
||||
29
Sources/FlaggedViews/FlaggedStatusLabel.swift
Normal file
29
Sources/FlaggedViews/FlaggedStatusLabel.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
import SharedModels
|
||||
import Styleguide
|
||||
import SwiftUI
|
||||
|
||||
/// Represents the status of a flagged value, which is stylable using the
|
||||
/// `.flaggedStatusLabelStyle` modifier on a view.
|
||||
///
|
||||
/// By default the status label is colored using the default status color.
|
||||
public struct FlaggedStatusLabel: View {
|
||||
@Environment(\.flaggedStatusLabelStyle) private var style
|
||||
let status: Flagged.CheckResult.Status
|
||||
|
||||
public init(status: Flagged.CheckResult.Status) {
|
||||
self.status = status
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
TextLabel(status.title)
|
||||
.textLabelStyle(
|
||||
.colored(status.flagColor)
|
||||
.combining(style)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
FlaggedStatusLabel(status: .warning)
|
||||
.flaggedStatusLabelStyle(.heavyTitle2)
|
||||
}
|
||||
24
Sources/FlaggedViews/Styles/FlaggedMessageLabelStyle.swift
Normal file
24
Sources/FlaggedViews/Styles/FlaggedMessageLabelStyle.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import Styleguide
|
||||
import SwiftUI
|
||||
|
||||
private struct FlaggedMessageLabelStyleKey: EnvironmentKey {
|
||||
static var defaultValue = 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<S: TextLabelStyle>(_ style: S) -> some View {
|
||||
flaggedMessageLabelStyle(AnyTextLabelStyle(style: style))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,16 +40,15 @@ public struct AnyFlaggedMessageViewStyle: FlaggedMessageViewStyle {
|
||||
|
||||
public struct DefaultFlaggedMessageViewStyle: FlaggedMessageViewStyle {
|
||||
|
||||
|
||||
|
||||
@ViewBuilder
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
if let message = configuration.message {
|
||||
if configuration.message != nil {
|
||||
HStack {
|
||||
Text(configuration.status.title)
|
||||
.bold()
|
||||
.foregroundStyle(configuration.status.flagColor)
|
||||
TextLabel(message)
|
||||
FlaggedStatusLabel(status: configuration.status)
|
||||
FlaggedMessageLabel(message: configuration.message)
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,14 +57,11 @@ public struct VerticalFlaggedMessageViewStyle: FlaggedMessageViewStyle {
|
||||
|
||||
@ViewBuilder
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
if let message = configuration.message {
|
||||
if configuration.message != nil {
|
||||
VStack(alignment: .leading) {
|
||||
Text(configuration.status.title)
|
||||
.bold()
|
||||
.foregroundStyle(configuration.status.flagColor)
|
||||
TextLabel(message)
|
||||
FlaggedStatusLabel(status: configuration.status)
|
||||
FlaggedMessageLabel(message: configuration.message)
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
Sources/FlaggedViews/Styles/FlaggedStatusLabelStyle.swift
Normal file
24
Sources/FlaggedViews/Styles/FlaggedStatusLabelStyle.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import SharedModels
|
||||
import Styleguide
|
||||
import SwiftUI
|
||||
|
||||
private struct FlaggedStatusLabelStyleKey: EnvironmentKey {
|
||||
static var defaultValue = AnyTextLabelStyle(style: .font(.caption, fontWeight: .bold))
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
public var flaggedStatusLabelStyle: AnyTextLabelStyle {
|
||||
get { self[FlaggedStatusLabelStyleKey.self] }
|
||||
set { self[FlaggedStatusLabelStyleKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
public func flaggedStatusLabelStyle(_ style: AnyTextLabelStyle) -> some View {
|
||||
environment(\.flaggedStatusLabelStyle, style)
|
||||
}
|
||||
|
||||
public func flaggedStatusLabelStyle<S: TextLabelStyle>(_ style: S) -> some View {
|
||||
flaggedStatusLabelStyle(AnyTextLabelStyle(style: style))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user