DayByDay/SeasonCard.swift
79 lines · 2156 bytes
1 symbol in this file
1//
2// SeasonCard.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// A single large, colorful card representing one season.
9/// Tapping the card plays a bounce animation and speaks the season name aloud.
10struct SeasonCard: View {
11 let season: Season
12 var isHighlighted = false
13
14 var body: some View {
15 TapCard(color: season.color, label: season.name, isHighlighted: isHighlighted) {
16 SpeechSynthesizer.shared.speak(season.name)
17 } content: {
18 SymbolLabel(symbol: season.symbol, name: season.name)
19 }
20 }
21}
22
23// MARK: - Season model
24
25nonisolated enum Season: Int, CaseIterable, Identifiable {
26 case spring, summer, fall, winter
27
28 var id: Int { rawValue }
29
30 /// The season for today's date.
31 /// Spring: March–May, Summer: June–August,
32 /// Fall: September–November, Winter: December–February.
33 static var current: Season {
34 let month = AppCalendar.current.component(.month, from: Date())
35 switch month {
36 case 3...5: return .spring
37 case 6...8: return .summer
38 case 9...11: return .fall
39 default: return .winter
40 }
41 }
42
43 var name: String {
44 switch self {
45 case .spring: "Spring"
46 case .summer: "Summer"
47 case .fall: "Fall"
48 case .winter: "Winter"
49 }
50 }
51
52 var symbol: String {
53 switch self {
54 case .spring: "leaf.fill"
55 case .summer: "sun.max.fill"
56 case .fall: "wind"
57 case .winter: "snowflake"
58 }
59 }
60
61 var color: Color {
62 switch self {
63 case .spring: Color(red: 0.35, green: 0.61, blue: 0.38) // fresh green
64 case .summer: Color(red: 0.79, green: 0.47, blue: 0.12) // sunny orange
65 case .fall: Color(red: 0.84, green: 0.45, blue: 0.2) // autumn orange
66 case .winter: Color(red: 0.35, green: 0.56, blue: 0.82) // cool blue
67 }
68 }
69}
70
71#Preview {
72 HStack(spacing: 24) {
73 SeasonCard(season: .spring, isHighlighted: true)
74 .frame(width: 200, height: 260)
75 SeasonCard(season: .summer)
76 .frame(width: 200, height: 260)
77 }
78 .padding()
79}