AddCarbsRootView.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import SwiftUI
  2. extension AddCarbs {
  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 = 0
  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.carbs, formatter: formatter, autofocus: true, cleanInput: true)
  18. Text("grams").foregroundColor(.secondary)
  19. }
  20. DatePicker("Date", selection: $viewModel.date)
  21. }
  22. Section {
  23. Button { viewModel.add() }
  24. label: { Text("Add") }
  25. }
  26. }
  27. .navigationTitle("Add Carbs")
  28. .navigationBarTitleDisplayMode(.automatic)
  29. .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
  30. }
  31. }
  32. }