Files
worldcup/components/team-flag.tsx
T
valknar b942ae7c8f fix: show placeholder badge for defunct nations with no flag-icons code
Soviet Union (su), Yugoslavia (yu), East Germany, Germany DR, FR Yugoslavia,
and Czechoslovakia have no valid entry in flag-icons. Map them to null in
TEAM_ISO so getIso() returns null, and render a muted initials badge in
TeamFlag instead of a broken/empty sprite. Also drop the buggy 2-char
substring fallback that generated random valid codes for unknown teams.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 19:21:38 +02:00

55 lines
1.4 KiB
TypeScript

import { getIso } from '@/lib/iso-codes'
interface Props {
name: string
iso2?: string | null
size?: 'sm' | 'md' | 'lg' | 'xl'
className?: string
}
const sizes = { sm: 'text-lg', md: 'text-2xl', lg: 'text-4xl', xl: 'text-[60px]' }
const placeholderSize = {
sm: { width: '1.35em', height: '1em', fontSize: '0.38em' },
md: { width: '1.35em', height: '1em', fontSize: '0.38em' },
lg: { width: '1.35em', height: '1em', fontSize: '0.38em' },
xl: { width: '1.35em', height: '1em', fontSize: '0.38em' },
}
export function TeamFlag({ name, iso2, size = 'md', className = '' }: Props) {
const code = iso2 !== undefined ? iso2 : getIso(name)
if (!code) {
const abbr = name
.split(/\s+/)
.map(w => w[0])
.join('')
.slice(0, 3)
.toUpperCase()
return (
<span
className={`rounded-sm inline-flex items-center justify-center flex-shrink-0 ${sizes[size]} ${className}`}
style={{
...placeholderSize[size],
background: 'rgba(42,92,53,0.35)',
color: '#6abf7a',
fontFamily: 'Space Grotesk, sans-serif',
fontWeight: 700,
letterSpacing: '0.04em',
lineHeight: 1,
}}
title={name}
>
{abbr}
</span>
)
}
return (
<span
className={`fi fi-${code} rounded-sm inline-block flex-shrink-0 ${sizes[size]} ${className}`}
title={name}
/>
)
}