Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="app">
</div>

              
            
!

CSS

              
                #app {
  display: flex;
  justify-content: center;
  //justify-content: space-around;
  align-items: center;
  height: 100vh;
  text-align: center;
}

h2 {
    font-size: 40px;
    &::before {
      content:'\f2f2';
	    font-family:'Font Awesome 5 Free';
	    font-weight: 900;
      position: relative;
      color: #00796B;
      right: 8px;
    }
    margin-bottom: 0px;
  }

#container {
  border: solid 10pt #D7CCC8;
  border-radius: 20px;
  padding: 30px;
  margin-top: 4px;;
}

button {
  padding: 12px;
  border-radius: 8px;  
}

#startButton::before {
	content:'\f0da';
	font-family:'Font Awesome 5 Free';
	font-weight: 900;
  position: relative;
  right: 4px;
}

#stopButton::before {
	content:'\f04c';
	font-family:'Font Awesome 5 Free';
	font-weight: 900;
  position: relative;
  right: 4px;
}

#reset::before {
  content:'\f2f1';
	font-family:'Font Awesome 5 Free';
	font-weight: 900;
  position: relative;
  right: 4px;
}

#break-decrement::before, #session-decrement::before {
  content:'\f068';
	font-family:'Font Awesome 5 Free';
	font-weight: 900;
}

#break-increment::before, #session-increment::before {
  content:'\f067';
	font-family:'Font Awesome 5 Free';
	font-weight: 900;
}

button.running {
  color: red;
}

button.stop {
  color: blue;
}

span.hide {
  display: none;
}

span.show {
  display: block;
}

.label {
  font-size: 20pt;
  font-weight: bold;
}

#time-left {
  font-size: 40pt;
  font-weight: bold;
}

#timer-container {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: solid 1pt #D7CCC8;
  display: grid;
  align-items: center;
  justify-content: center;
}

.innerContainer {
  display: grid;
  align-items: center;
  justify-content: center;
  grid-template-columns: repeat(2, 1fr); 
  justify-items: center;
}

.lengthContainer {
  display: grid;
  align-items: center;
  justify-content: center;
  grid-template-columns: repeat(3, 1fr); 
  justify-items: center;
}

#session-container, #break-container {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: solid 1pt #D7CCC8;
  display: grid;
  align-items: center;
  justify-content: center;
  grid-template-columns: repeat(2, 1fr); 
  justify-items: center;
  grid-gap: 1px;
  grid-column-gap: 2px;
}
              
            
!

JS

              
                
const projectName = 'pomodoro-clock';
localStorage.setItem('example_project', 'Pomodoro Clock');

const STOP_STATE = 'stop'
const RUNNING_STATE = 'running'
const SESSION_LABEL = 'Session'
const BREAK_LABEL = 'Break'

const INITIAL_STATE = {
      breakLabel: 'Break Length',
      sessionLabel: 'Session Length',
      timerLabel: SESSION_LABEL,
      breakLength: 5,
      sessionLength: 25,
      timerState: STOP_STATE,
      intervalID: '',
      timerCount: 0
    }

class MyApp extends React.Component {
  constructor(props) {
    super(props);
    this.state = INITIAL_STATE
    this.resetTimer = this.resetTimer.bind(this)
    this.incrementSession = this.incrementSession.bind(this)
    this.decrementSession = this.decrementSession.bind(this)
    this.controllTimer = this.controllTimer.bind(this)
    this.decrementBreak = this.decrementBreak.bind(this)
    this.incrementBreak = this.incrementBreak.bind(this)
    
    this.startCountDown = this.startCountDown.bind(this)
    this.countUp = this.countUp.bind(this)
    this.calculateRest = this.calculateRest.bind(this)
    this.stopCountDown = this.stopCountDown.bind(this)
    this.zeroPadding = this.zeroPadding.bind(this)
  }
  
  decrementBreak() {
    let currentVal = this.state.breakLength
    if (currentVal > 1) { currentVal-- }
    this.setState({ breakLength: currentVal })
  }
  
  incrementBreak() {
    let currentVal = this.state.breakLength
    if (currentVal < 60) { currentVal++ }
    this.setState({ breakLength: currentVal })    
  }
  
