// // DayOfWeekPicker.swift // Severed // import SwiftUI /// Seven circular day toggles (S M T W T F S) using system colors, meant to /// sit inside a Form/List row. The day-set summary is shown by the enclosing /// section header. struct DayOfWeekPicker: View { @Binding var days: Set var body: some View { HStack(spacing: 8) { ForEach(Weekday.displayOrder, id: \.self) { day in dayToggle(day) } } .padding(.vertical, 4) } private func dayToggle(_ day: Weekday) -> some View { let isOn = days.contains(day) return Button { if isOn { days.remove(day) } else { days.insert(day) } } label: { Text(day.shortLabel) .font(.subheadline.weight(.semibold)) .foregroundStyle(isOn ? Color.white : .secondary) .frame(maxWidth: .infinity) .aspectRatio(1, contentMode: .fit) .background( isOn ? AnyShapeStyle(.tint) : AnyShapeStyle(Color(.tertiarySystemFill)), in: Circle() ) } .buttonStyle(.borderless) .accessibilityIdentifier("dayToggle-\(day.rawValue)") .accessibilityLabel(day.abbreviation) .accessibilityAddTraits(isOn ? .isSelected : []) } } #Preview { @Previewable @State var days = Weekday.weekdays Form { Section { DayOfWeekPicker(days: $days) } header: { HStack { Text("On these days").textCase(nil) Spacer() Text(days.summary).textCase(nil) } } } }