CalendarDayCell.swift (1799B)
1 import SwiftUI 2 3 struct CalendarDayCell: View { 4 let date: Date 5 let dayNumber: Int 6 let isEnabled: Bool 7 let isToday: Bool 8 let isSelected: Bool 9 let onTap: () -> Void 10 11 var body: some View { 12 Button(action: onTap) { 13 Text("\(dayNumber)") 14 .font(.body) 15 .fontWeight(isToday || isSelected ? .bold : .regular) 16 .frame(maxWidth: .infinity, minHeight: 44) 17 .foregroundStyle(foregroundColor) 18 .background { 19 if isSelected { 20 Circle() 21 .fill(Color.accentColor) 22 .frame(width: 36, height: 36) 23 } else if isToday { 24 Circle() 25 .fill(Color.accentColor.opacity(0.15)) 26 .frame(width: 36, height: 36) 27 } 28 } 29 } 30 .buttonStyle(.plain) 31 .disabled(!isEnabled) 32 .accessibilityLabel(accessibilityLabel) 33 .accessibilityValue(accessibilityValue) 34 .accessibilityHint(isEnabled ? "Selects this puzzle date" : "") 35 .accessibilityAddTraits(isSelected ? .isSelected : []) 36 } 37 38 private var foregroundColor: Color { 39 if isSelected { return .white } 40 return isEnabled ? .primary : .secondary.opacity(0.4) 41 } 42 43 private var accessibilityLabel: String { 44 date.formatted(.dateTime.weekday(.wide).month(.wide).day().year()) 45 } 46 47 private var accessibilityValue: String { 48 var parts: [String] = [] 49 if isToday { parts.append("Today") } 50 if isSelected { parts.append("Selected") } 51 if !isEnabled { parts.append("Unavailable") } 52 return parts.joined(separator: ", ") 53 } 54 }