add Timer component

This commit is contained in:
Francesco Esposito 2019-03-15 10:33:22 +01:00
parent 2b0d00ac35
commit b14dbba3b4
2 changed files with 130 additions and 31 deletions

View File

@ -1,3 +1,63 @@
.timer { .timer {
font-size: 120px; font-size: 120px;
} font-weight: 600;
text-shadow: 0 0 2px #cf4242, 0 0 4px #2B2D1F;
color: white;
opacity: 1;
}
.buttons {
font-size: 22px;
font-weight: bold;
height: 70px;
border-radius: 30px;
box-shadow: 0 0 1px #03030349, 0 0 10px rgb(155, 156, 150);
opacity: 0.9;
}
.top-buffer {
margin-top: 15px;
}
.buttons-box {
background-color: rgba(255, 255, 255, 0.9); /* transparent */
padding: 20px;
margin-top: 5px;
border-radius: 30px;
opacity: 1;
box-shadow: 0 0 2px #cf4242, 0 0 5px rgb(243, 243, 243);
}
.App-logo {
height: 25vmin;
pointer-events: none;
filter: drop-shadow(0 0 1.00rem rgb(211, 204, 206));
align-items: center;
justify-content: center;
text-align: center;
}
.App-logo-rotation {
animation: App-logo-spin infinite 5s linear;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.App-logo-scale {
animation: crescendo 0.5s alternate infinite ease-in;
}
@keyframes crescendo {
0% {transform: scale(.8);}
100% {transform: scale(1.2);}
}

View File

@ -1,16 +1,18 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Button } from 'reactstrap'; import { Button, Container, Row, Col } from 'reactstrap';
import './Timer.css'; import './Timer.css';
import logo from '../logo.svg';
class Timer extends Component { class Timer extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.defaultSeconds = 1500; this.defaultSeconds = 1500;
this.defaultLogoSpin = 'App-logo-rotation';
this.state = { this.state = {
seconds: this.defaultSeconds, seconds: this.defaultSeconds,
started: false started: false,
logoSpin: ''
}; };
this.startTimer = this.startTimer.bind(this); this.startTimer = this.startTimer.bind(this);
this.stopTimer = this.stopTimer.bind(this); this.stopTimer = this.stopTimer.bind(this);
@ -26,12 +28,18 @@ class Timer extends Component {
} }
startTimer() { startTimer() {
this.setState({ started: true }) this.setState({
started: true,
logoSpin: this.defaultLogoSpin
});
this.interval = setInterval(() => this.tick(), 1000); this.interval = setInterval(() => this.tick(), 1000);
} }
stopTimer() { stopTimer() {
this.setState({ started: false }); this.setState({
started: false,
logoSpin: null
});
clearInterval(this.interval); clearInterval(this.interval);
} }
@ -43,35 +51,66 @@ class Timer extends Component {
render() { render() {
return ( return (
<div className="App"> <div className="App">
<Container>
<p class="timer">{this.fmtMSS(this.state.seconds)}</p> <Row>
<Col>
<Button <img className={`App-logo ${this.state.logoSpin}`} src={logo}/>
size="lg" </Col>
color="success" </Row>
onClick={this.startTimer} <Row>
disabled={this.state.started} <Col>
> <p
START class="timer"
</Button> >
{this.fmtMSS(this.state.seconds)}
<Button </p>
</Col>
</Row>
<div className="buttons-box">
<Row>
<Col>
<Button
className="buttons"
block
size="lg"
color="success"
onClick={this.startTimer}
disabled={this.state.started}
>
Start
</Button>
</Col>
</Row>
<Row className="top-buffer">
<Col>
<Button
className="buttons"
block
color="danger" color="danger"
size="lg" size="lg"
onClick={this.stopTimer} onClick={this.stopTimer}
disabled={!this.state.started} disabled={!this.state.started}
> >
STOP Stop
</Button> </Button>
</Col>
<Button <Col>
color="secondary" <Button
size="lg" className="buttons"
onClick={this.resetTimer} block
disabled={this.state.started} color="secondary"
> size="lg"
RESET onClick={this.resetTimer}
</Button> disabled={this.state.started}
>
Reset
</Button>
</Col>
</Row>
</div>
</Container>
</div> </div>
); );
} }