Skip to content

Commit 99443db

Browse files
author
Edvinas Jurele
committed
Add loto app
0 parents  commit 99443db

23 files changed

+10253
-0
lines changed

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://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.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*

README.md

+2,434
Large diffs are not rendered by default.

package.json

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

public/favicon.ico

3.78 KB
Binary file not shown.

public/index.html

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
<!--
8+
manifest.json provides metadata used when your web app is added to the
9+
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
10+
-->
11+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
13+
<!--
14+
Notice the use of %PUBLIC_URL% in the tags above.
15+
It will be replaced with the URL of the `public` folder during the build.
16+
Only files inside the `public` folder can be referenced from the HTML.
17+
18+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
19+
work correctly both with client-side routing and a non-root public URL.
20+
Learn how to configure a non-root public URL by running `npm run build`.
21+
-->
22+
<title>React App</title>
23+
</head>
24+
<body>
25+
<noscript>
26+
You need to enable JavaScript to run this app.
27+
</noscript>
28+
<div id="root"></div>
29+
<!--
30+
This HTML file is a template.
31+
If you open it directly in the browser, you will see an empty page.
32+
33+
You can add webfonts, meta tags, or analytics to this file.
34+
The build step will place the bundled scripts into the <body> tag.
35+
36+
To begin the development, run `npm start` or `yarn start`.
37+
To create a production bundle, use `npm run build` or `yarn build`.
38+
-->
39+
</body>
40+
</html>

public/manifest.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": "./index.html",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

src/App.css

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.App__tickets {
2+
/* text-align: center; */
3+
padding: 15px;
4+
}
5+
6+
.App__header {
7+
font-size: 18px;
8+
padding: 20px;
9+
background-color: #e5e5e5;
10+
}
11+
12+
.App__rolled-balls-bar {
13+
display: flex;
14+
flex-wrap: wrap;
15+
padding: 10px 20px;
16+
align-items: center;
17+
min-height: 50px;
18+
background-color: #efefef;
19+
}

src/App.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import React, { Component } from "react";
2+
import "./App.css";
3+
4+
import Ticket from "./components/Ticket";
5+
import Ball from "./components/Ball";
6+
import Input from "./components/Input";
7+
8+
const ticket1 = {
9+
values: [
10+
[5, 16, 42, 49, 65],
11+
[7, 23, 44, 46, 72],
12+
[11, 26, 43, 50, 64],
13+
[14, 29, 35, 48, 66],
14+
[6, 24, 41, 60, 69]
15+
],
16+
number: "0642953"
17+
};
18+
19+
const ticket2 = {
20+
values: [
21+
[7, 27, 39, 51, 66],
22+
[11, 20, 33, 49, 68],
23+
[8, 18, 45, 57, 75],
24+
[13, 21, 36, 53, 65],
25+
[10, 30, 37, 52, 72]
26+
],
27+
number: "0657387"
28+
};
29+
30+
class App extends Component {
31+
state = {
32+
rolledValues: [],
33+
value: ""
34+
};
35+
36+
crossOutNumber = number => {
37+
console.log("Entered", number);
38+
};
39+
40+
handleEnteredNumber = e => {
41+
const inputValue = e.target.value;
42+
const regexDigits = /\D/;
43+
const regexTwoDigits = /(^[\d]{2})[\d]/;
44+
const value = inputValue
45+
.replace(regexDigits, "")
46+
.replace(regexTwoDigits, "$1");
47+
this.setState({ value });
48+
};
49+
50+
handleEnteredNumberCrossout = e => {
51+
e.preventDefault();
52+
const value = this.state.value;
53+
this.crossOutNumber(value);
54+
if (
55+
value.length >= 1 &&
56+
value >= 1 &&
57+
value <= 75 &&
58+
!this.state.rolledValues.includes(value)
59+
) {
60+
this.state.rolledValues.push(this.state.value);
61+
}
62+
this.setState({ value: "" });
63+
};
64+
65+
render() {
66+
const { rolledValues } = this.state;
67+
return (
68+
<div className="App">
69+
<div className="App__tickets">
70+
<Ticket rolledValues={this.state.rolledValues} {...ticket1} />
71+
<Ticket rolledValues={this.state.rolledValues} {...ticket2} />
72+
</div>
73+
<div
74+
style={
75+
{
76+
// position: "fixed",
77+
// width: "100%",
78+
// bottom: 0
79+
}
80+
}
81+
>
82+
<div className="App__header">
83+
<form onSubmit={this.handleEnteredNumberCrossout}>
84+
<label htmlFor="ticketNumber">Įveskite skaičių: </label>
85+
<Input
86+
id="ticketNumber"
87+
value={this.state.value}
88+
onChange={this.handleEnteredNumber}
89+
/>
90+
</form>
91+
</div>
92+
<div className="App__rolled-balls-bar">
93+
{rolledValues.length ? (
94+
rolledValues.map((value, index) => (
95+
<Ball key={index} value={value} />
96+
))
97+
) : (
98+
<div>Nėra išridentų kamuoliukų</div>
99+
)}
100+
</div>
101+
</div>
102+
</div>
103+
);
104+
}
105+
}
106+
107+
export default App;

