AddAlarmSheet.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // LoopFollow
  2. // AddAlarmSheet.swift
  3. // Created by Jonas Björkert.
  4. import SwiftUI
  5. struct AddAlarmSheet: View {
  6. let onSelect: (AlarmType) -> Void
  7. @Environment(\.dismiss) private var dismiss
  8. private let columns = [
  9. GridItem(.adaptive(minimum: 110), spacing: 16),
  10. ]
  11. var body: some View {
  12. NavigationStack {
  13. ScrollView {
  14. LazyVGrid(columns: columns, spacing: 16) {
  15. ForEach(AlarmType.Group.allCases, id: \.self) { group in
  16. if AlarmType.allCases.contains(where: { $0.group == group }) {
  17. Section(header: Text(group.rawValue)
  18. .font(.headline)
  19. .frame(maxWidth: .infinity, alignment: .leading)
  20. .padding(.horizontal, 4)
  21. ) {
  22. ForEach(AlarmType.allCases.filter { $0.group == group }, id: \.self) { type in
  23. AlarmTile(type: type) {
  24. onSelect(type)
  25. }
  26. }
  27. }
  28. }
  29. }
  30. }
  31. .padding()
  32. }
  33. .navigationTitle("Add Alarm")
  34. .toolbar {
  35. ToolbarItem(placement: .cancellationAction) {
  36. Button("Cancel") { dismiss() }
  37. }
  38. }
  39. }
  40. .preferredColorScheme(Storage.shared.forceDarkMode.value ? .dark : nil)
  41. }
  42. }