LabeledValueView.swift 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // LabeledValueView.swift
  3. // LoopKitUI
  4. //
  5. // Created by Nathaniel Hamming on 2020-02-20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct LabeledValueView: View {
  10. public static let NoValueString: String = "–"
  11. var label: String
  12. var value: String?
  13. var highlightValue: Bool
  14. public init(label: String, value: String?, highlightValue: Bool = false) {
  15. self.label = label
  16. self.value = value
  17. self.highlightValue = highlightValue
  18. }
  19. public var body: some View {
  20. HStack {
  21. Text(label)
  22. .foregroundColor(.primary)
  23. Spacer()
  24. Text(value ?? LabeledValueView.NoValueString)
  25. .foregroundColor(highlightValue ? .accentColor : .secondary)
  26. }
  27. }
  28. }
  29. struct LabeledValueView_Previews: PreviewProvider {
  30. static var previews: some View {
  31. LabeledValueView(label: "Glucose", value: "80 mg/dL", highlightValue: true)
  32. }
  33. }