  resetTimer() {
    console.log('resetTimer!')
    const audioItem = document.getElementById('beep')
    audioItem.pause()
    audioItem.currentTime = 0
    this.stopCountDown()
    this.setState(INITIAL_STATE)
  }
  
  incrementSession() {
    let currentVal = this.state.sessionLength
    if (currentVal < 60) { currentVal++ }
    this.setState({ sessionLength: currentVal })
  }
  
  decrementSession() {
    let currentVal = this.state.sessionLength
    if (currentVal > 1) { currentVal-- }
    this.setState({ sessionLength: currentVal })
  }
  
  stopCountDown() {
     this.setState({ timerState: STOP_STATE })
     console.log(this.state.intervalId)
     clearInterval(this.state.intervalId)
  }
  
  startCountDown() {
    this.timerId = setInterval(this.countUp, 1000)
    this.setState({intervalId: this.timerId})
  }
  
  calculateRest() {
    return (this.state.sessionLength * 60) - this.state.timerCount
  }
  
  // return array
  restTimer() {
    const rest = this.calculateRest()
    let min = Math.floor(rest / 60)
    let sec = rest % 60
    return [this.zeroPadding(2, min), this.zeroPadding(2, sec)] 
  }
  
  zeroPadding(len, val) {
    return (Array(len).join('0') + val ).slice(-len)
  }
  
  countUp() {
    const timerCount = this.state.timerCount + 1
    const rest = this.calculateRest()
    this.setState({ timerCount: timerCount})
    this.setState({ timerRest: rest })
    if (rest === 0) {
      const currentLabel = this.state.timerLabel
      this.resetTimer()
      if (currentLabel == SESSION_LABEL) {
        this.setState({sessionLength: this.state.breakLength})
        this.setState({ timerLabel: BREAK_LABEL })
      } else {
        this.setState({sessionLength: this.state.sessionLength})
        this.setState({ timerLabel: SESSION_LABEL })        
      }
      this.beepSound()
      this.controllTimer()
    }
  }
  
  
  controllTimer() {
    if (this.state.timerState == STOP_STATE) {
      this.setState({ timerState: RUNNING_STATE })
      this.startCountDown()
    } else {
      this.stopCountDown()
    }
  }
  
  beepSound() {
   const audioItem = document.getElementById('beep')
   audioItem.play().then(() => {
      // Automatic playback started!
   }).catch((error) => {
     // Automatic playback failed.
     // Show a UI element to let the user manually start playback.
   })
 }
  
  render () {
    const timerState = this.state.timerState
    let startStyle = (timerState == RUNNING_STATE ? 'hide' : 'show')
    let stopStyle = (timerState == STOP_STATE ? 'hide' : 'show')
    let restTimer = this.restTimer()
    let sessionLabel = SESSION_LABEL
    return (
      <div id='wrapper'>
      <h2>Pomodoro Clock</h2>
      <div id="container">
        <div id="timer-container">
          <div id="timer-label" className='label'>{this.state.timerLabel}</div>
          <div id="time-left">{restTimer[0]}:{restTimer[1]}</div>
          <div className="innerContainer">
            <button id="start_stop" onClick={this.controllTimer} className={this.state.timerState}>
            <audio id="beep" preload="auto" 
          src="https://goo.gl/65cBl1" />
              <span id='startButton' className={startStyle}>Start</span>
              <span id='stopButton' className={stopStyle}>Stop</span>
            </button>
            <button id='reset' onClick={this.resetTimer}>Reset</button>  
          </div>
        </div>
         <div id="break-container">
          <div id='break-label' className='label'>{this.state.breakLabel}</div>
           <div className="lengthContainer">
            <button id='break-decrement' onClick={this.decrementBreak}></button>
            <div id="break-length">{this.state.breakLength}</div>
             <button id='break-increment' onClick={this.incrementBreak}></button>
           </div>
        </div>
        <div id="session-container">
          <div id='session-label' className='label'>{this.state.sessionLabel}</div>
          <div className="lengthContainer">
            <button id='session-decrement' onClick={this.decrementSession}></button>
            <div id="session-length">{this.state.sessionLength}</div>
            <button id='session-increment' onClick={this.incrementSession}></button>
          </div>
        </div>
      </div>
     </div>
    )
  }
}

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

Console