Skip to content

Commit

Permalink
feat(card): add selected card selection [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadphol committed Jan 2, 2025
1 parent 24f146e commit 4790a20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { SUIT, SUIT_SYMBOLS } from '@constants/card'
interface CardProps {
card: CardType
onClick?: () => void
isSelected?: boolean
}

const Card = ({ card, onClick }: CardProps) => {
const Card = ({ card, onClick, isSelected = false }: CardProps) => {
const { suit, rank } = card
const { color, bgColor } =
suit === SUIT.HEARTS || suit === SUIT.DIAMONDS
Expand All @@ -19,7 +20,10 @@ const Card = ({ card, onClick }: CardProps) => {
className={cn(
'flex h-24 w-16 cursor-pointer flex-col items-center justify-center rounded-lg border border-gray-300 bg-white p-2',
color,
bgColor
bgColor,
{
'border border-yellow-400': isSelected,
}
)}
onClick={onClick}
>
Expand Down
1 change: 1 addition & 0 deletions src/components/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const Game = () => {
onCardClick={handleCardClick}
isCurrentPlayer={true}
score={scores[currentPlayer]}
selectedCards={selectedCards}
/>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions src/components/player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ interface PlayerProps {
score: number
onCardClick?: (card: CardType) => void
isCurrentPlayer?: boolean
selectedCards?: CardType[]
}

const Player = ({ hand, playedCards, score, onCardClick, isCurrentPlayer = false }: PlayerProps) => {
const Player = ({
hand,
playedCards,
score,
onCardClick,
isCurrentPlayer = false,
selectedCards = [],
}: PlayerProps) => {
return (
<div className="mb-4">
<h2 className="mb-2 text-lg font-bold">Player Hand</h2>
Expand All @@ -30,7 +38,7 @@ const Player = ({ hand, playedCards, score, onCardClick, isCurrentPlayer = false
{playedCards.map((group, groupIndex) => (
<div key={groupIndex} className="flex space-x-2 rounded border border-gray-300 p-2">
{group.map((card, cardIndex) => (
<Card key={cardIndex} card={card} />
<Card key={cardIndex} card={card} isSelected={selectedCards.includes(card)} />
))}
</div>
))}
Expand Down

0 comments on commit 4790a20

Please sign in to comment.