BolusRootView.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import SwiftUI
  2. extension Bolus {
  3. struct RootView: BaseView {
  4. @EnvironmentObject var viewModel: ViewModel<Provider>
  5. private var formatter: NumberFormatter {
  6. let formatter = NumberFormatter()
  7. formatter.numberStyle = .decimal
  8. formatter.maximumFractionDigits = 2
  9. return formatter
  10. }
  11. var body: some View {
  12. Form {
  13. Section {
  14. HStack {
  15. Text("Amount")
  16. Spacer()
  17. DecimalTextField("0", value: $viewModel.amount, formatter: formatter, autofocus: true, cleanInput: true)
  18. Text("U").foregroundColor(.secondary)
  19. }
  20. }
  21. Section {
  22. Button { viewModel.add() }
  23. label: { Text("Enact") }
  24. }
  25. }
  26. .navigationTitle("Enact Bolus")
  27. .navigationBarTitleDisplayMode(.automatic)
  28. .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
  29. }
  30. }
  31. }