Skip to content

Commit e229ccf

Browse files
author
Roman Babaev
committed
Updates zoom feature
1 parent 88c389e commit e229ccf

File tree

4 files changed

+66
-9
lines changed

4 files changed

+66
-9
lines changed

src/App/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { FooterPanel } from "../FooterPanel";
44
import { Hat } from "../Hat";
55
import { Minesweeper } from "../core";
66
import { Options } from "../Options";
7+
import {
8+
ZOOM_MIN,
9+
ZOOM_MAX,
10+
ZOOM_DEFAULT
11+
} from '../constants';
712
import "./styles.css";
813

914
function preventZoom(event) {
@@ -35,7 +40,13 @@ export default class App extends React.Component {
3540
toggleOptions = () =>
3641
this.setState(({ showOptions }) => ({ showOptions: !showOptions }));
3742

38-
handleZoomChange = zoom => zoom && this.setState({ zoom });
43+
handleZoomChange = zoom => zoom && zoom > 0 && this.setState({
44+
zoom: zoom > ZOOM_MAX
45+
? ZOOM_MAX
46+
: zoom < ZOOM_MIN
47+
? ZOOM_MIN
48+
: zoom
49+
});
3950

4051
newGame = (arena, mines) => this.game.configure(arena, mines);
4152

src/FooterPanel/index.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
import React from "react";
22
import { Button, ControlsPanel, Switcher } from "@tarantool.io/ui-kit";
33
import b_ from 'b_';
4+
import { ZOOM_STEP } from '../constants';
45
import "./styles.css";
56

67
const b = b_.lock('FooterPanel');
78

8-
export const FooterPanel = ({ flaggingMode, zoom, onFlaggingSwitch, onZoomChange }) => (
9+
export const FooterPanel = ({
10+
flaggingMode,
11+
zoom,
12+
onFlaggingSwitch,
13+
onZoomChange
14+
}) => (
915
<ControlsPanel
1016
className={b()}
1117
controls={[
12-
<Button className={b('zoomButton')} text='+' size='xs' onClick={() => onZoomChange(zoom + 0.5)} />,
13-
<Button className={b('zoomButton')} text='-' size='xs' onClick={() => onZoomChange(zoom - 0.5)} />,
14-
<Switcher onChange={onFlaggingSwitch} title="Flag" checked={flaggingMode}>Flag</Switcher>
18+
<Button
19+
key='+'
20+
className={b('zoomButton')}
21+
text='+'
22+
size='xs'
23+
onClick={() => onZoomChange(zoom + ZOOM_STEP)}
24+
/>,
25+
<Button
26+
key='-'
27+
className={b('zoomButton')}
28+
text='-'
29+
size='xs'
30+
onClick={() => onZoomChange(zoom - ZOOM_STEP)}
31+
/>,
32+
<Switcher
33+
key='f'
34+
onChange={onFlaggingSwitch}
35+
title='Flag'
36+
checked={flaggingMode}
37+
>
38+
Flag
39+
</Switcher>
1540
]}
1641
/>
1742
);

src/Hat/index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,30 @@ export const Hat = ({
2020
className={b()}
2121
thin
2222
controls={[
23-
<Text className={b('output')} title='Mines counter'>💣{minesLeftCount}</Text>,
24-
<Text className={b('output')} title='Timer'>{timerValue === null ? 0 : Math.round(timerValue / 1000)}</Text>,
25-
<Button onClick={onResetClick} title='New game (Space)' intent={gameState === 'playing' ? 'secondary' : 'primary'}>
23+
<Text
24+
key='c'
25+
className={b('output')}
26+
title='Mines counter'
27+
>
28+
💣{minesLeftCount}
29+
</Text>,
30+
<Text
31+
key='t'
32+
className={b('output')}
33+
title='Timer'
34+
>
35+
{timerValue === null ? 0 : Math.round(timerValue / 1000)}
36+
</Text>,
37+
<Button
38+
key='n'
39+
onClick={onResetClick}
40+
title='New game (Space)'
41+
intent={gameState === 'playing' ? 'secondary' : 'primary'}
42+
>
2643
{gameState === "playing" ? "🙂" : gameState === "won" ? "😎" : "😵"}
2744
New game
2845
</Button>,
29-
<Button onClick={onOptionsClick} title="Options">Options</Button>
46+
<Button key='o' onClick={onOptionsClick} title="Options">Options</Button>
3047
]}
3148
/>
3249
);

src/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const ZOOM_MIN = 0.25;
2+
export const ZOOM_MAX = 4;
3+
export const ZOOM_STEP = 0.25;
4+
export const ZOOM_DEFAULT = 1;

0 commit comments

Comments
 (0)