DayByDay/DayCard.swift
101 lines · 3300 bytes
1 symbol in this file
1//
2// DayCard.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// A single large, colorful card representing one day of the week.
9/// Tapping the card plays a bounce animation and speaks the day name aloud,
10/// plus the child's day picture when there is one ("It's swim day!").
11struct DayCard: View {
12 let day: DayOfWeek
13 var isHighlighted = false
14 var picture: DayPictureKind? = nil
15
16 var body: some View {
17 TapCard(
18 color: day.color,
19 label: picture.map { "\(day.name), \($0.name)" } ?? day.name,
20 isHighlighted: isHighlighted
21 ) {
22 CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil)
23 } content: {
24 SymbolLabel(symbol: day.symbol, name: day.name)
25 } badge: {
26 if let picture {
27 Image(systemName: picture.symbol)
28 .font(.system(size: 30, weight: .bold))
29 .foregroundStyle(day.color)
30 .frame(width: 60, height: 60)
31 .background(Circle().fill(.white))
32 .padding(14)
33 .accessibilityHidden(true)
34 }
35 }
36 }
37}
38
39// MARK: - Day model
40
41nonisolated enum DayOfWeek: Int, CaseIterable, Identifiable {
42 case sunday, monday, tuesday, wednesday, thursday, friday, saturday
43
44 var id: Int { rawValue }
45
46 /// The day of the week for today's date.
47 static var current: DayOfWeek {
48 // Calendar weekday: 1 = Sunday, 7 = Saturday
49 let weekday = AppCalendar.current.component(.weekday, from: Date())
50 return DayOfWeek(rawValue: weekday - 1)!
51 }
52
53 var name: String {
54 switch self {
55 case .sunday: "Sunday"
56 case .monday: "Monday"
57 case .tuesday: "Tuesday"
58 case .wednesday: "Wednesday"
59 case .thursday: "Thursday"
60 case .friday: "Friday"
61 case .saturday: "Saturday"
62 }
63 }
64
65 /// A recognisable SF Symbol icon for each day so children who cannot read
66 /// still get a unique visual cue.
67 var symbol: String {
68 switch self {
69 case .sunday: "sun.max.fill"
70 case .monday: "moon.fill"
71 case .tuesday: "star.fill"
72 case .wednesday: "cloud.fill"
73 case .thursday: "bolt.fill"
74 case .friday: "heart.fill"
75 case .saturday: "sparkles"
76 }
77 }
78
79 /// A color per day, each at least 3:1 against the white icon and name.
80 var color: Color {
81 switch self {
82 case .sunday: Color(red: 0.80, green: 0.42, blue: 0.08) // orange
83 case .monday: Color(red: 0.25, green: 0.42, blue: 0.85) // blue
84 case .tuesday: Color(red: 0.84, green: 0.22, blue: 0.34) // red-pink
85 case .wednesday: Color(red: 0.18, green: 0.56, blue: 0.28) // green
86 case .thursday: Color(red: 0.55, green: 0.4, blue: 0.85) // purple
87 case .friday: Color(red: 0.66, green: 0.50, blue: 0.0) // mustard
88 case .saturday: Color(red: 0.0, green: 0.53, blue: 0.56) // teal
89 }
90 }
91}
92
93#Preview {
94 HStack(spacing: 24) {
95 DayCard(day: .wednesday, isHighlighted: true)
96 .frame(width: 200, height: 260)
97 DayCard(day: .thursday)
98 .frame(width: 200, height: 260)
99 }
100 .padding()
101}