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
|
2021-09-23 23:34:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function CardToken(props: CardTokenProps): JSX.Element {
|
2021-09-24 06:51:17 -04:00
|
|
|
const {onSelect, cardKey} = props
|
2021-09-23 23:34:33 -04:00
|
|
|
|
|
|
|
if (cardKey == null) {
|
|
|
|
return (
|
2021-09-24 06:51:17 -04:00
|
|
|
<div>
|
2021-09-23 23:34:33 -04:00
|
|
|
<span>{EMPTY_SPACE}</span>
|
2021-09-24 06:51:17 -04:00
|
|
|
</div>
|
2021-09-23 23:34:33 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return (
|
2021-09-24 06:51:17 -04:00
|
|
|
<button onClick={onSelect}>
|
|
|
|
<img
|
|
|
|
src={getCardSrc(cardKey)}
|
|
|
|
alt={getCardAlt(cardKey)}
|
|
|
|
/>
|
2021-09-23 23:34:33 -04:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|