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-24 22:51:26 -04:00
|
|
|
isSelected: boolean
|
|
|
|
disabled: boolean
|
2021-09-23 23:34:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function CardToken(props: CardTokenProps): JSX.Element {
|
2021-09-24 22:51:26 -04:00
|
|
|
const {onSelect, cardKey, isSelected, disabled} = props
|
2021-09-23 23:34:33 -04:00
|
|
|
if (cardKey == null) {
|
|
|
|
return (
|
2021-09-24 22:51:26 -04:00
|
|
|
<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 (
|
2021-09-24 22:51:26 -04:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`card-button${isSelected ? ' selected' : ''}`}
|
|
|
|
onClick={onSelect}
|
|
|
|
disabled={disabled}
|
|
|
|
>
|
2021-09-24 06:51:17 -04:00
|
|
|
<img
|
2021-09-24 22:51:26 -04:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|