freego_api/ui/components/board.tsx

34 lines
753 B
TypeScript
Raw Permalink Normal View History

2022-03-16 23:03:15 -04:00
import React, { useState } from "react";
import cn from "classnames";
import { Cell } from "../types";
import styles from "../styles/board.module.css";
interface BoardProps {
cells: Cell[];
cellWidth: number;
2022-03-16 23:03:15 -04:00
focusedCellIndex?: number;
onCellClick: (index: number) => void;
}
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>
);
export default Board;