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

              
                <main>
  <div id="typing-div">
    <h1 id="typing-text">25 + 5 Timer!</h1>
  </div>
  <div id="root"><!-- All the React code goes here! --></div>
</main>
              
            
!

CSS

              
                * {
  padding: 0;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background-color: #E0E0E0;
  color: #676A8B;
  font-family: sans-serif;
  user-select: none;
}

main {
  display: grid;
  text-align: center;
  justify-items: center;
  margin: auto;
}

#typing-div {
  margin-bottom: 10px;
  padding: 5px;
}

#typing-text {
  font-family: monospace;
  position: relative;
}

#typing-text::before,::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

#typing-text::before {
  content: '';
  background-color: #E0E0E0;
  animation: typing 6s steps(13) 1s forwards;
}

#typing-text::after {
  content: '';
  background-color: black;
  min-width: 2px;
  max-width: 2px;
  animation: cursor 6s steps(13) 1s forwards, blink 750ms ease infinite;
}

#root {
  padding: 30px;
}

#timing-info {
  padding: 10px;
  margin-bottom: 30px;
  display: flex;
  flex-direction: row;
  width: 35vw;
  min-width: 370px;
  border-radius: 100px;
  box-shadow: 0px 0px 6px 6px gray;
}

.timing-info {
  display: flex;
  flex-direction: column;
  text-align: center;
  align-items: center;
  justify-content: center;
  padding: 10px;
  margin: auto;
}

.time-control {
  display: flex;
  flex-direction: row;
  text-align: center;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

#break-label {
  padding: 5px;
}

#session-label {
  padding: 5px;
}

/* Button IDs should be here if you need them! */

#break-length {
  padding: 5px;
  margin-left: 10px;
  margin-right: 10px;
}

#session-length {
  padding: 5px;
  margin-left: 10px;
  margin-right: 10px;
}

.transparentButton {
  background-color: transparent;
  padding: 5px;
  justify-self: center;
  align-self: center;
  border: none;
  transition: 0.5s;
  width: 40px;
  border-radius: 50px;
  box-shadow: 0px 0px 1px 1px gray;
}

.transparentButton:hover {
  box-shadow: 0px 0px 4px 4px gray;
}

i {
  color: #5C5E7C;
  transition: 0.2s;
}

#timer-info {
  padding: 10px;
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 100px;
  box-shadow: 0px 0px 6px 6px gray;
}

#time-control2 {
  padding: 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 100px;
  box-shadow: 0px 0px 6px 6px gray;
}

#start_stop {
  margin: auto;
  width: 80px;
}

#reset {
  margin: auto;
}

@keyframes typing {
  to {
    left: 100%;
  }
}

@keyframes cursor {
  to {
    left: 100%;
  }
}

@keyframes blink {
  0% {
    opacity: 0;
  }
  
  50% {
    opacity: 0;
  }
  
  100% {
    opacity: 1;
  }
}
              
            
!

