Skip to content

Commit 45823c1

Browse files
committed
Initial commit.
0 parents  commit 45823c1

18 files changed

+6824
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
npm-debug.log

README.md

+1,244
Large diffs are not rendered by default.

package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "react-hangman",
3+
"version": "0.1.0",
4+
"private": true,
5+
"devDependencies": {
6+
"react-scripts": "0.8.5"
7+
},
8+
"dependencies": {
9+
"react": "^15.4.2",
10+
"react-dom": "^15.4.2"
11+
},
12+
"scripts": {
13+
"start": "react-scripts start",
14+
"build": "react-scripts build",
15+
"test": "react-scripts test --env=jsdom",
16+
"eject": "react-scripts eject"
17+
}
18+
}

public/favicon.ico

24.3 KB
Binary file not shown.

public/index.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
7+
<!--
8+
Notice the use of %PUBLIC_URL% in the tag above.
9+
It will be replaced with the URL of the `public` folder during the build.
10+
Only files inside the `public` folder can be referenced from the HTML.
11+
12+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
13+
work correctly both with client-side routing and a non-root public URL.
14+
Learn how to configure a non-root public URL by running `npm run build`.
15+
-->
16+
<title>React App</title>
17+
</head>
18+
<body>
19+
<div id="root"></div>
20+
<!--
21+
This HTML file is a template.
22+
If you open it directly in the browser, you will see an empty page.
23+
24+
You can add webfonts, meta tags, or analytics to this file.
25+
The build step will place the bundled scripts into the <body> tag.
26+
27+
To begin the development, run `npm start`.
28+
To create a production bundle, use `npm run build`.
29+
-->
30+
</body>
31+
</html>

src/App.css

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 80px;
8+
}
9+
10+
.App-header {
11+
background-color: #222;
12+
height: 150px;
13+
padding: 20px;
14+
color: white;
15+
}
16+
17+
@keyframes App-logo-spin {
18+
from { transform: rotate(0deg); }
19+
to { transform: rotate(360deg); }
20+
}
21+
22+
.App-VirtualKeyboard {
23+
display: flex;
24+
align-items: center;
25+
}
26+
27+
.App-VirtualKeyboard .VirtualKeyboard {
28+
width: 100%;
29+
}

src/App.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { Component } from 'react';
2+
import VirtualKeyboard from './VirtualKeyboard';
3+
import logo from './logo.svg';
4+
import './App.css';
5+
6+
class App extends Component {
7+
render() {
8+
return (
9+
<div className="App">
10+
<div className="App-header">
11+
<img src={logo} className="App-logo" alt="logo" />
12+
<h2>React Hangman</h2>
13+
</div>
14+
<div className="App-VirtualKeyboard">
15+
<VirtualKeyboard onClick={this.onLetterClick} />
16+
</div>
17+
</div>
18+
);
19+
}
20+
21+
onLetterClick(letter) {
22+
console.log(letter);
23+
}
24+
}
25+
26+
export default App;

src/App.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
});

src/LetterBlock.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.LetterBlock {
2+
cursor: pointer;
3+
border: 1px solid #999;
4+
border-radius: 5px;
5+
padding: 5px;
6+
min-width: 20px;
7+
color: #000;
8+
}

src/LetterBlock.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import './LetterBlock.css';
3+
4+
class LetterBlock extends Component {
5+
render() {
6+
return (
7+
<div className="LetterBlock">
8+
<span
9+
onClick={this.props.onClick}
10+
className={this.props.disabled ? 'disabled' : ''}>
11+
{this.props.value}
12+
</span>
13+
</div>
14+
);
15+
}
16+
}
17+
18+
LetterBlock.propTypes = {
19+
value: PropTypes.string.isRequired,
20+
onClick: PropTypes.func,
21+
disabled: PropTypes.bool,
22+
};
23+
24+
LetterBlock.defaultProps = {
25+
disabled: false,
26+
};
27+
28+
export default LetterBlock;

src/LettersRow.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.LettersRow {
2+
display: flex;
3+
flex-direction: row;
4+
justify-content: space-between;
5+
}

src/LettersRow.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import './LettersRow.css';
3+
4+
class LettersRow extends Component {
5+
render() {
6+
return (
7+
<div className="LettersRow">
8+
{this.props.children}
9+
</div>
10+
);
11+
}
12+
}
13+
14+
LettersRow.propTypes = {
15+
children: PropTypes.arrayOf(PropTypes.element).isRequired,
16+
}
17+
18+
export default LettersRow;

src/VirtualKeyboard.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.VirtualKeyboard .LettersRow {
2+
width: 30%;
3+
}

src/VirtualKeyboard.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import LettersRow from './LettersRow';
3+
import LetterBlock from './LetterBlock';
4+
import './VirtualKeyboard.css';
5+
6+
class VirtualKeyboard extends Component {
7+
render() {
8+
return (
9+
<div className="VirtualKeyboard">
10+
<div key="First" className="VirtualKeyboard-FirstRow">
11+
{this._renderRow(VirtualKeyboard.FIRST_ROW)}
12+
</div>
13+
<div key="Second" className="VirtualKeyboard-SecondRow">
14+
{this._renderRow(VirtualKeyboard.SECOND_ROW)}
15+
</div>
16+
<div key="Third" className="VirtualKeyboard-ThirdRow">
17+
{this._renderRow(VirtualKeyboard.THIRD_ROW)}
18+
</div>
19+
</div>
20+
);
21+
}
22+
23+
_renderRow(letters) {
24+
const children = letters.map(letter => (
25+
<LetterBlock
26+
value={letter}
27+
onClick={this.props.onClick.bind(null, letter)}
28+
key={`LetterBlock-${letter}`}
29+
/>
30+
));
31+
32+
return (
33+
<LettersRow>
34+
{children}
35+
</LettersRow>
36+
);
37+
}
38+
}
39+
40+
VirtualKeyboard.propTypes = {
41+
onClick: PropTypes.func.isRequired,
42+
}
43+
44+
VirtualKeyboard.FIRST_ROW = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'];
45+
VirtualKeyboard.SECOND_ROW = ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'];
46+
VirtualKeyboard.THIRD_ROW = ['Z', 'X', 'C', 'V', 'B', 'N', 'M'];
47+
48+
export default VirtualKeyboard;

src/index.css

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: sans-serif;
5+
box-sizing: border-box;
6+
}

src/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
import './index.css';
5+
6+
ReactDOM.render(
7+
<App />,
8+
document.getElementById('root')
9+
);

src/logo.svg

+7
Loading

0 commit comments

Comments
 (0)