2022-03-16 23:03:15 -04:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import cn from "classnames";
|
2022-03-16 21:46:20 -04:00
|
|
|
import { Cell } from "../types";
|
|
|
|
import styles from "../styles/board.module.css";
|
2022-03-05 09:57:20 -05:00
|
|
|
|
2022-03-16 21:46:20 -04:00
|
|
|
interface BoardProps {
|
|
|
|
cells: Cell[];
|
|
|
|
cellWidth: number;
|
2022-03-16 23:03:15 -04:00
|
|
|
focusedCellIndex?: number;
|
|
|
|
onCellClick: (index: number) => void;
|
2022-03-16 21:46:20 -04:00
|
|
|
}
|
2022-03-05 09:57:20 -05:00
|
|
|
|
2022-03-16 23:03:15 -04:00
|
|
|
const Board = (props: BoardProps) => (
|
|
|
|
<div
|
|
|
|
className={styles.gridContainer}
|
|
|
|
style={{
|
|
|
|
gridTemplateColumns: `repeat(${props.cellWidth}, 1fr)`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{props.cells.map((cell, i) => (
|
|
|
|
<button
|
|
|
|
className={cn(styles.gridCell, {
|
|
|
|
[styles.cellClicked]: i === props.focusedCellIndex,
|
|
|
|
})}
|
|
|
|
onClick={() => props.onCellClick(i)}
|
|
|
|
>
|
|
|
|
{cell.piece}
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
2022-03-16 21:46:20 -04:00
|
|
|
|
|
|
|
export default Board;
|