Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
improve big board sizing (new layout) for the main game for all screens
Browse files Browse the repository at this point in the history
  • Loading branch information
panmona committed Apr 24, 2019
1 parent 1cfe0bb commit 1bdd5d9
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 74 deletions.
9 changes: 5 additions & 4 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { configure } from '@storybook/react'

import '../src/index.css';
import '../src/icons/icons.css';

import '@material/button/dist/mdc.button.min.css';
import '@material/icon-button/dist/mdc.icon-button.css';
import '@material/list/dist/mdc.list.css';
import '@material/card/dist/mdc.card.css';
import '@rmwc/icon/icon.css';
import '@material/typography/dist/mdc.typography.css';

import '@rmwc/icon/icon.css';

import '../src/index.css';
import '../src/icons/icons.css';

import '../../icons/x.svg';
import '../../icons/o.svg';
import '../../icons/draw.svg';
Expand Down
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import '@material/button/dist/mdc.button.min.css';
import '@material/icon-button/dist/mdc.icon-button.css';
import '@material/list/dist/mdc.list.css';
import '@material/card/dist/mdc.card.css';
import '@rmwc/icon/icon.css';
import '@material/typography/dist/mdc.typography.css';
import '@rmwc/icon/icon.css';

export class App extends React.Component {
render() {
Expand Down
17 changes: 17 additions & 0 deletions src/components/Board/BigBoard/BigBoard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,21 @@ describe('BigBoard', function() {
});
});
});

it('should add the given className', () => {
const playerMoved = jest.fn(() => {});
const activeBoards = [{ x: 0, y: 0 }];

const bigBoard = shallow(
<BigBoard
currentPlayer={Player.Cross}
board={unfinishedBoardMock}
activeBoards={activeBoards}
onPlayerMoved={playerMoved}
className={'myClassName'}
/>,
);

expect(bigBoard.hasClass('myClassName')).toBe(true);
});
});
9 changes: 8 additions & 1 deletion src/components/Board/BigBoard/BigBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../../state/AppState';
import { arePointsEqual, Point } from '../../../util';
import styles from './BigBoard.module.css';
import classNames from 'classnames';

interface BigBoardProps {
currentPlayer: Player;
Expand All @@ -19,6 +20,7 @@ interface BigBoardProps {
tileY: number,
) => void;
markTileSpecially?: MarkSpecially;
className?: string;
}

export class BigBoard extends React.Component<BigBoardProps> {
Expand Down Expand Up @@ -95,6 +97,11 @@ export class BigBoard extends React.Component<BigBoardProps> {
};

render() {
return <div className={styles.bigBoard}>{this.createSmallBoards()}</div>;
const { className } = this.props;
return (
<div className={classNames(styles.bigBoard, className)}>
{this.createSmallBoards()}
</div>
);
}
}
18 changes: 6 additions & 12 deletions src/components/GameFinishedDisplay/GameFinished.module.css
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
.winnerText {
margin: 0 0 0.5rem;
margin: 0 1em 0 0;
}

.winnerIcon {
vertical-align: bottom;
}

.restartAlignment {
display: grid;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 1rem;
}

@media only screen and (min-width: 505px) {
.restartAlignment {
grid-template-columns: auto auto;
}

.winnerText {
margin: 0 1em 0 0;
}
}

