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

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

CSS

              
                body {
  margin: 0;
  padding: 0;
  background-color: #CCE698;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
  font-family: 'Lato', sans-serif;
  color: #48311E;
  text-align: center;
}

.wrapper {
  margin: 0 auto;
  max-width: 300px;
  height: 100vh;
}

.logo {
  font-size: 28px;
  font-family: 'Fascinate Inline', cursive;
  color: #E62200;
  padding: 10px 5px 20px;
  text-transform: uppercase;
}

.timer-label, .time-left {
  text-align: center;
}

.timer-label {
  font-size: 28px;
  text-transform: uppercase;
}

.time-left {
  font-size: 48px;
  margin-bottom: 20px;
}

.actionBtn {
  border-radius: 10px;
  padding: 5px 10px;
  width: 100px;
  height: 40px;
  line-height: 26px;
  font-size: 20px;
  text-align: center;
  outline: 0;
  cursor: pointer;
  background-color: #8FCA6F;
  border: 2px solid #90623C;
  color: #48311E;
}

.actionBtn:hover {
  border: 2px solid #E62200;
  color: #E62200;
}

.session-label, .break-label {
  padding: 5px;
  font-size: 22px;
}

.row {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-pack: distribute;
      justify-content: space-around;
  -ms-flex-line-pack: center;
      align-content: center;
  padding: 5px 20px;
  margin-bottom: 20px;
}

.settingBtn {
  border-radius: 10px;
  padding: 5px 5px;
  width: 40px;
  height: 40px;
  line-height: 30px;
  font-size: 30px;
  text-align: center;
  outline: 0;
  cursor: pointer;
  background-color: #8FCA6F;
  border: 2px solid #90623C;
  color: #48311E;
}

.row-label {
  font-size: 32px;
}

.footer {
  position: absolute;
  bottom: 15px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 16px;
  color: #48311E;
}

              
            
!

JS

              
                class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      break: 5,
      work: 25,
      label: 'Session',
      intervalID: null,
      currentTime: -1,
      sound: null
      };
  }

  componentDidMount = () => {
    const sound = document.querySelector('audio');
    this.setState({ sound:  sound });
  }

  componentWillUnmount = () => {
    if (this.state.intervalID !== null ) clearInterval(this.state.intervalID);
  }

  timer = () => {
    let time = this.state.currentTime - 1;
    if (time >= 0 ) {
      this.setState({ currentTime: time });
    } else {
      if (this.state.currentTime !== -1) this.state.sound.play();
      let newTime, newLabel;
      if (this.state.label === 'Session') {
        newTime = this.state.break * 60;
        newLabel = 'Break';
      } else {
        newTime = this.state.work * 60;
        newLabel = 'Session';
      }
      this.setState({
        label: newLabel,
        currentTime: newTime
      });
    }
  }

  handleClick = (e) => {
      let target = e.target.id;
      let breakTime = this.state.break;
      let workTime = this.state.work;
      switch(target) {
        case 'session-increment':
          if (workTime < 60) { workTime++; this.setState({ work: workTime }); }
        break;
        case 'session-decrement':
          if (workTime > 1 ) { workTime--; this.setState({ work: workTime }); }
        break;
        case 'break-increment':
          if (breakTime < 60) { breakTime++; this.setState({ break: breakTime }); }
        break;
        case 'break-decrement':
          if (breakTime > 1) { breakTime--; this.setState({ break: breakTime }); }
        break;
        case 'start_stop':
          if(this.state.intervalID === null) {
            let startFrom;
            if (this.state.currentTime === -1) {
              startFrom = this.state.work * 60;
            } else {
              startFrom = this.state.currentTime;
            }
            this.setState({
              currentTime: startFrom
            }, ()=>{
              const intervalID = setInterval(this.timer,1000);
              this.setState({ intervalID: intervalID });
            });

          } else {
            clearInterval(this.state.intervalID);
            this.setState({ intervalID: null });
          }
        break;
        case 'reset':
          if (this.state.intervalID !== null ) clearInterval(this.state.intervalID);
          this.state.sound.pause();
          this.state.sound.currentTime = 0;
          this.setState({
            break: 5,
            work: 25,
            label: 'Session',
            intervalID: null,
            currentTime: -1
          });
        break;
      }
  }


  render() {
    let timeToDisplay, minutes, seconds, min, sec, labelBtn;
    if (this.state.currentTime < 0 ) {
      minutes = this.state.work;
      sec = '00';
    } else {
      minutes = Math.floor(this.state.currentTime / 60);
      seconds = (this.state.currentTime - (minutes * 60));
      seconds < 10 ? sec = '0'+seconds: sec = seconds;
    }
    minutes < 10 ? min = '0'+minutes: min = minutes;
    timeToDisplay = `${min}:${sec}`;
    this.state.intervalID === null ? labelBtn = 'START' : labelBtn = 'STOP';

    return (
      <div className="wrapper" onClick={this.handleClick}>
        <div className="logo">Pomodoro Clock</div>
        <div className="timer-label" id="timer-label">{ this.state.label }</div>
        <div className="time-left" id="time-left">{ timeToDisplay }</div>
        <nav className="row">
          <button className="actionBtn" id="start_stop">{ labelBtn }</button>
          <button className="actionBtn" id="reset">RESET</button>
        </nav>
        <div className="session-label" id="session-label">Session Length</div>
        <div className="row" >
          <button className="settingBtn plus" id="session-increment">+</button>
          <div className="row-label" id="session-length">{ this.state.work }</div>
          <button className="settingBtn minus" id="session-decrement">-</button>
        </div>
        <div className="break-label" id="break-label">Break Length</div>
        <div className="row" >
          <button className="settingBtn plus" id="break-increment">+</button>
          <div className="row-label" id="break-length">{ this.state.break }</div>
          <button className="settingBtn minus" id="break-decrement">-</button>
        </div>
        <footer className="footer">Created by&nbsp;
          <a className="link" href="http://mybytes.pl/" target="_blank" rel="noopener">Sebastian Sporek</a>
        </footer>
        <audio id="beep" src="http://mybytes.pl/misc/FccPomodoroAlarm.mp3"></audio>
      </div>
    );
  }
}

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

              
            
!
999px

Console