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 rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">

<div id="root" />
              
            
!

CSS

              
                body{
  background-color: #6ed3cf;
  font-family: 'Poppins', sans-serif;
}

.incrementer{
  border-radius: 20px;
  border:none;
  width: 25px;
  height: 25px;
  position: relative;
  top: 20px;
  background-color: #c62131;
}

.incrementer-left{
  left:-20px;
}

.incrementer-right{
  left:20px;
}

.incrementer-group{
  position: relative;
  border-radius: 25px;
  background-color: #e62739;
}
  
#title{
  text-align: center
}

#Incrementers{
  position: relative;
  padding: 30px;
  padding-top: 0px;
  top:-20px;
  text-align: center;
}

#Break,#Session{
  display: flex;
  display: inline-block;
  padding: 50px;
}

#Break *,#Session *{
  float: left
}

#Timer{
  position: relative;
  top: -50px;
  text-align: center;
  margin: 0 auto;
  background: #5aadaa;
  width: 400px;
  height: 153px;
  border-radius: 40px;
}

#reset{
  background-color: #9068be;
  height:35px;
  width: 80px;
  margin-left: 20px;
  margin-right: 20px;
  border-radius:10px;
  border: none;
}

#start_stop{
  background-color: #9068be;
  height:35px;
  width: 80px;
  margin-left: 20px;
  margin-right: 20px;
  border-radius:10px;
  border: none;
}

#time-left{
  position: relative;
  font-size:40px;
  top: -35px;
  margin-bottom: -25px;
}

@media only screen and (max-width: 1000px) {
  #Incrementers{
    top: -40px;
  }
  #Session{
    position: relative;
    top: -60px;
  }
  #Timer{
    top: -130px;
    margin-bottom: -130px;
  }
}
              
            
!

