Feat: Working on pressure estimations feature
This commit is contained in:
142
Sources/Styleguide/FlaggedView.swift
Normal file
142
Sources/Styleguide/FlaggedView.swift
Normal file
@@ -0,0 +1,142 @@
|
||||
import SharedModels
|
||||
import SwiftUI
|
||||
|
||||
public struct FlaggedView<Label: View>: View {
|
||||
|
||||
@Environment(\.flaggedViewStyle) private var flaggedViewStyle
|
||||
|
||||
let label: () -> Label
|
||||
let flagged: Flagged
|
||||
|
||||
public init(
|
||||
flagged: Flagged,
|
||||
@ViewBuilder label: @escaping () -> Label
|
||||
) {
|
||||
self.label = label
|
||||
self.flagged = flagged
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
flaggedViewStyle.makeBody(
|
||||
configuration: .init(flagged: flagged, label: .init(label()))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension FlaggedView where Label == Text {
|
||||
public init(_ title: LocalizedStringKey, flagged: Flagged) {
|
||||
self.init(flagged: flagged) { Text(title) }
|
||||
}
|
||||
}
|
||||
|
||||
extension FlaggedView where Label == EmptyView {
|
||||
public init(flagged: Flagged) {
|
||||
self.init(flagged: flagged) { EmptyView() }
|
||||
}
|
||||
}
|
||||
|
||||
//public struct FlaggedView: View {
|
||||
//
|
||||
// public let style: Style?
|
||||
// public let title: String
|
||||
// public let flagged: Flagged
|
||||
// public let fractionLength: Int
|
||||
//
|
||||
// public init(
|
||||
// style: Style? = nil,
|
||||
// title: String,
|
||||
// flagged: Flagged,
|
||||
// fractionLength: Int = 3
|
||||
// ) {
|
||||
// self.style = style
|
||||
// self.title = title
|
||||
// self.flagged = flagged
|
||||
// self.fractionLength = fractionLength
|
||||
// }
|
||||
//
|
||||
// public init(
|
||||
// _ title: String,
|
||||
// flagged: Flagged,
|
||||
// style: Style? = nil,
|
||||
// fractionLength: Int = 3
|
||||
// ) {
|
||||
// self.style = style
|
||||
// self.title = title
|
||||
// self.flagged = flagged
|
||||
// self.fractionLength = fractionLength
|
||||
// }
|
||||
//
|
||||
// @ViewBuilder
|
||||
// private var messageView: some View {
|
||||
// if let message = flagged.message {
|
||||
// HStack {
|
||||
// Text(flagged.projectedValue.key.title)
|
||||
// .bold()
|
||||
// .foregroundStyle(flagged.projectedValue.key.flagColor)
|
||||
//
|
||||
// Text(message)
|
||||
// .foregroundStyle(Color.secondary)
|
||||
// }
|
||||
// .font(.caption)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public var body: some View {
|
||||
// switch style {
|
||||
// case .none:
|
||||
// VStack(alignment: .leading, spacing: 8) {
|
||||
// HStack {
|
||||
// Text(title)
|
||||
// .foregroundStyle(Color.secondary)
|
||||
// Spacer()
|
||||
// Text(
|
||||
// flagged.wrappedValue,
|
||||
// format: .number.precision(.fractionLength(fractionLength))
|
||||
// )
|
||||
// Image(systemName: "flag.fill")
|
||||
// .foregroundStyle(flagged.projectedValue.key.flagColor)
|
||||
// }
|
||||
// messageView
|
||||
// }
|
||||
// case .some(.gridRow):
|
||||
// GridRow {
|
||||
// VStack(alignment: .leading, spacing: 8) {
|
||||
// Text(title)
|
||||
// .foregroundStyle(Color.secondary)
|
||||
// messageView
|
||||
// }
|
||||
//
|
||||
// Spacer()
|
||||
//
|
||||
// Text(flagged.wrappedValue, format: .number.precision(.fractionLength(fractionLength)))
|
||||
// .gridCellAnchor(.trailing)
|
||||
//
|
||||
// Image(systemName: "flag.fill")
|
||||
// .foregroundStyle(flagged.flagColor)
|
||||
// .gridCellAnchor(.trailing)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public enum Style {
|
||||
// case gridRow
|
||||
// }
|
||||
//
|
||||
// public static func gridRow(_ title: String, flagged: Flagged) -> Self {
|
||||
// .init(style: .gridRow, title: title, flagged: flagged)
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//#Preview {
|
||||
// List {
|
||||
// Grid(horizontalSpacing: 20) {
|
||||
// FlaggedView(style: .gridRow, title: "Test", flagged: .error(message: "Error message"))
|
||||
// FlaggedView(style: .gridRow, title: "Test", flagged: .init(wrappedValue: 0.5, .result(.good("Good message"))))
|
||||
// }
|
||||
//
|
||||
// FlaggedView(style: nil, title: "Test", flagged: .error(message: "Error message"))
|
||||
// FlaggedView(style: nil, title: "Test", flagged: .init(wrappedValue: 0.5, .result(.good("Good message"))))
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user