field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | LICENSE

SectionWideButton.swift (1282B)


      1 import SwiftUI
      2 
      3 public struct SectionWideButton: View {
      4     private let title: String
      5     private let enabled: Bool
      6     private let isProminent: Bool
      7     private let action: () -> Void
      8 
      9     public init(
     10         _ title: String,
     11         enabled: Bool = true,
     12         isProminent: Bool = false,
     13         action: @escaping () -> Void
     14     ) {
     15         self.title = title
     16         self.enabled = enabled
     17         self.isProminent = isProminent
     18         self.action = action
     19     }
     20 
     21     public var body: some View {
     22         Button(action: action) {
     23             Text(title)
     24                 .font(.headline)
     25                 .frame(maxWidth: .infinity)
     26                 .padding(.vertical, 4)
     27         }
     28         .buttonStyle(.plain)
     29         .foregroundStyle(foregroundStyle)
     30         .disabled(!enabled)
     31         .listRowBackground(backgroundStyle)
     32         .animation(.easeInOut(duration: 0.15), value: isProminent)
     33         .accessibilityAddTraits(.isButton)
     34     }
     35 
     36     private var backgroundStyle: Color {
     37         guard enabled else { return Color.secondary.opacity(0.25) }
     38         return isProminent ? .accentColor : Color.secondary.opacity(0.15)
     39     }
     40 
     41     private var foregroundStyle: Color {
     42         guard enabled else { return .secondary }
     43         return isProminent ? .white : .primary
     44     }
     45 }