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

              
                <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono" rel="stylesheet" type="text/css">>

<div id="app">
</div>
              
            
!

CSS

              
                body{
  background-color:black;
  button{
    color:black;
    background: none;
    outline: none;
    border: none;
  }
  button:hover{
    color: #34d2d2;
  }
}



.container{
  border: 2px solid black;
  width:414px;
  height:819px;
  margin:auto;
  font-family:IBM Plex Mono;
  background-color:#D23434;
}

#titlecard{
  margin-top: 73px;
}

#title{
  text-align:center;
  font-size:36px;
  text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
}

#setters{
  margin-top: 103px;
  margin-left: 53px;
  font-size:23px;
  margin-right:60px;
  text-align:center;
  h3{
    font-family: IBM Plex Mono;
    font-style: normal;
    font-weight: 500;
    font-size: 24px;
    line-height: 31px;
    text-align: center;
  }
  i{
    font-size:30px;
  }
}

#session{
  float:right;
}

#break{
  float:left;
}
#timer{
  margin-top:313px;
  text-align:center;
  border: 4px solid black;
  border-radius: 21px;
  margin-left:43px;
  margin-right:43px;
}

#play-pause{
  text-align:center;
  margin-top:10px;
  i{
    font-size:30px;
  }
}

#start_stop{
  
}


              
            
!

JS

              
                let x;


class App extends React.Component{
  constructor(props){
    super(props);
    this.cycle = undefined;
    this.state = {
      breakLength: 5,
      sessionLength: 25,
      timer:  25*60,
      paused: true,
      session: 'Session'
    }
    this.handleBreakLength = this.handleBreakLength.bind(this);
    this.handleSessionLength = this.handleSessionLength.bind(this);
    this.format = this.format.bind(this);
    this.countDown = this.countDown.bind(this);
    
    this.reset = this.reset.bind(this);
    this.cycle = undefined;
    this.switchSession = this.switchSession.bind(this);
    this.toggleColor = this.toggleColor.bind(this);
    this.beep = this.beep.bind(this);
  }
  
  componentWillUnmount() {
    clearInterval(this.cycle);
  }
  
  handleBreakLength(e){
    if(this.state.paused == false){
      return
    }
    let value = e.currentTarget.id;
    //if up arrow increase breakLength by 1 
    if(value == 'break-increment'){
      if(this.state.breakLength < 60){
        this.setState({
          breakLength: this.state.breakLength + 1
        })
      }  
    }
    // if down arrow decrease breakLength by 1 
    else{
      //Make sure breakLength doesn't go below 1
      if(this.state.breakLength > 1){
        this.setState({
          breakLength: this.state.breakLength - 1
          
        })
      }
    }
  }
  
  handleSessionLength(e){
    if(this.state.paused === false){
      return
    }
    let value = e.currentTarget.id;
    //if up arrow increase sessionLength by 1 
    if(value == 'session-increment'){
      if(this.state.sessionLength < 60){
        this.setState({
          sessionLength: this.state.sessionLength + 1,
          timer: this.state.timer + 60
        })
      }
    }
    // if down arrow decrease sessionLength by 1 
    else{
      //Make sure sessionLength doesn't go below 1
      if(this.state.sessionLength > 1){
        this.setState({
          sessionLength: this.state.sessionLength - 1,
          timer: this.state.timer - 60
        })
      }
    }
  }
  
  toggleColor(){
    let div = document.getElementsByClassName('container');
    if(this.state.session == 'Break'){
      div[0].style.backgroundColor = '#D23434'
      this.setState({
        session: 'Session'
      })
    }
    else{
      div[0].style.backgroundColor = '#32CD32'
      this.setState({
        session: 'Break'
      })
    }
  }
  