JS

              
                class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      breakLength: 5,
      sessionLength: 25,
      currentActivity: "Session",
      timeLeft: "",
      running: false,
      style: { }
    }
    
    this.intervalID = null
    
    this.handleBreakDecrement = this.handleBreakDecrement.bind(this)
    this.handleBreakIncrement = this.handleBreakIncrement.bind(this)
    this.handleSessionDecrement = this.handleSessionDecrement.bind(this)
    this.handleSessionIncrement = this.handleSessionIncrement.bind(this)
    this.handleReset = this.handleReset.bind(this)
    this.handleStartStop = this.handleStartStop.bind(this)
  }
  
  componentDidMount() {
    this.setState({timeLeft: this.state.sessionLength.toString() + ":00"})
  }
  
  handleBreakDecrement() {
    if(!this.state.running) {
      if(this.state.currentActivity === "Break") {
        if(this.state.breakLength > 1) {
          
          let displayBreak = this.state.breakLength - 1 < 10 ? "0" + (this.state.breakLength - 1).toString() : (this.state.breakLength - 1).toString()
          
          this.setState(prevState => {return {breakLength: prevState.breakLength - 1, timeLeft: displayBreak + ":00"}})
        }
      } else {
        if(this.state.breakLength > 1) {
          this.setState(prevState => {return {breakLength: prevState.breakLength - 1}})
        }
      }
    }
  }
  
  handleBreakIncrement() {
    if(!this.state.running) {
      if(this.state.currentActivity === "Break") {
        if(this.state.breakLength <= 59) {
          
          let displayBreak = this.state.breakLength + 1 < 10 ? "0" + (this.state.breakLength + 1).toString() : (this.state.breakLength + 1).toString()
          
          this.setState(prevState => {return {breakLength: prevState.breakLength + 1, timeLeft: displayBreak + ":00"}})
        }
      } else {
        if(this.state.breakLength <= 59) {
          this.setState(prevState => {return {breakLength: prevState.breakLength + 1}})
        }
      }
    }
  }
  
  handleSessionDecrement() {
    if(!this.state.running) {
      if(this.state.currentActivity === "Session") {
        if(this.state.sessionLength > 1) {
          
          let displaySession = this.state.sessionLength - 1 < 10 ? "0" + (this.state.sessionLength - 1).toString() : (this.state.sessionLength - 1).toString()
          
          this.setState(prevState => {return {sessionLength: prevState.sessionLength - 1, timeLeft: displaySession + ":00"}})
        }
      } else {
        if(this.state.sessionLength > 1) {
          this.setState(prevState => {return {sessionLength: prevState.sessionLength - 1}})
        }
      }
    }
    
  }
  
  handleSessionIncrement() {
    if(!this.state.running) {
      if(this.state.currentActivity === "Session") {
        if(this.state.sessionLength <= 59) {
          
          let displaySession = this.state.sessionLength + 1 < 10 ? "0" + (this.state.sessionLength + 1).toString() : (this.state.sessionLength + 1).toString()
          
          this.setState(prevState => {return {sessionLength: prevState.sessionLength + 1, timeLeft: displaySession + ":00"}})
        }
      } else {
        if(this.state.sessionLength <= 59) {
          this.setState(prevState => {return {sessionLength: prevState.sessionLength + 1}})
        }
      }
    }
  }
  
  handleReset() {
    let beep = document.getElementById("beep")
    beep.pause()
    beep.currentTime = 0
    clearInterval(this.intervalID)
    this.setState({breakLength: 5, sessionLength: 25, currentActivity: "Session", timeLeft: "25:00", running: false, style: { }})
  }
  
  handleStartStop() {
    if(!this.state.running) {
      this.intervalID =  setInterval(() => {
        let time = (parseInt(this.state.timeLeft.substring(0, 2)) * 60) + parseInt(this.state.timeLeft.substring(3, 5))
        time--
        if(time <= 60) {
          this.setState({style: {color: "#a50d0d"}})
        } else {
          this.setState({style: {color: "#676A8B"}})
        }
        if(time < 0) {
          let beep = document.getElementById("beep")
          beep.currentTime = 0
          beep.play()
          if(this.state.currentActivity === "Session") {
            
            let displayBreak = this.state.breakLength < 10 ? "0" + this.state.breakLength.toString() : this.state.breakLength.toString()
            
            this.setState({currentActivity: "Break", timeLeft: displayBreak + ":00", running: true})
            return
          } else {
            
            let displaySession = this.state.sessionLength < 10 ? "0" + this.state.sessionLength.toString() : this.state.sessionLength.toString()
            
            this.setState({currentActivity: "Session", timeLeft: displaySession + ":00", running: true})
            return
          }
        } else {
          let minutes = Math.floor(time / 60)
          let seconds = Math.round(time % 60)
          minutes = minutes < 10 ? '0' + minutes.toString() : minutes.toString()
          seconds = seconds < 10 ? '0' + seconds.toString() : seconds.toString()
          this.setState({timeLeft: minutes.toString() + ":" + seconds.toString(), running: true})
        }
      }, 1000)
    } else {
      clearInterval(this.intervalID)
      this.setState({running: false})
    }
  }
  
  render() {
    return (
      <div>
        <div id="timer-info" style={this.state.style}>
          <h2 id="timer-label">{this.state.currentActivity}</h2>
          <h2 id="time-left">{this.state.timeLeft}</h2>
        </div>
        <div id="timing-info">
          <div className="timing-info">
            <h3 id="break-label">Break Length</h3>
            <div className="time-control">
              <button id="break-decrement" className="transparentButton" onClick={this.handleBreakDecrement}><i className="fa fa-arrow-down fa-2x"></i></button>
              <h3 id="break-length">{this.state.breakLength}</h3>
              <button id="break-increment" className="transparentButton" onClick={this.handleBreakIncrement}><i className="fa fa-arrow-up fa-2x"></i></button>
            </div>
          </div>
          <div className="timing-info">
            <h3 id="session-label">Session Length</h3>
            <div className="time-control">
              <button id="session-decrement" className="transparentButton" onClick={this.handleSessionDecrement}><i className="fa fa-arrow-down fa-2x"></i></button>
              <h3 id="session-length">{this.state.sessionLength}</h3>
              <button id="session-increment" className="transparentButton" onClick={this.handleSessionIncrement}><i className="fa fa-arrow-up fa-2x"></i></button>
            </div>
          </div>
        </div>
        <div id="time-control2">
          <button id="start_stop" className="transparentButton" onClick={this.handleStartStop}><i className="fa fa-play fa-2x"></i><i className="fa fa-pause fa-2x"></i></button>
          <button id="reset" className="transparentButton" onClick={this.handleReset}><i className="fa fa-sync-alt fa-2x"></i></button>
        </div>
        <audio id="beep" src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/audio/BeepSound.wav"></audio>
      </div>
    )
  }
}


ReactDOM.render(<App />, document.getElementById("root"))
              
            
!
999px

Console