Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href="https://fonts.googleapis.com/css?family=Lobster&display=swap" rel="stylesheet"> 

<div id="root"></div>
            
          
!
            
              body {
  text-align: center;
  background: linear-gradient(to right, #ffd89b, #19547b);
  font-family: 'Lobster', cursive;
}

#main{
  font-size: 20px;
  width: 550px;
  height: 550px;
  border-radius:50%;
  border:1px solid black;
  margin: 110px auto;
  display: flex;
  flex-flow: column wrap;
  justify-content: center;
  align-items: center;
}

button {
  font-family: 'Lobster', cursive;
  font-size: 30px;
  background: none;
  border: none; 
  color: black;
 }

button:hover {
  cursor: pointer;
}

#br,#ses, {
  display: flex;
  flex-flow: row nowrap; 
  justify-content: space-around;
}

#time {
  width: 300px;
  border: 2px solid black;
  border-radius: 35px;
  margin: 10px auto;
}

#timer-label {
   font-size: 25px;
}

#time-left,#br,#ses {
  font-family: 'Lobster', cursive;
}

#controls {
  display: inline-block;
  margin-top: 20px;
}

#start_stop,#reset {
  font-size: 25px;
  font-family: 'Lobster', cursive;
}

#start_stop {
  margin-right: 70px;
}

#break-label {
  margin-top: -40px;
}











            
          
!
            
              class Clock extends React.Component {
  constructor(props){
    super(props);
    this.state={
      intervalFlag: 0,
      indicating: "Session",
      breakLength: 5, 
      sessionLength: 25,
      minutes: 25,
      seconds:'00',
      timerFlag: "not running",
      breakFlag: false
    }
  }
   
  showCountdown = () => {
        let seconds = parseInt(this.state.seconds);
        let minutes = parseInt(this.state.minutes); // edw to parseInt prepei na ginei paroti arxika to minutes einai akeraios. Ka8e fora pou bazw mhdeniko sto min to min ginetai string opote prepei ka8e fora pou kaleitai h showCountdown na to kanw akeraio me to parseInt
        if(minutes < 10){minutes = ("0").concat(minutes)} // an ta lepta einai katw apo 10 tote bazw mhdeniko brosta gia na deixnei 08 kai oxi 8. Prosoxh edw to minutes ginetai string eksou kai to parseInt sthn arxh se ka8e kalesma ths sunarthshs
        if(seconds < 10){seconds = ("0").concat(seconds)} // omoiws kai edw
        this.setState({minutes: minutes, seconds: seconds});
    }
  
  beginCountdown = () => {
        let seconds = parseInt(this.state.seconds);
        let minutes = this.state.minutes; // edw den xreiazetai na ginei akeraios giati einai hdh akeraios kai den uparxei kapoia metatroph tou se string
        if(minutes == 0 && seconds == 0){ // shmainei pws eite exei teliwsei to session eite exei teliwsei to break opote prepei na elegksw an prepei na ksekinhsei break h session
            if(this.state.breakFlag === true){ // an einai true shmainei oti exei ginei break kai prepei na teliwsei to break kai na arxisei to session gia auto ta lepta sto setState einai osa grafei to sessionlength, to breakFlag ginetai false giati 8a teliwsei to break kai to indicating ginetai Session wste na xeroume oti ksekinaei neo Session countdown
                this.setState({
                  indicating: "Session",
                  minutes: this.state.sessionLength, 
                  breakFlag: false });
                  $('audio#beep')[0].play(); // jQuery tropos na paikseis enan hxo. Epistrefei pinaka gia auto bazw to [0]
            }
            else{ // alliws an einai false shmainei pws prepei twra na ginei break gia auto ta lepta sto setState einai osa grafei to breakLength, omoiws breakFlag ginetai true kai indicating ginetai Break wste na xeroume oti twra ksekinaei to break
                this.setState({
                  indicating: "Break",
                  minutes: this.state.breakLength, 
                  breakFlag: true });
                  $('audio#beep')[0].play();
            }
        }
        else if(seconds == 0){ // an ta seconds einai 0 kai ta minutes oxi tote ta seconds ginontai 59 kai meiwnw ta minutes kata 1
            this.setState({ seconds: 59, minutes: minutes - 1 });
        }
        else{ // afou ta seconds den einai 0 kai den einai kai ta minutes tote apla meiwnw ka8e fora ta seconds kata 1
            this.setState({ seconds: seconds - 1 });
        }
        this.showCountdown(); 
  }
  
  Actions = (action) => {
    
    if(action == "STARTSTOP") {
      if(this.state.timerFlag == "not running"){ // an exei stamathsei to roloi tote patwntas to start/stop to ksekinas kai allazeis thn katastash tou se "running" kai kaleis thn beginCountdown ka8e ena deuterolepto
            this.setState({ timerFlag: "running" });
            this.state.intervalFlag = setInterval(this.beginCountdown, 1000); // kaleis thn beginCountdown ka8e ena deuterolepto kai mesa sthn beginCountdown kaleis sto telos thn showCountdown wste ka8e deuterolepto na allazei to roloi
        }
        if(this.state.timerFlag == "running"){ // an to roloi trexei tote patwntas start/stop to stamataw kai allazw thn katastash tou se "not running"
            this.setState({ timerFlag: "not running" });
            clearInterval(this.state.intervalFlag); //stamataw thn setInterval dhladh stamataw to countdown
        }                       
    }
    if(action == "RESET") { // otan pataw to koubi reset tote prepei ola na pane sthn arxikh tous katastash tou this.state kai prepei na stamathsw to countdown kai na kanw rewind ton hxo
      this.setState({
        intervalFlag: 0,
        indicating: "Session",
        breakLength : 5,
        sessionLength : 25,
        minutes : 25,
        seconds : '00',
        timerFlag: "not running",
        breakFlag: false
      });
      clearInterval(this.state.intervalFlag); // stamataw to countdown
       $('audio#beep')[0].pause();// kanw pause ton hxo
       $('audio#beep')[0].currentTime = 0;// kanw rewind ton hxo sthn arxh
    }
    if(action == "bdecr") { // otan pataw to koubi - sto breakLength tote to meiwnw kata 1
      if(this.state.breakLength>1)
     this.setState({breakLength: this.state.breakLength-1});
    }
    if(action == "bincr") { // otan pataw to koubi + sto breakLength tote to auxanw kata 1
      if(this.state.breakLength<60)
      this.setState({breakLength: this.state.breakLength+1});
    }
    if(action == "sdecr") { // otan pataw to koubi - sto sessionLength tote to meiwnw kata 1 kai prepei na meiwnetai antistoixa kai h diarkeia tou countdown dhladh ta minutes
      if(this.state.sessionLength>1)
      this.setState({
        sessionLength: this.state.sessionLength-1,
        minutes: this.state.sessionLength - 1
      });
    }
    if(action == "sincr") { // otan pataw to koubi + sto sessionLength tote to auxanw kata 1 kai prepei na auxanetai antistoixa kai h diarkeia tou countdown dhladh ta minutes
      if(this.state.sessionLength<60)
      this.setState({
        sessionLength: this.state.sessionLength+1,
        minutes: this.state.sessionLength + 1
      });
    }
  }

  render(){
    return(
     <div>
       <Controls
         Actions={this.Actions}
         breakLength={this.state.breakLength}
         sessionLength={this.state.sessionLength}
         indicating={this.state.indicating}
         minutes={this.state.minutes}
         seconds={this.state.seconds}
         timerFlag={this.state.timerFlag}
         breakFlag={this.state.breakFlag}
       />
       <audio id="beep" src="https://www.trekcore.com/audio/computer/computerbeep_73.mp3"/>
     </div>
    )
  }
}

