Skip to content

Commit

Permalink
* created a presentational component to house Game and UltimateGame
Browse files Browse the repository at this point in the history
* tweaked css a little
  • Loading branch information
ldgit committed Sep 9, 2018
1 parent 3725dec commit d673162
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 27 deletions.
20 changes: 20 additions & 0 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import Game from './Game';
import Title from './Title';
import UltimateGame from './UltimateGame';

export default function App() {
return (
<div>
<Title name="React" />
<div className="table">
<div className="table-cell">
<UltimateGame />
</div>
<div className="table-cell table-large-padding">
<Game />
</div>
</div>
</div>
);
}
6 changes: 3 additions & 3 deletions src/components/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export default function Board({

return (
<div data-testid={testId} className={className}>
<div className="board-row">
<div className="table-row">
{renderSquare('0', 'topLeftSquare')}
{renderSquare('1', 'topMiddleSquare')}
{renderSquare('2', 'topRightSquare')}
</div>
<div className="board-row">
<div className="table-row">
{renderSquare('3', 'centerLeftSquare')}
{renderSquare('4', 'centerMiddleSquare')}
{renderSquare('5', 'centerRightSquare')}
</div>
<div className="board-row">
<div className="table-row">
{renderSquare('6', 'bottomLeftSquare')}
{renderSquare('7', 'bottomMiddleSquare')}
{renderSquare('8', 'bottomRightSquare')}
Expand Down
18 changes: 7 additions & 11 deletions src/components/Game.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import Title from './Title';
import Board from './Board';
import Status from './Status';
import { calculateWinner } from '../helpers';
Expand Down Expand Up @@ -61,16 +60,13 @@ export default class Game extends React.Component {
});

return (
<div>
<Title name="React" />
<div className="game">
<div className="game-board">
<Board squares={squares} onClick={i => this.handleClick(i)} />
</div>
<div className="game-info">
<Status gameInfo={status} />
<ol>{moves}</ol>
</div>
<div className="game">
<div className="game-board">
<Board squares={squares} onClick={i => this.handleClick(i)} />
</div>
<div className="game-info">
<Status gameInfo={status} />
<ol>{moves}</ol>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Title.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

export default function Title({ name }) {
return <h1>Hello {name}</h1>;
return <h1>Tic-tac-toe in {name}!</h1>;
}
2 changes: 1 addition & 1 deletion src/components/UltimateGame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class UltimateGame extends React.Component {

renderBoard(boardIndex, boards, testId) {
const currentBoard = boards[boardIndex];
const boardClass = `board-cell ${getColorClass(currentBoard)}`;
const boardClass = `table-cell table-board-border ${getColorClass(currentBoard)}`;

return (
<Board
Expand Down
21 changes: 18 additions & 3 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ ol, ul {
padding-left: 30px;
}

.board-row {
.table {
display: table;
}

.table-row {
display: table-row;
}

.board-cell {
border: 2px solid #fff;
.table-column {
display: table-column;
}

.table-cell {
display: table-cell;
}

.table-large-padding {
padding-left: 50px;
}

.table-board-border {
border: 2px solid #fff;
}

.status {
margin-bottom: 10px;
}
Expand Down
12 changes: 4 additions & 8 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from 'react';
import ReactDom from 'react-dom';
import Game from './components/Game';
import UltimateGame from './components/UltimateGame';
import App from './components/App';
import './index.css';

const ultimateGameApp = document.createElement('div');
const normalGameApp = document.createElement('div');
document.body.appendChild(ultimateGameApp);
document.body.appendChild(normalGameApp);
ReactDom.render(<UltimateGame />, ultimateGameApp);
ReactDom.render(<Game />, normalGameApp);
const app = document.createElement('div');
document.body.appendChild(app);
ReactDom.render(<App />, app);

0 comments on commit d673162

Please sign in to comment.