Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="timer"></div>


              
            
!

CSS

              
                body {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-family: Arial;
}

#timer-conteiner {
  display: grid;
  grid-template-columns:  1fr 1fr;  
  grid-template-rows: 70px 70px;
  padding: 0px 40px 10px 40px;
  border: solid black;
  border-radius: 10px;
  border-width: 5px;
  margin-top: 100px;
  min-width: 320px;
}

#break-conteiner, #session-conteiner, #timer, #control-timer {
  border: ;
} 

#break-label, #session-label {
  
}

#session-length, #break-length {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  height: 25px;
}

#header-text, #timer,  #control-timer {
  grid-column-start: 1; 
  grid-column-end: 3;
}

#break-conteiner, #session-conteiner {
  display: grid;
  grid-template-columns:  1fr 1fr 1fr;  
  grid-template-rows: 23px 23px 23px ;
 
}

#break-label, #session-label {
  grid-column-start: 1; 
  grid-column-end: 4;
  font-size: 20px;
  word-break:break-all;
}

#control-timer {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

#timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  
}

button {
  background: none;
	color: inherit;
	border: none; 
  color: black;
}

button:active {
 color: grey;
}

svg {
  color: white;
  background-color: red
}

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

#time-left {
  font-size: 50px;
}

@media (min-width:320px)  { 
  #timer-conteiner {
  padding: 0px 20px 10px 20px;
  }
  

@media (min-width:600px)  { 
#timer-conteiner {
  padding: 0px 25px 10px 25px;
  }
}
@media (min-width:801px)  { #break-label, #timer-conteiner {
  padding: 0px 30px 10px 30px;
  }
}
@media (min-width:1025px) { #break-label, #timer-conteiner {
  padding: 0px 35px 10px 35px;
  }
}
@media (min-width:1281px) { #break-label, #timer-conteiner {
  padding: 0px 40px 10px 40px;
  }
}
              
            
!

