|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useMemo } from 'react'; |
1 | 4 | import { useGame } from '@/hooks/game'; |
2 | 5 | import { CardFooter } from './card-footer'; |
3 | 6 | import { CardHeader } from './card-header'; |
4 | 7 |
|
5 | 8 | export function BlackCard() { |
6 | 9 | const { currentBlackCard } = useGame(); |
7 | | - // TODO: |
8 | | - // - [ ] Handle pick (Fill in the blanks) |
9 | | - // - [ ] Blank fill style |
| 10 | + // Determine text size class based on character count |
| 11 | + const textSizeClass = useMemo(() => { |
| 12 | + const text = currentBlackCard?.text || ''; |
| 13 | + const charCount = text.length; |
| 14 | + |
| 15 | + // Text size thresholds based on character count |
| 16 | + if (charCount <= 74) return 'text-4xl'; // Up to 74 chars |
| 17 | + if (charCount <= 100) return 'text-3xl'; // Up to 100 chars |
| 18 | + if (charCount <= 150) return 'text-2xl'; // Up to 150 chars |
| 19 | + if (charCount <= 200) return 'text-xl'; // Up to 200 chars |
| 20 | + return 'text-lg'; // More than 200 chars |
| 21 | + }, [currentBlackCard?.text]); |
| 22 | + |
| 23 | + // Process text to replace "___" with styled lines |
| 24 | + const processedContent = useMemo(() => { |
| 25 | + const text = currentBlackCard?.text || ''; |
| 26 | + |
| 27 | + // If no fill-in-the-gap markers, return the text as is |
| 28 | + if (!text.includes('___')) return text; |
| 29 | + |
| 30 | + // Split by the fill-in-the-gap marker |
| 31 | + const segments = text.split('___'); |
| 32 | + |
| 33 | + // Map through segments and join with styled lines |
| 34 | + return segments.map((segment, index) => { |
| 35 | + // Last segment doesn't need a line after it |
| 36 | + if (index === segments.length - 1) { |
| 37 | + // biome-ignore lint/suspicious/noArrayIndexKey: <explanation> |
| 38 | + return <span key={index}>{segment}</span>; |
| 39 | + } |
| 40 | + |
| 41 | + // Add a line after each segment (except the last) |
| 42 | + return ( |
| 43 | + // biome-ignore lint/suspicious/noArrayIndexKey: <explanation> |
| 44 | + <span key={index}> |
| 45 | + {segment} |
| 46 | + <span className="mx-1 inline-block h-4 w-24 border-b-2 border-zinc-50 align-middle" /> |
| 47 | + </span> |
| 48 | + ); |
| 49 | + }); |
| 50 | + }, [currentBlackCard?.text]); |
10 | 51 |
|
11 | 52 | return ( |
12 | 53 | <div className="flex aspect-card h-[30rem] flex-col justify-between gap-5 rounded-2xl border border-zinc-950 bg-zinc-950 p-9 dark:border-zinc-50"> |
13 | 54 | <CardHeader packId={currentBlackCard?.packId || ''} variant="blackCard" /> |
14 | 55 |
|
15 | | - <div className="flex-1"> |
16 | | - <span className="text-4xl font-bold leading-snug text-zinc-50"> |
17 | | - {currentBlackCard?.text || ''} |
| 56 | + <div className="flex flex-1 items-center"> |
| 57 | + <span |
| 58 | + className={`${textSizeClass} font-bold leading-snug text-zinc-50`} |
| 59 | + > |
| 60 | + {processedContent} |
18 | 61 | </span> |
19 | 62 | </div> |
20 | 63 |
|
|
0 commit comments