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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<div id='root'></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i');
@import url('https://fonts.googleapis.com/css?family=Orbitron');

@font-face{
    font-family: 'DS-DIGITAL';
    src: url('https://res.cloudinary.com/dzsmdyknz/raw/upload/v1532588680/fcc-drum-machine/ds-digital-font/DS-DIGIT.TTF');
    src: url('https://res.cloudinary.com/dzsmdyknz/raw/upload/v1532588680/fcc-drum-machine/ds-digital-font/DS-DIGIB.TTF');
    src: url('https://res.cloudinary.com/dzsmdyknz/raw/upload/v1532588679/fcc-drum-machine/ds-digital-font/DS-DIGII.TTF');
    src: url('https://res.cloudinary.com/dzsmdyknz/raw/upload/v1532588679/fcc-drum-machine/ds-digital-font/DS-DIGI.TTF');
}

body,
body * {
    margin:          unset;
    box-sizing:      unset;
    padding:         unset; 
    color:           unset;
    text-decoration: unset;
}

body{
  background: white;
  margin: 0;
  width: 100%;
  height: 100vh;
  padding: 3.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  font-family: 'Lato', sans-serif;
}

.mainheader{
  font-weight: 800;
}

#pclock{
  background: orange;
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  padding-left: 1.2em;
  padding-right:1.2em;
  padding: 1em;
  color: white;
  margin: 0rem 0rem 1rem 0rem;
  display: grid;
  width: 100%;
  height: 60vh;
  grid-gap: 1rem;
  
}

.vibrateme{
  animation-name: vibrate;
  animation-duration: 0.5s;
  animation-delay: 0s;
}

@keyframes vibrate{
  0% {
    -ms-transform: rotate(0deg); /* IE 9 */
    -webkit-transform: rotate(0deg); /* Safari */
    transform: rotate(0deg);
  } 
  12.5% {
    -ms-transform: rotate(15deg); /* IE 9 */
    -webkit-transform: rotate(15deg); /* Safari */
    transform: rotate(15deg);
  }
  25%{
    -ms-transform: rotate(0deg); /* IE 9 */
    -webkit-transform: rotate(0deg); /* Safari */
    transform: rotate(0deg);
  }
  37.5%{
    -ms-transform: rotate(-15deg); /* IE 9 */
    -webkit-transform: rotate(-15deg); /* Safari */
    transform: rotate(-15deg);
  }
  50%{
    -ms-transform: rotate(0deg); /* IE 9 */
    -webkit-transform: rotate(0deg); /* Safari */
    transform: rotate(0deg);
  }
  62.5% {
    -ms-transform: rotate(15deg); /* IE 9 */
    -webkit-transform: rotate(15deg); /* Safari */
    transform: rotate(15deg);
  }
  75%{
    -ms-transform: rotate(0deg); /* IE 9 */
    -webkit-transform: rotate(0deg); /* Safari */
    transform: rotate(0deg);
  }
  87.5%{
    -ms-transform: rotate(-15deg); /* IE 9 */
    -webkit-transform: rotate(-15deg); /* Safari */
    transform: rotate(-15deg);
  }
  100%{
    -ms-transform: rotate(0deg); /* IE 9 */
    -webkit-transform: rotate(0deg); /* Safari */
    transform: rotate(0deg);
  }
}

header{
  border-bottom: 2px solid rgba(0,0,0,0.3);
  padding-bottom: 0.5rem;
}

header h1{
  display: flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 400;
  font-family: 'Lato',sans-serif;
  color: rgba(255,255,255,0.3);
}

header h1 span{
  font-size: 1rem;
  margin-right: 0.5rem;
  color: #43A047;
}

main{
  display: grid;
  grid-gap: 1rem;
}

.text-center{
  text-align: center;
}

.counter{
  background: rgba(0,0,0,0.2);
  display: grid;
  grid-gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
}

.counter-label{
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}

.counter-screen{
  background: #00BFA5;
  padding: 0.5rem;
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 4px;
  font-size: 1.25rem;
  font-weight: 600;
  font-family: 'DS-DIGITAL', sans-serif;
}

.counter-controls{
  display: grid;
  grid-template-columns: repeat(2,1fr);
  grid-gap: 0.5rem;
  text-align: center;
  justify-content: space-evenly;
}

.btn{
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 4px;
  cursor: pointer;
  outline: transparent;
  color: rgba(0,0,0,0.6);
  box-shadow: 0px 1px 1px rgba(0,0,0,0.5);
  text-shadow: 0px 1px rgba(255,255,255,0.1);
  text-transform: uppercase;
}

.btn:active{
  font-size: 0.95rem;
  background: transparent;
  box-shadow: 0px 0px 1px rgba(0,0,0,0.5);
}

#clock{
  background: rgba(0,0,0,0.2);
  display: flex;
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
}

