AddTempTargetRootView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import SwiftUI
  2. extension AddTempTarget {
  3. struct RootView: BaseView {
  4. @EnvironmentObject var viewModel: ViewModel<Provider>
  5. private var formatter: NumberFormatter {
  6. let formatter = NumberFormatter()
  7. formatter.numberStyle = .decimal
  8. return formatter
  9. }
  10. var body: some View {
  11. Form {
  12. Section {
  13. HStack {
  14. Text("Bottom target")
  15. Spacer()
  16. DecimalTextField("0", value: $viewModel.low, formatter: formatter, autofocus: true, cleanInput: true)
  17. Text(viewModel.units.rawValue).foregroundColor(.secondary)
  18. }
  19. HStack {
  20. Text("Top target")
  21. Spacer()
  22. DecimalTextField("0", value: $viewModel.high, formatter: formatter, cleanInput: true)
  23. Text(viewModel.units.rawValue).foregroundColor(.secondary)
  24. }
  25. HStack {
  26. Text("Duration")
  27. Spacer()
  28. DecimalTextField("0", value: $viewModel.duration, formatter: formatter, cleanInput: true)
  29. Text("minutes").foregroundColor(.secondary)
  30. }
  31. DatePicker("Date", selection: $viewModel.date)
  32. }
  33. Section {
  34. Button { viewModel.add() }
  35. label: { Text("Continue") }
  36. }
  37. }
  38. .navigationTitle("Add Temp Target")
  39. .navigationBarTitleDisplayMode(.automatic)
  40. .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
  41. }
  42. }
  43. }