src/App.test.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+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});

src/components/Ball/index.css

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.Ball {
2+
display: inline-block;
3+
line-height: 1;
4+
margin: 5px;
5+
background-color: darkgrey;
6+
border-radius: 50%;
7+
padding: 5px;
8+
}
9+
10+
.Ball.Ball--blue {
11+
background-color: rgba(0, 0, 255, 0.5);
12+
}
13+
14+
.Ball.Ball--black {
15+
background-color: rgba(0, 0, 0, 0.5);
16+
color: white;
17+
}
18+
19+
.Ball.Ball--red {
20+
background-color: rgba(255, 0, 0, 0.5);
21+
}
22+
23+
.Ball.Ball--yellow {
24+
background-color: rgba(255, 255, 0, 0.5);
25+
}
26+
27+
.Ball.Ball--green {
28+
background-color: rgba(0, 255, 0, 0.5);
29+
}

src/components/Ball/index.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import cx from "classnames";
4+
5+
import "./index.css";
6+
7+
const Ball = ({ value, className }) => {
8+
const getBallColor = color => {
9+
if (value > 0 && value < 16) return "Ball--blue";
10+
if (value >= 16 && value < 31) return "Ball--black";
11+
if (value >= 31 && value < 46) return "Ball--red";
12+
if (value >= 46 && value < 61) return "Ball--yellow";
13+
if (value >= 61 && value < 76) return "Ball--green";
14+
};
15+
16+
return (
17+
<div className={cx("Ball", className, getBallColor())}>
18+
{value.toString().length === 1 ? `0${value}` : value}
19+
</div>
20+
);
21+
};
22+
23+
Ball.propTypes = {
24+
value: PropTypes.string.isRequired,
25+
className: PropTypes.string
26+
};
27+
28+
Ball.defaultProps = {
29+
className: undefined
30+
};
31+
32+
export default Ball;

src/components/Input/index.css

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.Input {
2+
height: 26px;
3+
font-size: 18px;
4+
padding: 5px;
5+
border-radius: 4px;
6+
border-style: none;
7+
max-width: 80px;
8+
outline: none;
9+
}

src/components/Input/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import cx from "classnames";
4+
5+
import "./index.css";
6+
7+
const Input = ({ className, ...props }) => (
8+
<input type="text" {...props} className={cx("Input", className)} />
9+
);
10+
11+
Input.propTypes = {
12+
className: PropTypes.string
13+
};
14+
15+
Input.defaultProps = {
16+
className: undefined
17+
};
18+
19+
export default Input;

src/components/Ticket/index.css

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.Ticket {
2+
font-family: "Courier New", Courier, monospace, sans-serif;
3+
text-align: center;
4+
display: inline-block;
5+
margin: 5px 5px 25px 5px;
6+
padding: 25px;
7+
8+
background: url(../../images/bg.jpg) left top;
9+
overflow: hidden;
10+
}
11+
12+
.Ticket table {
13+
border-collapse: collapse;
14+
}
15+
16+
.Ticket td,
17+
.Ticket th {
18+
border: 1px dashed black;
19+
}
20+
21+
.TicketField__footer {
22+
margin-top: 10px;
23+
}
24+
25+
.TicketField__ticket-number {
26+
letter-spacing: 2px;
27+
}

0 commit comments

Comments
 (0)