  switchSession(){
    if(this.state.session === 'Session'){
      this.setState({
        timer: this.state.breakLength * 60
      })
      this.toggleColor();
    }
    else{
      this.setState({
        timer: this.state.sessionLength * 60
      })
      this.toggleColor();
    }
  }
  
  
  countDown(){
    if(this.state.paused === false){
      clearInterval(this.cycle);
      this.setState({
        paused: true
      })
    }
    else{
      this.setState({
        paused: false
      });
      
      this.cycle = setInterval(() =>{
        if(this.state.timer === 0){
          this.setState({
            session: (this.state.session === 'Session') ? 'Break' : 'Session',
            timer: (this.state.session === 'Session') ? (this.state.breakLength * 60) : (this.state.sessionLength * 60)
          });
          //this.switchSession();
          this.beep();
        }
        else{
          this.setState({
            timer: this.state.timer - 1
          })
        }
        
      }, 1000)
    }
  }
  
  
  reset(){
    this.setState({
      breakLength: 5,
      sessionLength: 25,
      timer: 1500,
      paused: true,
      session: 'Session'
    })
    this.audioBeep.pause();
    this.audioBeep.currentTime = 0;
    let div = document.getElementsByClassName('container');
    div[0].style.backgroundColor = '#D23434';
    clearInterval(this.cycle);
  }
  
  beep(){
    this.audioBeep.play()
  }
  
  //Convert timer into minutes:seconds that people can see
  format(g){
    let minutes = Math.floor(g / 60);
    let seconds = g % 60;
    
    seconds = seconds < 10 ? '0'+seconds : seconds;
    minutes = minutes < 10 ? '0'+minutes : minutes;
    return minutes+':'+seconds;
  }
  
  render(){
    return (
      <div className = "container">
        <div id="titlecard">
          <h1 id="title"> Pomodoro Clock </h1>
        </div>
        <Controllers changeBreak={this.handleBreakLength} 
                     breakLength={this.state.breakLength}
                     changeSess={this.handleSessionLength}
                     sessionLength={this.state.sessionLength}
          />
        <Timer format = {this.format(this.state.timer)}
               session ={this.state.session}/>
        <Play  countDown = {()=>this.countDown()} 
               reset = {()=>this.reset()}/>
        
        <audio src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/audio/BeepSound.wav"
               id="beep"
               ref={(audio) => {
            this.audioBeep = audio;
          }}
          ></audio>
      </div>
    )
  }
}

class Controllers extends React.Component{
  render(){
    return(
    <div id = "setters">
      <div id="break">
        <h3 id="break-label">Break <br/>  Length</h3>
        <button id="break-increment" onClick={this.props.changeBreak} value="plus"><i class="fas fa-arrow-up"></i></button>
        <span id="break-length">{this.props.breakLength}</span>
        <button id="break-decrement" onClick={this.props.changeBreak} value="minus"><i class="fas fa-arrow-down"></i></button>
      </div>
      <div id="session">
        <h3 id="session-label">Session <br/> Length</h3>
        <button id="session-increment" onClick={this.props.changeSess}><i class="fas fa-arrow-up"></i></button>
        <span id="session-length">{this.props.sessionLength}</span>
        <button id="session-decrement" onClick={this.props.changeSess}><i class="fas fa-arrow-down"></i></button>
      </div>
    </div>
    )
  }
}

class Timer extends React.Component{
  render() {
    return(
      <div id="timer">
        <h1 id="timer-label" > {this.props.session} </h1>
        <h2 id="time-left"> {this.props.format} </h2>
      </div>
    )
  }
}

class Play extends React.Component{
  render(){
    return(
      <div id ="play-pause">
        <div id="start_stop">
          <button onClick={this.props.countDown} >
            <i class="fas fa-play"></i>
            <i class="fas fa-pause"></i>
          </button>
          <button id="reset" onClick={this.props.reset}><i class="fas fa-sync"></i></button>
        </div>
      </div>
    )
  }
}

ReactDOM.render(<App/>, document.getElementById('app'))
              
            
!
999px

Console