JS

              
                class App extends React.Component{
	constructor(props) {
    super(props)
    this.state = {
      BreakLength: 5,
      SessionLength: 25,
      State: "Session",
      running: true,
      timeDisplayed: "25:00",
      currentSecondsLeft: 0,
      currentMinutesLeft: 25
      }
    this.changeBreak = this.changeBreak.bind(this)
    this.changeSession = this.changeSession.bind(this)
    this.reset = this.reset.bind(this)
    this.countDown = this.countDown.bind(this)
    this.myTimer = this.myTimer.bind(this)
    this.myVar = this.myVar.bind(this)
    this.playAudio = this.playAudio.bind(this)
  }
  
  playAudio(){
    var audio = new Audio("https://goo.gl/65cBl1")
    audio.play()
  }
  
  changeBreak(number){
    let value = this.state.BreakLength
    value += number
    if (value >= 1 && value <= 60){
      this.setState({BreakLength:value})
      if(this.state.State == "Break"){
        if (value.toString().length < 2){
          returnString = "0" + value + ":" + "00"
        } else {
          returnString = "" + value + ":" + "00"
        }
        let returnNum = Number(value)
        this.setState({timeDisplayed:returnString,currentMinutesLeft:returnNum,currentSecondsLeft: 0})
      }
    }
  }
  
  changeSession(number){
    let value = this.state.SessionLength
    value += number
    if (value >= 1 && value <= 60){
      this.setState({SessionLength:value})
      if(this.state.State == "Session"){
        let returnString = ""
        if (value.toString().length < 2){
          returnString = "0" + value + ":" + "00"
        } else {
          returnString = "" + value + ":" + "00"
        }
        let returnNum = Number(value)
        this.setState({timeDisplayed:returnString,currentMinutesLeft:returnNum,currentSecondsLeft: 0})
      }
    }
  }
  
  reset(){
    this.setState({BreakLength:5,
      SessionLength:25,
      State: "Session",
      running: false,
      timeDisplayed:"25:00",
      currentMinutesLeft:25,
      currentSecondsLeft:0})
    if(this.interval){
      clearInterval(this.interval)
    }
  }
  
  myTimer(){
    let returnString = ""
    console.log("I'm in.")
    if (this.state.running == true){
      console.log("Nah.")
      clearInterval(this.interval)
    } else if (this.state.State == "Session" && this.state.currentSecondsLeft == 0 && this.state.currentMinutesLeft == 0){
      this.playAudio()
      let newTime = this.state.BreakLength
      let newMins = newTime.toString()
      let newTimeDisplayed = ""
      if (newMins.length > 1){
        newTimeDisplayed = newTime.toString() + ":" + "00"
      } else {
        newTimeDisplayed = "0" + newTime.toString() + ":" + "00"
      }
        this.setState({State:"Break",timeDisplayed:newTimeDisplayed,currentMinutesLeft:newTime,currentSecondsLeft:0})
    } else if (this.state.State == "Break" && this.state.currentSecondsLeft == 0 && this.state.currentMinutesLeft == 0){
      this.playAudio()
      let newTime = this.state.SessionLength
      let newMins = newTime.toString()
      let newTimeDisplayed = ""
      if (newMins.length > 1){
        newTimeDisplayed = newTime.toString() + ":" + "00"
      } else {
        newTimeDisplayed = "0" + newTime.toString() + ":" + "00"
      }
      this.setState({State:"Session",timeDisplayed:newTimeDisplayed,currentMinutesLeft:newTime,currentSecondsLeft:0})
    } else if (this.state.currentSecondsLeft == 0){
      let newSeconds = 59
      let newMins = this.state.currentMinutesLeft -= 1
      let newMinsString = ""
      if (newMins.toString().length > 1){
        newMinsString = newMins.toString()
      } else {
        newMinsString = "0" + newMins.toString()
      }
      returnString = newMinsString + ":" + newSeconds.toString()
      this.setState({currentSecondsLeft:newSeconds,currentMinutesLeft:newMins,timeDisplayed:returnString})
      console.log("Now I'm 2.")
    } else {
      let newSeconds = this.state.currentSecondsLeft - 1
      let newSecondsString = newSeconds.toString()
      if (newSecondsString.length <= 1){
        newSecondsString = "0" + newSeconds.toString()
      }
      let newMinutesString = this.state.currentMinutesLeft.toString()
      if (newMinutesString.length <= 1){
        newMinutesString = "0" + this.state.currentMinutesLeft.toString()
      }
      returnString = newMinutesString + ":" + newSecondsString
      this.setState({currentSecondsLeft:newSeconds,timeDisplayed:returnString})
      console.log("Now I'm in 3.")
    }
    
  }
  
  myVar(){
    this.interval = setInterval(this.myTimer,1000)
  }
  
  
  
  countDown(){
    console.log(this.state.running)
    let newThing = !this.state.running
    this.setState({running:newThing})
    console.log(this.state.running)
    if(this.state.running){
      this.myVar()
    }
}
  
	render(){
    return(
    <div>
      <h1 id="title">Pomodoro Clock</h1>
      <div id="Incrementers">
		      <div id="Break"><Incrementer onIncrement={() => this.changeBreak(1)} onDecrement={() => this.changeBreak(-1)} length={this.state.BreakLength} label="break-label" spanLabel="break-length" signifier="Break" title="Break Length" increment="break-increment" decrement="break-decrement" /></div>
          <div id="Session"><Incrementer onIncrement={() => this.changeSession(1)} onDecrement={() => this.changeSession(-1)} length={this.state.SessionLength} label="session-label" spanLabel="session-length" signifier="Session" title="Session Length" increment="session-increment" decrement="session-decrement" /></div>
      </div>
      <Timer countDown={this.countDown} timeDisplayed={this.state.timeDisplayed} reset={() => this.reset()} mode={this.state.State} />
    </div>
    )
	}
}

function Incrementer(props) {
	return (
    <div class="incrementer-group">
      <button class="incrementer incrementer-left" onClick={props.onIncrement} id={props.increment}><i class="fa fa-arrow-up" aria-hidden="true"></i></button>
      <h3 id={props.label}>{props.signifier} Length: {props.length} Minutes</h3>
      <button class="incrementer incrementer-right" onClick={props.onDecrement} id={props.decrement}><i class="fa fa-arrow-down" aria-hidden="true"></i></button>
    </div>
  )
}

function Timer(props){
  return(
    <div id="Timer">
      <h2 id="timer-label">{props.mode}</h2>
      <p id="time-left">{props.timeDisplayed}</p>
      <button onClick={props.countDown} id="start_stop">Start/Stop</button>
      <button onClick={props.reset} id="reset">Reset</button>
    </div>
  )
}


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

              
            
!
999px

Console