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

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Karla');


$dark-gray: #333;
$darker-gray: #1a1a1a;
$white: #fff;
$green: #009900;

html,
body,
header,
main,
footer,
h1,
h2,
h3,
h4,
h5,
h6,
div,
span,
button,
a {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-sizing: border-box;
  color: $white;
  font-family: 'Karla', Arial, sans-serif;
  font-size: 100%;
  font-weight: 400;
  letter-spacing: 1px;
  line-height: 1;
  margin: 0;
  padding: 0;
  text-align: center;
}

html {
  height: 100%;
}

body {
  font-size: 0.9rem;
  min-height: 100%;
  padding: 0 20px;
  position: relative;
}

a,
a:visited,
a:active,
a:focus {
  color: inherit;
  letter-spacing: inherit;
  text-decoration: none;
  &:hover {
    text-decoration: underline;
  }
}

span {
  color: inherit;
  letter-spacing: inherit;
}

button,
button:hover,
button:active,
button:focus {
  cursor: pointer;
}

*:focus {
  box-shadow: 0 0 3px 3px green;
  outline: none;
}

html {
  background: $dark-gray;
  button,
  button:active,
  button:focus {
    background: $green;
    border: 3px solid $green;
    color: $dark-gray;
    &:hover {
      background: transparent;
      color: $green;
    }
  }

  h1 {
    font-size: 2.5rem;
    font-weight: 400;
    letter-spacing: 4px;
    padding-top: 15px;
    text-align: center;
  }

  main {
    padding: 30px 0 80px;
  }
  h2 {
    font-size: 2rem;
    font-weight: 300px;
    letter-spacing: 2px;
    padding-bottom: 20px;
  }

  .card {
    background: $darker-gray;
    border-radius: 25px;
    display: inline-block;
    padding: 20px;
    margin: 20px;
    width: 250px;
    h3 {
      font-size: 1.25rem;
      font-weight: 400;
      letter-spacing: 1px;
    }
    .time-length {
      font-size: 2.2rem;
      letter-spacing: 1px;
      padding: 5px 0;
    }
    .settings,
    .settings:hover,
    .settings:active,
    .settings:focus {
      border-radius: 50%;
      height: 32px;
      margin: 5px 7px;
      width: 32px;
    }
  }
  .clock {
    border: 3px solid $green;
    border-radius: 25px;
    margin: auto;
    max-width: 250px;
    padding: 20px 0;
  }
  .timer {
    color: $green;
    font-size: 3rem;
    letter-spacing: 2px;
    margin: 15px 0;
  }
  .controls,
  .controls:hover,
  .controls:active,
  .controls:focus {
    border-radius: 25px;
    height: 45px;
    margin: 6px;
    width: 45px;
  }
}

footer {
  background: $darker-gray;
  font-size: 1rem;
  letter-spacing: 4px;
  padding: 15px 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
  width: 100%;
  a,
  a:visited,
  a:hover,
  a:active,
  a:focus {
    color: $green;
  }
}
              
            
!

