This commit is contained in:
30 files changed
+3776
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { RotateCcw, Trophy, X } from 'lucide-react';
|
||||
import type { GameResult } from '../types';
|
||||
|
||||
interface ResultModalProps {
|
||||
result: GameResult;
|
||||
onRestart: () => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const CONFETTI = Array.from({ length: 26 }, (_, i) => ({
|
||||
left: `${(i * 37) % 100}%`,
|
||||
delay: `${(i % 8) * 0.09}s`,
|
||||
color: ['#f0b84b', '#e86d4d', '#6878e8', '#38a880'][i % 4],
|
||||
}));
|
||||
|
||||
export function ResultModal({ result, onRestart, onClose }: ResultModalProps) {
|
||||
const answer = result.heavyBags.length
|
||||
? result.heavyBags.map((index) => `#${String(index + 1).padStart(2, '0')}`).join(', ')
|
||||
: 'none of them';
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop" role="presentation">
|
||||
{result.won && <div className="confetti" aria-hidden="true">{CONFETTI.map((piece, i) => <i key={i} style={{ '--x': piece.left, '--delay': piece.delay, '--confetti': piece.color } as React.CSSProperties} />)}</div>}
|
||||
<section className={`result-modal ${result.won ? 'won' : 'lost'}`} role="dialog" aria-modal="true" aria-labelledby="result-title">
|
||||
<button className="modal-close" type="button" onClick={onClose} aria-label="Close result"><X size={20} /></button>
|
||||
<div className="result-emblem">{result.won ? <Trophy size={34} /> : <span>!</span>}</div>
|
||||
<span className="eyebrow">{result.won ? 'CASE CLOSED' : 'MYSTERY REMAINS'}</span>
|
||||
<h2 id="result-title">{result.won ? 'Brilliant deduction.' : 'Not quite this time.'}</h2>
|
||||
<p>The heavy {result.heavyBags.length === 1 ? 'bag was' : 'bags were'} <strong>{answer}</strong>.</p>
|
||||
{result.won ? (
|
||||
<div className="score-award"><span>SCORE EARNED</span><strong>+{result.scoreEarned.toLocaleString()}</strong></div>
|
||||
) : (
|
||||
<p className="result-tip">Compare the extra grams with the coin counts you assigned to each bag.</p>
|
||||
)}
|
||||
<button className="primary-action" type="button" onClick={onRestart}><RotateCcw size={17} /> PLAY AGAIN</button>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user