ironie-nextjs/src/app/components/PlayerCard.tsx
2025-05-28 00:41:23 +02:00

82 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client'
import Image from 'next/image'
import { Player, Team } from '@/app/types/team'
export type CardWidth =
| 'sm' // max-w-sm (24rem)
| 'md' // max-w-md (28rem)
| 'lg' // max-w-lg (32rem)
| 'xl' // max-w-xl (36rem)
| '2xl' // max-w-2xl (42rem)
| 'full' // w-full
| 'auto' // keine Begrenzung
type Props = {
player: Player
team?: Team // aktuell nicht genutzt, aber falls du später z.B. TeamFarbe brauchst
align?: 'left' | 'right'
maxWidth?: CardWidth
}
export default function PlayerCard({
player,
team,
align = 'left',
maxWidth = 'sm',
}: Props) {
/* --- HilfsKlassen ----------------------------------------------------- */
const widthClasses: Record<CardWidth, string> = {
sm: 'max-w-sm',
md: 'max-w-md',
lg: 'max-w-lg',
xl: 'max-w-xl',
'2xl':'max-w-2xl',
full: 'w-full',
auto: '', // keine Begrenzung
}
// Linksbündig = Karte nach links schieben, Rechtsbündig = nach rechts
const alignClasses =
align === 'right'
? 'ml-auto'
: align === 'left'
? 'mr-auto'
: 'mx-auto'
// Für den FlexContainer innen:
// * links: Avatar Name (row)
// * rechts: Name Avatar (rowreverse)
const rowDir = align === 'right' ? 'flex-row-reverse text-right' : ''
const avatarSrc = player.avatar || '/default-avatar.png'
/* --- Rendering --------------------------------------------------------- */
return (
<div
className={`
flex flex-col bg-white border border-gray-200 shadow-2xs rounded-xl
dark:bg-neutral-900 dark:border-neutral-700 dark:shadow-neutral-700/70
${alignClasses} ${widthClasses[maxWidth]}
`}
>
<div className="p-2 md:p-4">
<div className={`flex items-center gap-3 ${rowDir}`}>
<Image
src={avatarSrc}
alt={player.name}
width={48}
height={48}
className="rounded-full shrink-0 border object-cover"
/>
<span className="whitespace-nowrap overflow-hidden text-ellipsis">
{player.name}
</span>
</div>
</div>
</div>
)
}