JS

              
                class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      sessionLength: 25,
      breakLength: 5,
      timerLabel: "Session",
      currentMinutes: 25,
      currentSeconds: 0,
      currentButton: {
        func: () => this.countDown(),
        icon: "fa-play",
        title: "Play"
      }
    };
    this.timer = null;
    this.sessionTimer = this.state.sessionLength * 60;
    this.breakTimer = this.state.breakLength * 60;
    this.playTimer = this.playTimer.bind(this);
  }

  changeTimers(type) {
    let sessionLength = this.state.sessionLength;
    let breakLength = this.state.breakLength;

    switch (type) {
      case "sessionMinus":
        if (sessionLength > 1) {
          sessionLength--;
        }
        break;
      case "sessionPlus":
        if (sessionLength < 60) {
          sessionLength++;
        }
        break;
      case "breakMinus":
        if (breakLength > 1) {
          breakLength--;
        }
        break;
      case "breakPlus":
        if (breakLength < 60) {
          breakLength++;
        }
    }
    clearInterval(this.timer);
    document.getElementById("beep").pause();
    document.getElementById("beep").currentTime = 0;
    this.setState({
      sessionLength,
      breakLength,
      timerLabel: "Session",
      currentMinutes: sessionLength,
      currentSeconds: 0,
      currentButton: {
        func: () => this.countDown(),
        icon: "fa-play",
        title: "Play"
      }
    });
    this.sessionTimer = sessionLength * 60;
    this.breakTimer = breakLength * 60;
  }

  countDown() {
    this.timer = setInterval(this.playTimer, 1000);
    this.setState({
      currentButton: {
        func: () => this.pauseTimer(),
        icon: "fa-pause",
        title: "Pause"
      }
    });
  }

  playTimer() {
    if (this.sessionTimer > 0) {
      this.sessionTimer--;
      this.setState({
        timerLabel: "Session",
        currentMinutes: parseInt(this.sessionTimer / 60, 10),
        currentSeconds: parseInt(this.sessionTimer % 60, 10)
      });
    } else {
      if (
        this.breakTimer === this.state.breakLength * 60 &&
        this.state.currentMinutes === 0 &&
        this.state.currentSeconds === 0
      ) {
        document.getElementById("beep").play();
        this.setState({
          timerLabel: "Break",
          currentMinutes: this.state.breakLength,
          currentSeconds: 0
        });
      } else {
        if (this.breakTimer > 0) {
          this.breakTimer--;
          this.setState({
            timerLabel: "Break",
            currentMinutes: parseInt(this.breakTimer / 60, 10),
            currentSeconds: parseInt(this.breakTimer % 60, 10)
          });
        } else {
          document.getElementById("beep").play();
          clearInterval(this.timer);
          this.sessionTimer = this.state.sessionLength * 60;
          this.breakTimer = this.state.breakLength * 60;
          this.setState({
            timerLabel: "Session",
            currentMinutes: parseInt(this.sessionTimer / 60, 10),
            currentSeconds: parseInt(this.sessionTimer % 60, 10)
          });
          this.countDown();
        }
      }
    }
  }

  pauseTimer() {
    clearInterval(this.timer);
    document.getElementById("beep").pause();
    this.setState({
      currentButton: {
        func: () => this.countDown(),
        icon: "fa-play",
        title: "Play"
      }
    });
  }

  resetTimer() {
    clearInterval(this.timer);
    document.getElementById("beep").pause();
    document.getElementById("beep").currentTime = 0;
    this.setState({
      sessionLength: 25,
      breakLength: 5,
      timerLabel: "Session",
      currentMinutes: 25,
      currentSeconds: 0,
      currentButton: {
        func: () => this.countDown(),
        icon: "fa-play",
        title: "Play"
      }
    });
    this.sessionTimer = this.state.sessionLength * 60;
    this.breakTimer = this.state.breakLength * 60;
  }

  render() {
    return (
      <div className="body">
        {/* HEADER */}
        <header>
          <h1>Pomodoro Timer</h1>
        </header>
        <main>
          {/* TIMEER SETTINGS */}
          <h2>Set Timers</h2>
          <div className="card">
            <h3 id="session-label">Session Length</h3>
            <div className="time-length" id="session-length">
              {this.state.sessionLength}
            </div>
            <div className="button-group">
              <button
                type="button"
                className="settings"
                onClick={() => this.changeTimers("sessionPlus")}
                aria-label="Add one minute"
                title="Add one minute"
                id="session-increment"
              >
                <span className="fa fa-plus" />
              </button>
              <button
                type="button"
                className="settings"
                onClick={() => this.changeTimers("sessionMinus")}
                aria-label="Subtract one minute"
                title="Subtract one minute"
                id="session-decrement"
              >
                <span className="fa fa-minus" />
              </button>
            </div>
          </div>
          <div className="card">
            <h3 id="break-label">Break Length</h3>
            <div className="time-length" id="break-length">
              {this.state.breakLength}
            </div>
            <div className="button-group">
              <button
                type="button"
                className="settings"
                onClick={() => this.changeTimers("breakPlus")}
                aria-label="Add one minute"
                title="Add one minute"
                id="break-increment"
              >
                <span className="fa fa-plus" />
              </button>
              <button
                type="button"
                className="settings"
                onClick={() => this.changeTimers("breakMinus")}
                aria-label="Subtract one minute"
                title="Subtract one minute"
                id="break-decrement"
              >
                <span className="fa fa-minus" />
              </button>
            </div>
          </div>
          <div className="clock">
            <h2 id="timer-label">{this.state.timerLabel}</h2>
            <div className="timer" id="time-left">
              {this.state.currentMinutes < 10
                ? `0${this.state.currentMinutes}`
                : this.state.currentMinutes}:{this.state.currentSeconds < 10
                ? `0${this.state.currentSeconds}`
                : this.state.currentSeconds}
            </div>
            <div className="button-group">
              <button
                type="button"
                className="controls"
                onClick={this.state.currentButton.func}
                aria-label={this.state.currentButton.title}
                title={this.state.currentButton.title}
                id="start_stop"
              >
                <span className={`fa ${this.state.currentButton.icon} fa-lg`} />
              </button>
              <button
                type="button"
                className="controls"
                onClick={() => this.resetTimer()}
                aria-label="Reset"
                title="Reset"
                id="reset"
              >
                <span className="fa fa-redo-alt fa-lg" />
              </button>
            </div>
          </div>
          <audio src="https://goo.gl/65cBl1" id="beep" />
        </main>
        <footer> Coded by <a href="www.freecodecamp.org/allanmolson">Allan Olson</a></footer>
      </div>
    );
  }
}

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

              
            
!
999px

Console