#clock-screen{
  background: lightsteelblue;
  align-items: center;
  text-transform: uppercase;
  width: 100%;
  height: auto;
  display: grid;
  justify-content: center;
  border-radius: 4px;
  font-family: 'DS-DIGITAL', sans-serif;
  padding: 1.5rem;
}

#timer-label{
  letter-spacing: 2px;
  padding-bottom: 0.125rem;
}

#time-left{
  font-weight: 600;
  font-size: 2.6rem;
}


#clock-controls{
  background: rgba(0,0,0,0.2);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 0.125rem;
  justify-content: space-evenly;
  padding: 0.125rem;
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
}

.btn-icon{
  font-size: 0.75rem;
  margin: 0 0.5rem;
}


.hidden{
  opacity: 0;
  width: 0;
  height: 0;
}

@media screen and (min-width: 320px){
  #screen{
    grid-template-columns: repeat(2,1fr);
  }
  
  #counter-left{
    grid-column: 1;
  }
  
  #counter-right{
    grid-column: 2;
    grid-row: 1;
  }
  
  #clock{
    grid-column: 1 / -1;
  }
}

@media screen and (min-width: 480px){
  #screen{
    grid-template-columns: 1fr 2fr 1fr;
  }
  
  #counter-left{
    grid-column: 1;
  }
  
  #counter-right{
    grid-column: 3;
    grid-row: 1;
  }
  
  #clock{
    grid-column: 2 ;
  }
}

#debug{
  padding: 5em;
  margin: 0.5rem;
  background: #00BFA5;
  border: 1px solid rgba(0,0,0,0.5);
  border-radius: 6px;
}
.bonn{
  margin-left: 1em;
}
              
            
!

JS

              
                const leftPad = (val)=>{
  if(val<10) return `0${val}`
  return `${val}`
}

// const alarm = document.createElement('audio'); alarm.setAttribute("src", "https://res.cloudinary.com/dzsmdyknz/video/upload/v1536336611/sample-swap/sfx-and-unusual-sounds/electro-and-synthetic/clock_radio_alarm.mp3");



class PomodoroClock extends React.Component{
  
  constructor(props){
    super(props);
    this.state = {
      breaklength: 5,
      sessionlength: 25,
      startTimer: 'stopped',
      timerType: 'Session',
      timer: 1500,
      accInterval: '',
      breaktime: ''
    }
  }
  
 
  
  brkDecrement = () =>{
    const { breaklength, startTimer, timerType, timer } = this.state;
    if(startTimer == 'stopped'){
      if(timerType == 'Break'){
        this.setState({
          breaklength: breaklength !=1? breaklength - 1 : breaklength,
          timer: breaklength * 60 - 60
        });  
      } else {
        this.setState({
          breaklength: breaklength !=1? breaklength - 1 : breaklength
        }); 
      }
      
      this.playAudio();
    }
  }
  
  brkIncrement = () =>{
    const { breaklength, startTimer, timerType, timer } = this.state;
    if(startTimer == 'stopped'){
      if(timerType == 'Break'){
        if(breaklength !=60){
          this.setState({
            breaklength: breaklength + 1,
            timer: breaklength * 60 + 60
          });
        }
        
      } else {
        if(breaklength !=60){
          this.setState({
            breaklength: breaklength + 1
          });
        }
      }
      
      this.playAudio();
    }
  }
  
  sesDecrement = () =>{
    const { sessionlength, startTimer, timerType, timer } = this.state;
    if(startTimer === 'stopped'){
      if(timerType == 'Session'){
        if(sessionlength !=1){
          this.setState({
            sessionlength: sessionlength - 1,
            timer: sessionlength * 60 - 60
          });  
        }
        
      } else {
        if(sessionlength !=1){
            this.setState({
            sessionlength: sessionlength - 1 
          });  
        }
      }
      this.playAudio();  
    }
  }
  
  sesIncrement = () =>{
    const { sessionlength, startTimer, timerType, timer } = this.state;
    if(startTimer == 'stopped'){
      if(timerType == 'Session'){
        if(sessionlength !=60){
          this.setState({
            sessionlength: sessionlength + 1,
            timer: sessionlength * 60 + 60
          });    
        }
        
      } else {
        if(sessionlength !=60){
          this.setState({
            sessionlength: sessionlength + 1
          });   
        }
      }
      
      this.playAudio();  
    }
  }
  
  timerControl = () =>{
    const {startTimer,accInterval} = this.state;
    if(startTimer == 'stopped'){
      this.beginCountdown();
      this.setState({
        startTimer: 'running'
      });
    } 
    if(startTimer == 'running'){
      accInterval && accInterval.cancel();
      this.setState({
        startTimer: 'stopped'
      });
    }
    
    this.playAudio();
  }
  
