SectionHeader.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // SectionHeader.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 SectionHeader: View {
  10. var label: String
  11. var style: Style
  12. public enum Style {
  13. case regular
  14. case tight
  15. }
  16. public init(label: String, style: Style = .default) {
  17. self.label = label
  18. self.style = style
  19. }
  20. public var body: some View {
  21. // iOS 14 puts section headers in all-caps by default. This un-does that.
  22. content.textCase(nil)
  23. }
  24. @ViewBuilder private var content: some View {
  25. Text(label)
  26. .font(.headline)
  27. .foregroundColor(.primary)
  28. .padding(.leading, style == .tight ? -10 : 0)
  29. }
  30. }
  31. fileprivate struct HorizontalSizeClassOverrideHelper: HorizontalSizeClassOverride {}
  32. public extension SectionHeader.Style {
  33. static let `default`: SectionHeader.Style = {
  34. return .regular
  35. }()
  36. }
  37. struct SectionHeader_Previews: PreviewProvider {
  38. static var previews: some View {
  39. SectionHeader(label: "Header Label")
  40. }
  41. }