Feat: Adds flagged equipment measurement view and style
This commit is contained in:
@@ -71,7 +71,6 @@ public struct DefaultFlagViewStyle: FlaggedViewStyle {
|
||||
flaggedMessageView(flagged: configuration.flagged)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct FlagAndMessageOnlyStyle: FlaggedViewStyle {
|
||||
@@ -106,6 +105,33 @@ extension FlaggedViewStyle where Self == FlagAndMessageOnlyStyle {
|
||||
}
|
||||
}
|
||||
|
||||
public struct FlaggedGridRowStyle: FlaggedViewStyle {
|
||||
|
||||
let fractionLength: Int
|
||||
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
GridRow {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
configuration.label
|
||||
.foregroundStyle(Color.secondary)
|
||||
flaggedMessageView(flagged: configuration.flagged)
|
||||
}
|
||||
Text(
|
||||
configuration.flagged.wrappedValue,
|
||||
format: .number.precision(.fractionLength(fractionLength))
|
||||
)
|
||||
configuration.flagged.flagImage
|
||||
.gridCellAnchor(.trailing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension FlaggedViewStyle where Self == FlaggedGridRowStyle {
|
||||
public static func gridRow(fractionLength: Int = 2) -> Self {
|
||||
.init(fractionLength: fractionLength)
|
||||
}
|
||||
}
|
||||
|
||||
private struct FlaggedViewStyleKey: EnvironmentKey {
|
||||
static let defaultValue = AnyFlaggedViewStyle(style: DefaultFlagViewStyle())
|
||||
}
|
||||
@@ -123,10 +149,9 @@ extension FlaggedViewStyle where Self == DefaultFlagViewStyle {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate extension Flagged.CheckResult.Key {
|
||||
|
||||
extension Flagged.CheckResult.Key {
|
||||
|
||||
public var flagColor: Color {
|
||||
var flagColor: Color {
|
||||
switch self {
|
||||
case .good:
|
||||
return .green
|
||||
@@ -140,7 +165,7 @@ extension Flagged.CheckResult.Key {
|
||||
|
||||
|
||||
extension Flagged {
|
||||
public var flagColor: Color { projectedValue.key.flagColor }
|
||||
var flagColor: Color { projectedValue.key.flagColor }
|
||||
|
||||
public var flagImage: some View {
|
||||
Image(systemName: "flag.fill")
|
||||
@@ -151,7 +176,7 @@ extension Flagged {
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func flaggedMessageView(flagged: Flagged) -> some View {
|
||||
fileprivate func flaggedMessageView(flagged: Flagged) -> some View {
|
||||
if let message = flagged.message {
|
||||
HStack {
|
||||
Text(flagged.projectedValue.key.title)
|
||||
@@ -171,6 +196,6 @@ extension View {
|
||||
public func flaggedViewStyle<S: FlaggedViewStyle>(
|
||||
_ style: S
|
||||
) -> some View {
|
||||
environment(\.flaggedViewStyle, AnyFlaggedViewStyle(style: style))
|
||||
flaggedViewStyle(AnyFlaggedViewStyle(style: style))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user