  beginCountdown = () =>{
    const { breaklength, sessionlength, startTimer, timerType, timer } = this.state;
    this.setState({
       accInterval: accurateInterval(()=>{
         this.decrementTimer();
         this.stageControl();
       },1000)
    })
  }
  
  stageControl = () =>{
    const { breaklength, sessionlength, startTimer, timerType, timer,accInterval } = this.state;
    if(timer < 0){
      if(timerType == 'Session'){
        accInterval && accInterval.cancel();
        this.beginCountdown();
        this.switchTimer(breaklength * 60, 'Break');
      }else if(timerType == 'Break'){
        accInterval && accInterval.cancel();
        this.beginCountdown();
        this.switchTimer(sessionlength * 60, 'Session');
      }
    }
    
    if(timer === 0){
      //const vibration = accurateInterval(()=>'vibrateme',2000);
      this.setState({
        breaktime: 'vibrateme'
      })
      this.playBuzzer.play();
    } else{
      this.setState({
        breaktime: ''
      })
    }
  }
  
  decrementTimer = () =>{
    const { timer } = this.state;
    this.setState({
      timer: timer - 1
    });
  }
  
  switchTimer = (timerLength, timerType) =>{
    this.setState({
      timerType: timerType,
      timer: timerLength
    })
  }
  
  timerReset = () =>{
    const { breaklength, sessionlength, timerType, accInterval } = this.state;
    this.setState({
      breaklength: 5,
      sessionlength: 25,
      startTimer: 'stopped',
      timerType: 'Session',
      timer: 1500,
      accInterval: '',
      breaktime: ''
    });
    accInterval && accInterval.cancel();
    this.playBuzzer.pause();
    this.playBuzzer.currentTime = 0;
    //this.playAudio();
  }
  
  
  playAudio = () =>{
    const keysound = document.getElementById('keysound');
    keysound.currentTime = 0;
    keysound.play();
  }
  
  // playBuzzer = () =>{
  //   const beeper = document.getElementById('beep');
  //   beeper.currentTime = 0;
  //   beeper.play();
  // }
  
  
  render(){
    const { breaklength, sessionlength, startTimer, timerType, timer, breaktime } = this.state;
  
    const min = leftPad(Math.floor(timer / 60));
    const sec = leftPad(timer % 60);

    return (
      <div className='App'>
        <h1 className="text-center mainheader">Pomodoro Clock</h1>
        {/*<div id="debug">
          <pre>
            {JSON.stringify(this.state,null,2)}
          </pre>
        </div>*/}
        <div id="pclock" className={`${breaktime}`}>
  
          <main id="screen" className="row bonn">
            <section id="counter-left" className="counter">
              <p id="break-label" className="text-center counter-label">Break Length</p>
              <div id="break-length" className="text-center counter-screen">{breaklength}</div>
              <div className="counter-controls">
                <button id="break-decrement" className="counter-btn btn" onClick={this.brkDecrement}>-</button>
                <button id="break-increment" className="counter-btn btn" onClick={this.brkIncrement}>+</button>
              </div>
            </section>
            <section id="clock" className="clock">
              <div id="clock-screen">
                <h3 id="timer-label" className="text-center">{timerType}</h3>
                <div id="time-left" className="text-center">{`${min}:${sec}`}</div>
              </div>  
            </section>
            <section id="counter-right" className="counter">
              <p id="session-label" className="text-center counter-label">Session Length</p>
              <div id="session-length" className="text-center counter-screen">{sessionlength}</div>
              <div className="counter-controls">
                <button id="session-decrement" className="counter-btn btn" onClick={this.sesDecrement}>-</button>
                <button id="session-increment" className="counter-btn btn" onClick={this.sesIncrement}>+</button>
              </div>
            </section>
          </main>
          <div id="clock-controls" className="row">
            <button id="start_stop" className="clock-control-btn btn" onClick={this.timerControl}><i class="fas fa-play btn-icon"></i> Play / <i class="fas fa-pause btn-icon"></i>Pause</button>
            <button id="reset" className="clock-control-btn btn" onClick={this.timerReset}><i class="fas fa-sync-alt btn-icon"></i> Reset</button>
          </div>
        </div>  
        <audio id="keysound" className="hidden" src="https://res.cloudinary.com/dzsmdyknz/video/upload/v1533087306/sample-swap/sfx-and-unusual-sounds/bleeps-blips-blonks-blarts-and-zaps/simpletone.mp3"></audio>
        <audio id="beep" preload="auto" className="hidden" src="https://res.cloudinary.com/dzsmdyknz/video/upload/v1536336611/sample-swap/sfx-and-unusual-sounds/electro-and-synthetic/clock_radio_alarm.mp3" ref={(audio)=>{this.playBuzzer=audio;}}></audio>
      </div>
    )
  }
}

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

Console