11import classNames from 'classnames' ;
22
3- // 👨🏻 💻 1A - This component uses individual props for each map location. Can we refactor it to use slots instead?
3+ // 💻 1A - This component uses individual props for each map location. Can we refactor it to use slots instead?
44interface IPokemonMap {
55 className ?: string ;
6-
6+
77 // North area props
88 showNorthArea ?: boolean ;
99 northAreaName ?: string ;
1010 northAreaIcon ?: string ;
1111 northAreaColor ?: string ;
12-
13- // South area props
12+
13+ // South area props
1414 showSouthArea ?: boolean ;
1515 southAreaName ?: string ;
1616 southAreaIcon ?: string ;
1717 southAreaColor ?: string ;
18-
18+
1919 // East area props
2020 showEastArea ?: boolean ;
2121 eastAreaName ?: string ;
2222 eastAreaIcon ?: string ;
2323 eastAreaColor ?: string ;
24-
24+
2525 // West area props
2626 showWestArea ?: boolean ;
2727 westAreaName ?: string ;
2828 westAreaIcon ?: string ;
2929 westAreaColor ?: string ;
30-
30+
3131 // Center area props
3232 showCenterArea ?: boolean ;
3333 centerAreaName ?: string ;
3434 centerAreaIcon ?: string ;
3535 centerAreaColor ?: string ;
3636}
3737
38- const mapContainerClasses = 'grid grid-cols-3 grid-rows-3 gap-2 w-80 h-80 p-4 bg-green-100 rounded-lg border-2 border-green-300' ;
39- const areaClasses = 'flex flex-col items-center justify-center p-3 rounded-lg border-2 text-sm font-bold text-white shadow-md' ;
38+ const mapContainerClasses =
39+ 'grid grid-cols-3 grid-rows-3 gap-2 w-80 h-80 p-4 bg-green-100 rounded-lg border-2 border-green-300' ;
40+ const areaClasses =
41+ 'flex flex-col items-center justify-center p-3 rounded-lg border-2 text-sm font-bold text-white shadow-md' ;
4042
41- // 👨🏻 💻 1B - Look at all these props and conditional logic! This is hard to maintain.
42- // 👨🏻 💻 1C - Refactor this to use northSlot, southSlot, eastSlot, westSlot, centerSlot instead
43+ // 💻 1B - Look at all these props and conditional logic! This is hard to maintain.
44+ // 💻 1C - Refactor this to use northSlot, southSlot, eastSlot, westSlot, centerSlot instead
4345export const PokemonMap = ( {
4446 className,
4547 showNorthArea,
@@ -67,100 +69,133 @@ export const PokemonMap = ({
6769 < div className = { classNames ( mapContainerClasses , className ) } >
6870 { /* Empty top-left */ }
6971 < div > </ div >
70-
72+
7173 { /* North area */ }
72- < div className = { classNames ( areaClasses , northAreaColor || 'bg-gray-400' ) } >
74+ < div
75+ className = { classNames (
76+ areaClasses ,
77+ northAreaColor || 'bg-gray-400'
78+ ) }
79+ >
7380 { showNorthArea && (
7481 < >
7582 < span className = "text-2xl mb-1" > { northAreaIcon } </ span >
76- < span className = "text-xs text-center" > { northAreaName } </ span >
83+ < span className = "text-xs text-center" >
84+ { northAreaName }
85+ </ span >
7786 </ >
7887 ) }
7988 </ div >
80-
89+
8190 { /* Empty top-right */ }
8291 < div > </ div >
83-
92+
8493 { /* West area */ }
85- < div className = { classNames ( areaClasses , westAreaColor || 'bg-gray-400' ) } >
94+ < div
95+ className = { classNames (
96+ areaClasses ,
97+ westAreaColor || 'bg-gray-400'
98+ ) }
99+ >
86100 { showWestArea && (
87101 < >
88102 < span className = "text-2xl mb-1" > { westAreaIcon } </ span >
89- < span className = "text-xs text-center" > { westAreaName } </ span >
103+ < span className = "text-xs text-center" >
104+ { westAreaName }
105+ </ span >
90106 </ >
91107 ) }
92108 </ div >
93-
109+
94110 { /* Center area */ }
95- < div className = { classNames ( areaClasses , centerAreaColor || 'bg-gray-400' ) } >
111+ < div
112+ className = { classNames (
113+ areaClasses ,
114+ centerAreaColor || 'bg-gray-400'
115+ ) }
116+ >
96117 { showCenterArea && (
97118 < >
98119 < span className = "text-2xl mb-1" > { centerAreaIcon } </ span >
99- < span className = "text-xs text-center" > { centerAreaName } </ span >
120+ < span className = "text-xs text-center" >
121+ { centerAreaName }
122+ </ span >
100123 </ >
101124 ) }
102125 </ div >
103-
126+
104127 { /* East area */ }
105- < div className = { classNames ( areaClasses , eastAreaColor || 'bg-gray-400' ) } >
128+ < div
129+ className = { classNames (
130+ areaClasses ,
131+ eastAreaColor || 'bg-gray-400'
132+ ) }
133+ >
106134 { showEastArea && (
107135 < >
108136 < span className = "text-2xl mb-1" > { eastAreaIcon } </ span >
109- < span className = "text-xs text-center" > { eastAreaName } </ span >
137+ < span className = "text-xs text-center" >
138+ { eastAreaName }
139+ </ span >
110140 </ >
111141 ) }
112142 </ div >
113-
143+
114144 { /* Empty bottom-left */ }
115145 < div > </ div >
116-
146+
117147 { /* South area */ }
118- < div className = { classNames ( areaClasses , southAreaColor || 'bg-gray-400' ) } >
148+ < div
149+ className = { classNames (
150+ areaClasses ,
151+ southAreaColor || 'bg-gray-400'
152+ ) }
153+ >
119154 { showSouthArea && (
120155 < >
121156 < span className = "text-2xl mb-1" > { southAreaIcon } </ span >
122- < span className = "text-xs text-center" > { southAreaName } </ span >
157+ < span className = "text-xs text-center" >
158+ { southAreaName }
159+ </ span >
123160 </ >
124161 ) }
125162 </ div >
126-
163+
127164 { /* Empty bottom-right */ }
128165 < div > </ div >
129166 </ div >
130167 ) ;
131168} ;
132169
133- // 👨🏻 💻 1D - Look at how verbose these prop combinations are!
134- // 👨🏻 💻 1E - Refactor these to use slots: northSlot={<LocationCard />}, centerSlot={<TownCard />}, etc.
170+ // 💻 1D - Look at how verbose these prop combinations are!
171+ // 💻 1E - Refactor these to use slots: northSlot={<LocationCard />}, centerSlot={<TownCard />}, etc.
135172export const Exercise = ( ) => (
136173 < div className = "p-6 bg-blue-50 rounded-lg border-2 border-blue-200" >
137- < h2 className = "text-2xl font-bold mb-4 text-blue-800" > 🗺️ Pokemon World Map</ h2 >
138-
174+ < h2 className = "text-2xl font-bold mb-4 text-blue-800" >
175+ 🗺️ Pokemon World Map
176+ </ h2 >
177+
139178 < PokemonMap
140179 showNorthArea = { true }
141180 northAreaName = "Viridian Forest"
142181 northAreaIcon = "🌲"
143182 northAreaColor = "bg-green-600"
144-
145183 showSouthArea = { true }
146184 southAreaName = "Route 1"
147185 southAreaIcon = "🛤️"
148186 southAreaColor = "bg-yellow-600"
149-
150187 showEastArea = { true }
151188 eastAreaName = "Power Plant"
152189 eastAreaIcon = "⚡"
153190 eastAreaColor = "bg-yellow-500"
154-
155191 showWestArea = { true }
156192 westAreaName = "Mt. Silver"
157193 westAreaIcon = "🏔️"
158194 westAreaColor = "bg-gray-600"
159-
160195 showCenterArea = { true }
161196 centerAreaName = "Pallet Town"
162197 centerAreaIcon = "🏠"
163198 centerAreaColor = "bg-blue-600"
164199 />
165200 </ div >
166- ) ;
201+ ) ;
0 commit comments