JS

              
                class Timer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {      
    breakMinutes: 5,
    sessionMinutes: 25,
    timerState: false,
    timerAmount: 1500,
    timerName: 'Session'
    };
    this.decrementBreak = this.decrementBreak.bind(this);
    this.incrementBreak = this.incrementBreak.bind(this);
    this.decrementSession = this.decrementSession.bind(this);
    this.incrementSession = this.incrementSession.bind(this);
    this.reset = this.reset.bind(this); 
    this.intervalSet = this.intervalSet.bind(this);
    this.intervalClear = this.intervalClear.bind(this);
    this.clockInfo = this.clockInfo.bind(this);
    this.playSound = this.playSound.bind(this);
  }
  
  
  playSound() {
    if (this.state.timerAmount < 0) {
      let audio = document.getElementById('beep')
      audio.play();
    }
    
  }
  clockInfo() {
    if (this.state.timerAmount < 0) {
      
      if (this.state.timerName === 'Session') {
        "00:00"
        this.playSound();
        this.setState(state => ({
          timerAmount: this.state.breakMinutes * 60,
          timerName: 'Break'
    }));     
     } else if (this.state.timerName === 'Break') {
       "00:00"
      this.playSound();
      this.setState(state => ({
         timerAmount: this.state.sessionMinutes * 60,
         timerName: 'Session'
    }));
   }
  } else {
    let minutes = Math.floor(this.state.timerAmount / 60);
    let seconds = this.state.timerAmount - minutes * 60;
    seconds = seconds < 10 ? '0' + seconds : seconds;
    minutes = minutes < 10 ? '0' + minutes : minutes;
    return minutes + ':' + seconds;
    }
   }
  
  intervalSet() {
    this.interval = setInterval(() => this.tick(), 1000);
    this.setState(state => ({
      timerState: true
    }));
    }
  
 intervalClear() {
   clearInterval(this.interval);
   this.setState(state => ({
      timerState: false
    }));
   }
 
   decrementBreak() {
   if (this.state.timerState === false && this.state.timerName === 'Session') {
    this.setState(state => ({
      breakMinutes: state.breakMinutes - 1,
    }));
   } else if (this.state.timerState === false && this.state.timerName === 'Break') {
     this.setState(state => ({
      breakMinutes: state.breakMinutes - 1,
      timerAmount: state.breakMinutes * 60 - 60
    }));
   }
  } 
  
   incrementBreak() {
   if (this.state.timerState === false && this.state.timerName === 'Session') {
    this.setState(state => ({
      breakMinutes: state.breakMinutes + 1,
    }));
   } else if (this.state.timerState === false && this.state.timerName === 'Break') {
     this.setState(state => ({
      breakMinutes: state.breakMinutes + 1,
      timerAmount: state.breakMinutes * 60 + 60
    }));
   }
  }
 
   decrementSession() {
    if (this.state.timerState === false && this.state.timerName === 'Session') {
      this.setState(state => ({
      sessionMinutes: state.sessionMinutes - 1,
      timerAmount: state.sessionMinutes * 60 - 60
    }));
   } else if (this.state.timerState === false && this.state.timerName === 'Break') {
     this.setState(state => ({
      sessionMinutes: state.sessionMinutes - 1,
    }));
   }
  }
  
   incrementSession() {
    if (this.state.timerState === false && this.state.timerName === 'Session') {
    this.setState(state => ({
      sessionMinutes: state.sessionMinutes + 1,
      timerAmount: state.sessionMinutes * 60 + 60
    }));
   } else if (this.state.timerState === false && this.state.timerName === 'Break') {
     this.setState(state => ({
      sessionMinutes: state.sessionMinutes + 1,
    }));
   }
  }
  
  soundPlay(time) {
    time = this.state.timerAmount
    if (this.state.timerAmount === 0) {
      this.audioBeep.play();
    }
  }
  
  reset() {
    clearInterval(this.interval)
    this.audioBeep.pause();
    this.audioBeep.currentTime = 0;
    this.setState(state => ({
      breakMinutes: 5,
      sessionMinutes: 25,
      timerState: false,
      timerAmount: 1500,
      timerName: 'Session'
    }));
  }

  tick() {
    this.setState(state => ({
      timerAmount: state.timerAmount - 1
    }));
  }


  render() {

    return (
      <div id="timer-conteiner">
        <h1 id="header-text">25 + 5 Clock</h1>
        <div id="break-conteiner">
          <div id="break-label">Break Length</div>
          
          <button id="break-decrement" onClick={() => {this.state.breakMinutes > 1 ? this.decrementBreak() : this.state.breakMinutes}}><i className="fa fa-minus-circle fa-2x" aria-hidden="true"></i></button>
          <div  id="break-length">{this.state.breakMinutes}</div>
          <button id="break-increment" onClick={() => {this.state.breakMinutes < 60 ? this.incrementBreak() : this.state.breakMinutes}}><i className="fa fa-plus-circle fa-2x" aria-hidden="true"></i></button>
        </div>
        <div id="session-conteiner">
          <div id="session-label">Session Length</div>
          <button id="session-decrement" onClick={() => {this.state.sessionMinutes > 1 ? this.decrementSession() : this.state.sessionMinutes}}><i className="fa fa-minus-circle fa-2x" aria-hidden="true"></i></button>
          <div id="session-length">{this.state.sessionMinutes}</div>
          <button id="session-increment" onClick={() => {this.state.sessionMinutes < 60 ? this.incrementSession() : this.state.sessionMinutes}}><i className="fa fa-plus-circle fa-2x" aria-hidden="true"></i></button>
        </div>
        <div id="timer">
          <div id="timer-label">{this.state.timerName}</div>
          <div  id="time-left" style={this.state.timerAmount < 60 ? { color: 'red' } : { color: 'black' }}>{this.clockInfo()}</div>
        </div>
        <div id="control-timer">
          <div><button id="start_stop" onClick={() => {!this.state.timerState ? this.intervalSet() : this.intervalClear()}}><i className="fa fa-play-circle fa-3x" aria-hidden="true" style={this.state.timerState  === false ? { display: 'initial' } : { display: 'none' }}></i><i class="fa fa-pause-circle fa-3x" aria-hidden="true" style={this.state.timerState  === true ? { display: 'initial' } : { display: 'none' }}></i></button></div>
          <div><button id="reset" onClick={this.reset}><i class="fa fa-refresh fa-3x" aria-hidden="true"></i></button></div>
        </div>
        <audio className="clip" id="beep" preload="auto" 
          ref={(audio) => {
            this.audioBeep = audio;
          }}
          src="https://od.lk/s/MTFfMzQzMTcxMTlf/beep-18%20%281%20sec%29.mp3">
  </audio>
      </div>
    );
  }
}

ReactDOM.render(
	<Timer />,
	document.getElementById('timer')
);
              
            
!
999px

Console