tome-web/client/game/cards/Card.tsx

42 lines
907 B
TypeScript
Raw Normal View History

2021-09-23 23:34:33 -04:00
import React from 'react'
2021-09-24 06:51:17 -04:00
import type {CardKey} from '../types.ts'
import {getCardAlt, getCardSrc} from './cards.ts'
2021-09-23 23:34:33 -04:00
const EMPTY_SPACE = '-'
interface CardTokenProps {
cardKey: CardKey | null
2021-09-24 06:51:17 -04:00
onSelect?: () => void
isSelected: boolean
disabled: boolean
2021-09-23 23:34:33 -04:00
}
export default function CardToken(props: CardTokenProps): JSX.Element {
const {onSelect, cardKey, isSelected, disabled} = props
2021-09-23 23:34:33 -04:00
if (cardKey == null) {
return (
<div className={`card-button card-back${isSelected ? ' selected' : ''}`}>
<div>
<span>{EMPTY_SPACE}</span>
</div>
2021-09-24 06:51:17 -04:00
</div>
2021-09-23 23:34:33 -04:00
)
}
return (
<button
type="button"
className={`card-button${isSelected ? ' selected' : ''}`}
onClick={onSelect}
disabled={disabled}
>
2021-09-24 06:51:17 -04:00
<img
className="card-image"
2021-09-24 06:51:17 -04:00
src={getCardSrc(cardKey)}
alt={getCardAlt(cardKey)}
/>
2021-09-23 23:34:33 -04:00
</button>
)
}