BodyPartCard.swift
89 lines · 2889 bytes
1 symbol in this file
1//
2// BodyPartCard.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// A single large, colorful card representing one body part.
9/// Tapping the card plays a bounce animation and speaks the body part name aloud.
10struct BodyPartCard: View {
11 let bodyPart: LearnBodyPart
12
13 var body: some View {
14 TapCard(color: bodyPart.color, label: bodyPart.name) {
15 SpeechSynthesizer.shared.speak(bodyPart.name)
16 } content: {
17 SymbolLabel(symbol: bodyPart.symbol, name: bodyPart.name)
18 }
19 }
20}
21
22// MARK: - Body part model
23
24nonisolated enum LearnBodyPart: Int, CaseIterable, Identifiable {
25 case head, eyes, ears, nose, mouth, hands, fingers, arms, legs, feet, heart, belly
26
27 var id: Int { rawValue }
28
29 var name: String {
30 switch self {
31 case .head: "Head"
32 case .eyes: "Eyes"
33 case .ears: "Ears"
34 case .nose: "Nose"
35 case .mouth: "Mouth"
36 case .hands: "Hands"
37 case .fingers: "Fingers"
38 case .arms: "Arms"
39 case .legs: "Legs"
40 case .feet: "Feet"
41 case .heart: "Heart"
42 case .belly: "Belly"
43 }
44 }
45
46 var symbol: String {
47 switch self {
48 case .head: "brain.head.profile"
49 case .eyes: "eye.fill"
50 case .ears: "ear.fill"
51 case .nose: "nose.fill"
52 case .mouth: "mouth.fill"
53 case .hands: "hand.raised.fill"
54 case .fingers: "hand.point.up.fill"
55 case .arms: "figure.arms.open"
56 case .legs: "figure.walk"
57 case .feet: "shoeprints.fill"
58 case .heart: "heart.fill"
59 case .belly: "circle.fill"
60 }
61 }
62
63 var color: Color {
64 switch self {
65 case .head: Color(red: 0.82, green: 0.46, blue: 0.27) // warm orange
66 case .eyes: Color(red: 0.26, green: 0.58, blue: 0.8) // blue
67 case .ears: Color(red: 0.6, green: 0.45, blue: 0.85) // purple
68 case .nose: Color(red: 0.88, green: 0.39, blue: 0.49) // rose
69 case .mouth: Color(red: 0.9, green: 0.3, blue: 0.35) // red
70 case .hands: Color(red: 0.71, green: 0.52, blue: 0.22) // golden
71 case .fingers: Color(red: 0.28, green: 0.61, blue: 0.41) // green
72 case .arms: Color(red: 0.21, green: 0.61, blue: 0.61) // teal
73 case .legs: Color(red: 0.5, green: 0.4, blue: 0.8) // indigo
74 case .feet: Color(red: 0.7, green: 0.5, blue: 0.3) // brown
75 case .heart: Color(red: 0.85, green: 0.3, blue: 0.45) // deep pink
76 case .belly: Color(red: 0.79, green: 0.47, blue: 0.32) // peach
77 }
78 }
79}
80
81#Preview {
82 HStack(spacing: 24) {
83 BodyPartCard(bodyPart: .head)
84 .frame(width: 200, height: 260)
85 BodyPartCard(bodyPart: .hands)
86 .frame(width: 200, height: 260)
87 }
88 .padding()
89}