@@ -6,22 +6,34 @@ interface CodeProps {
66}
77export default function Code ( { code, errors, userInput } : CodeProps ) {
88 return (
9- < pre className = "text-primary mb-4 overflow-auto" >
10- { code . split ( "" ) . map ( ( char , index ) => (
11- < span
12- key = { index }
13- className = { cn ( {
14- "text-red-500 opacity-100" : errors . includes ( index ) ,
15- "bg-yellow-200 opacity-80 text-black" : userInput . length === index ,
16- "opacity-100" :
17- userInput . length !== index && userInput [ index ] === char ,
18- "opacity-50" :
19- userInput . length !== index && userInput [ index ] !== char ,
20- } ) }
21- >
22- { char }
9+ < >
10+ < pre className = "text-primary mb-4 overflow-auto" >
11+ { code . split ( "" ) . map ( ( char , index ) => (
12+ < span
13+ key = { index }
14+ className = { cn ( "border" , {
15+ "text-red-500 opacity-100" :
16+ code [ index ] !== " " && errors . includes ( index ) ,
17+ "border-red-500 opacity-100" :
18+ code [ index ] === " " && errors . includes ( index ) ,
19+ "bg-yellow-200 opacity-80 text-black" : userInput . length === index ,
20+ "opacity-100" :
21+ userInput . length !== index && userInput [ index ] === char ,
22+ "opacity-50" :
23+ ! errors . includes ( index ) &&
24+ userInput . length !== index &&
25+ userInput [ index ] !== char ,
26+ } ) }
27+ >
28+ { char === "\n" ? "⏎\n" : char }
29+ </ span >
30+ ) ) }
31+ </ pre >
32+ { errors . length > 0 && (
33+ < span className = "text-red-500" >
34+ You must fix all errors before you can finish the race!
2335 </ span >
24- ) ) }
25- </ pre >
36+ ) }
37+ </ >
2638 ) ;
2739}
0 commit comments