class Controls extends React.Component{
  // me ton tropo pou kaleitai h onClick se ka8e button, pernaw san argument to name tou ka8e button wste h Actions na xerei poio button path8hke kai na bei sthn antistoixh if 
  render(){
    return(
      <div>
        <h1>Pomodoro Clock</h1>
        <div id="main">
         <div id="break-label">
          <h3 id="break-title">Break Length</h3>
           <div id="br">
             <button id="break-decrement" name="bdecr" onClick={b => this.props.Actions(b.target.name)}>-</button> 
             <p id="break-length">{this.props.breakLength}</p>
             <button id="break-increment" name="bincr" onClick={b => this.props.Actions(b.target.name)}>+</button>
           </div>
        </div>
        <div id="session-label">
          <h3>Session Length</h3>
          <div id="ses">
             <button id="session-decrement" name="sdecr" onClick={b => this.props.Actions(b.target.name)}>-</button>
             <p id="session-length">{this.props.sessionLength}</p>
             <button id="session-increment" name="sincr" onClick={b => this.props.Actions(b.target.name)}>+</button>
          </div>
         </div>
         <div id="time">
            <p id="timer-label">{this.props.indicating}</p>
            <p id="time-left">{this.props.minutes}:{this.props.seconds}</p>
         </div>
          <div id="controls">
            <button id="start_stop" name="STARTSTOP" onClick={b => this.props.Actions(b.target.name)}>
            Start/Stop
            </button>
            <button id="reset" name="RESET" onClick={b => this.props.Actions(b.target.name)}>Reset</button>
          </div>
        </div>
     </div>
    )
  }
}
      
ReactDOM.render(<Clock />, document.getElementById('root'));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console