.hidden {
opacity: 0;
visibility: hidden;
Expand Down
22 changes: 11 additions & 11 deletions src/components/GameFinishedDisplay/GameFinishedDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface GameFinishedDisplayState {
winnerText: string | JSX.Element;
}

// TODO: refactor to function component sometime.
export class GameFinishedDisplay extends React.Component<
GameFinishedDisplayProps,
GameFinishedDisplayState
Expand Down Expand Up @@ -55,27 +54,28 @@ export class GameFinishedDisplay extends React.Component<
return (
<>
<Icon
className={classNames(
styles.floatLeft,
styles.winnerIconContainer,
)}
icon={{
icon: winner === Winner.Circle ? 'o' : 'x',
size: 'large',
}}
/>
<span className={styles.floatRight}>wins!</span>
className={styles.winnerIcon}
/>{' '}
wins!
</>
);
case Winner.Draw:
return `It's a draw!`;
return "It's a draw!";

// Reservation so that the board doesn't shift down
default: {
return (
<>
<Icon icon={{ icon: 'x', size: 'large' }} />
<span className={styles.floatRight}>reservation</span>
<Icon
icon={{ icon: 'x', size: 'xlarge' }}
className={styles.winnerIcon}
/>
resrv
{/* This doesn't get shown to anyone, screenreaders included.*/}
</>
);
}
Expand All @@ -98,7 +98,7 @@ export class GameFinishedDisplay extends React.Component<
[styles.visible]: visible,
})}
>
<Typography use="headline5" className={styles.winnerText}>
<Typography use="headline4" className={styles.winnerText}>
{winnerText}
</Typography>
<Button dense={true} raised={true} onClick={this.tryRestart}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ exports[`GameFinished should match snapshot when circle wins 1`] = `
>
<Typography
className="winnerText"
use="headline5"
use="headline4"
>
<Icon
className="floatLeft winnerIconContainer"
className="winnerIcon"
icon={
Object {
"icon": "o",
"size": "large",
}
}
/>
<span
className="floatRight"
>
wins!
</span>
wins!
</Typography>
<withRipple(Button)
dense={true}
Expand All @@ -39,22 +36,19 @@ exports[`GameFinished should match snapshot when cross wins 1`] = `
>
<Typography
className="winnerText"
use="headline5"
use="headline4"
>
<Icon
className="floatLeft winnerIconContainer"
className="winnerIcon"
icon={
Object {
"icon": "x",
"size": "large",
}
}
/>
<span
className="floatRight"
>
wins!
</span>
wins!
</Typography>
<withRipple(Button)
dense={true}
Expand All @@ -72,7 +66,7 @@ exports[`GameFinished should match snapshot when draw 1`] = `
>
<Typography
className="winnerText"
use="headline5"
use="headline4"
>
It's a draw!
</Typography>
Expand All @@ -92,21 +86,18 @@ exports[`GameFinished should match snapshot when no one wins 1`] = `
>
<Typography
className="winnerText"
use="headline5"
use="headline4"
>
<Icon
className="winnerIcon"
icon={
Object {
"icon": "x",
"size": "large",
"size": "xlarge",
}
}
/>
<span
className="floatRight"
>
reservation
</span>
resrv
</Typography>
<withRipple(Button)
dense={true}
Expand Down
5 changes: 0 additions & 5 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

html,
body {
/* From medium: https://medium.design/system-shock-6b1dc6d6596f */
font-family: -apple-system, '.SFNSText-Regular', 'San Francisco', 'Roboto',
'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif;

margin: 0;
padding: 0;
}
Expand All @@ -24,7 +20,6 @@ body,
.centerAll,
.centerHorizontal {
height: 100%;
width: 100%;
}

.centerAll {
Expand Down
7 changes: 5 additions & 2 deletions src/views/Game/Game.module.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
.gameWrapper {
display: grid;
width: 50%;
margin-top: 1em;
margin-bottom: 1em;

font-size: 7px;
font-size: 9px;
}

.bigBoardSize {
width: 80vmin;
}

@media only screen and (min-width: 500px) {
Expand Down
31 changes: 15 additions & 16 deletions src/views/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ interface GameProps {
) => void;
}

export class Game extends React.Component<GameProps> {
render() {
const { currentPlayer, board, activeBoards, onPlayerMoved } = this.props;
export function Game(props: GameProps) {
const { currentPlayer, board, activeBoards, onPlayerMoved } = props;

return (
<div className="centerAll">
<div className={styles.gameWrapper}>
<GameFinishedDisplay />
<BigBoard
currentPlayer={currentPlayer}
board={board}
activeBoards={activeBoards}
onPlayerMoved={onPlayerMoved}
/>
</div>
return (
<div className="centerAll">
<div className={styles.gameWrapper}>
<GameFinishedDisplay />
<BigBoard
currentPlayer={currentPlayer}
board={board}
activeBoards={activeBoards}
onPlayerMoved={onPlayerMoved}
className={styles.bigBoardSize}
/>
</div>
);
}
</div>
);
}

const mapStateToProps = (state: AppState) => ({
Expand Down
1 change: 1 addition & 0 deletions src/views/Game/__snapshots__/Game.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ exports[`Game should match snapshot 1`] = `
},
]
}
className="bigBoardSize"
currentPlayer={0}
onPlayerMoved={[MockFunction]}
/>
Expand Down

0 comments on commit 1bdd5d9

Please sign in to comment.