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

              
                <header>
  <link href="https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@100;200;400;500;600;700;800&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Chelsea+Market&display=swap" rel="stylesheet">
</header>
<h1><span id="react">React</span> Pomodoro Clock</h1>
<div id="root"></div>
              
            
!

CSS

              
                body {
  margin: 0px;
  font-family: 'Montserrat Alternates', sans-serif;
  display: grid;
  justify-items: center;
  align-items: center;
  background: #666;
}

h1{
  width: 100vw;
  text-align: center;
  font-family: 'Chelsea Market', cursive;
  color: #fff;
  margin-bottom: -40px;
}

#react{
  color: #79D8F8;
}

#container {
  height: 100vh;
  width: 100vw;
  display: grid;
  justify-items: center;
  align-items: center;
  grid-template-columns: 100%;
  grid-template-rows: 100%;
}

#pomodoro-container {
  display: grid;
  width: 48.5vw;
  height: 30vw;
  max-width: 485px;
  max-height: 300px;
  min-width: 323.6px;
  min-height: 200px;
  grid-template-columns: 33% 34% 33%;
  grid-template-rows: 34% 33% 33%;
  grid-column-gap: 0px;
  grid-row-gap: 0px;
  background: #FFF;
  border-radius: 5px;
  box-shadow: 3px 3px 5px 1px #333;
}

#play-container {
  display: grid;
  grid-column-start: 1;
  grid-column-end: 2;
  grid-row-start: 1;
  grid-row-end: 2;
  justify-content: center;
  align-items: center;
}

#timer-label-container {
  display: grid;
  grid-column-start: 2;
  grid-column-end: 3;
  grid-row-start: 1;
  grid-row-end: 2;
  justify-content: center;
  align-items: center;
}

#timer-label {
  display: grid;
  justify-content: center;
  align-items: center;
  font-weight: 300;
  font-size: 22px;
  margin-bottom: -1.5vw;
  white-space: nowrap;
}

#time-left {
  display: grid;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 34px;
  margin-top: -1.5vw;
}

#reset-container {
  display: grid;
  grid-column-start: 3;
  grid-column-end: 4;
  grid-row-start: 1;
  grid-row-end: 2;
  justify-content: center;
  align-items: center;
}

#s-d-container {
  display: grid;
  grid-column-start: 1;
  grid-column-end: 2;
  grid-row-start: 2;
  grid-row-end: 3;
  justify-content: center;
  align-items: center;
}

#session-label-container {
  display: grid;
  grid-column-start: 2;
  grid-column-end: 3;
  grid-row-start: 2;
  grid-row-end: 3;
  justify-content: center;
  align-items: space-around;
  font-weight: 800;
}

#session-label {
  display: grid;
  justify-content: center;
  align-items: center;
  font-weight: 300;
  font-size: 14px;
  white-space: nowrap;
  margin-bottom: -2vw;
}

#session-length {
  display: grid;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  margin-top: -2vw;
  font-size: 24px;
}

#s-i-container {
  display: grid;
  grid-column-start: 3;
  grid-column-end: 4;
  grid-row-start: 2;
  grid-row-end: 3;
  justify-content: center;
  align-items: center;
}

#session-increment {
  border: 0;
  padding: 0;
  color: #00CF00;
  background: #FFF;
}

#s-d-container {
  display: grid;
  grid-column-start: 1;
  grid-column-end: 2;
  grid-row-start: 2;
  grid-row-end: 3;
  justify-content: center;
  align-items: center;
}

#session-decrement {
  border: 0;
  padding: 0;
  color: #CF0000;
  background: #FFF;
}

#break-label-container {
  display: grid;
  grid-column-start: 2;
  grid-column-end: 3;
  grid-row-start: 3;
  grid-row-end: 4;
  justify-content: center;
  align-items: center;
}

#break-label {
  display: grid;
  justify-content: center;
  align-items: center;
  font-weight: 300;
  font-size: 14px;
  margin-bottom: -2vw;
  white-space: nowrap;
}

#break-length {
  display: grid;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  margin-top: -2vw;
  font-size: 24px;
}

#b-i-container {
  display: grid;
  grid-column-start: 3;
  grid-column-end: 4;
  grid-row-start: 3;
  grid-row-end: 4;
  justify-content: center;
  align-items: center;
}

#break-increment {
  border: 0;
  padding: 0;
  color: #00CF00;
  background: #FFF;
}

#b-d-container {
  display: grid;
  grid-column-start: 1;
  grid-column-end: 2;
  grid-row-start: 3;
  grid-row-end: 4;
  justify-content: center;
  align-items: center;
}

#break-decrement {
  border: 0;
  padding: 0;
  color: #CF0000;
  background: #FFF;
}

#start_stop {
  border: 0;
  padding: 0;
  color: #bbb;
  background: #FFF;
  font-size: 10px;
}

#start_stop:hover{
  color: #00CF00;
}

#reset{
  border: 0;
  padding: 0;
  color: #bbb;
  background: #FFF;
  font-size: 10px;
}

#reset:hover{
  color: #000;
}

audio {
  display: none;
}

.incdec{
  font-size: 26px;
  font-weight: 900;
}

.incdec:hover{
  transform: scale(1.2);
}

@media only screen and (max-width: 900px) {
#time-left {
  font-weight: 700;
  font-size: 24px;
}
}
              
            
!

JS

              
                class App extends React.Component {
  constructor() {
    super();
    this.state = {
      display: 0,
      breakLength: 5,
      sessionLength: 25,
      timerLabel: "Session",
      timeLeft: 25,
      minutes: 25,
      seconds: 0,
      isPaused: 1
    };
    this.bDecInc = this.bDecInc.bind(this);
  }

  // Handle reset button click
  reset(event) {
    this.setState({
      breakLength: 5,
      sessionLength: 25,
      timeLeft: 25,
      minutes: 25,
      seconds: 0,
      isPaused: 1,
      timerLabel: "Session"
    });
    clearInterval(this.timeLeft);
    document.getElementById("beep").pause().currentTime = 0;
    document.body.style.background = "#666";
  }

  // Handle clicks on break increase / decrease buttons
  bDecInc(id, event) {
    let amount = 0;
    if (id === "bDec" && this.state.breakLength > 1) {
      amount = -1;
    }

    if (id === "bInc" && this.state.breakLength < 60) {
      amount = 1;
    }

    this.setState({ breakLength: this.state.breakLength + amount });

    if (this.state.isBreak) {
      this.setState({ minutes: this.state.breakLength });
    }
  }

  sDec(event) {
    if (this.state.isPaused) {
      if (this.state.sessionLength > 1) {
        this.setState({ sessionLength: this.state.sessionLength - 1 });
        if (this.state.timerLabel === "Session") {
          this.setState({ minutes: this.state.sessionLength - 1 });
        }
      }
    }
  }

  sInc(event) {
    if (this.state.isPaused) {
      if (this.state.sessionLength < 60) {
        this.setState({ sessionLength: this.state.sessionLength + 1 });
        this.setState({ minutes: this.state.sessionLength + 1 });
      }
    }
  }

  hitPlay() {
    if (this.state.timerLabel === "Session") {
      if (this.state.isPaused === 1) {
        this.sessionTime("isSession");
      } else {
        document.body.style.background = "#666";
        clearInterval(this.timeLeft);
        this.setState({ isPaused: 1 });
      }
    } else if (this.state.isPaused === 1) {
      this.sessionTime("isBreak");
    } else {
      document.body.style.background = "#666";
      clearInterval(this.timeLeft);
      this.setState({ isPaused: 1 });
    }
  }

  sessionTime(event) {
    console.log(event);
    console.log("It is now Session Time");
    document.body.style.background = "#006600";
    this.setState({ isPaused: 0 });
    this.timeLeft = setInterval(() => {
      const { seconds, minutes } = this.state;
      if (seconds > 0) {
        this.setState(({ seconds }) => ({
          seconds: seconds - 1
        }));
      }
      if (seconds === 0) {
        if (minutes === 0) {
          //clearInterval(this.timeLeft)
          if (event === "isSession") {
            this.setState({ timerLabel: "Break Time!" });
            document.body.style.background = "660000";
            this.setState({ minutes: this.state.breakLength });
            this.setState({ seconds: 0 });
            event = "isBreak";
            document.getElementById("beep").play();
          } else {
            this.setState({ timerLabel: "Session" });
            document.body.style.background = "#006600";
            this.setState({ minutes: this.state.sessionLength });
            this.setState({ seconds: 0 });
            event = "isSession";
            document.getElementById("beep").play();
          }
        } else {
          this.setState(({ minutes }) => ({
            minutes: minutes - 1,
            seconds: 59
          }));
        }
      }
    }, 1000);
  }

  render() {
    let minutesDisplay;
    let secondsDisplay;

    if (this.state.minutes < 10) {
      minutesDisplay = "0" + this.state.minutes;
    } else {
      minutesDisplay = this.state.minutes;
    }

    if (this.state.seconds < 10) {
      secondsDisplay = "0" + this.state.seconds;
    } else {
      secondsDisplay = this.state.seconds;
    }

    return (
      <div id="container">
        <div id="pomodoro-container">
          <div id="break-label-container">
            <div id="break-label">Break Length</div>

            <div id="break-length">{this.state.breakLength}</div>
          </div>

          <div id="b-d-container">
            <button
              id="break-decrement"
              onClick={(e) => this.bDecInc("bDec", e)}
            >
              <i class="far fa-minus fa-2x incdec"></i>
            </button>
          </div>

          <div id="b-i-container">
            <button
              id="break-increment"
              onClick={(e) => this.bDecInc("bInc", e)}
            >
              <i class="far fa-plus fa-2x incdec"></i>
            </button>
          </div>
          <div id="session-label-container">
            <div id="session-label">Session Length</div>

            <div id="session-length">{this.state.sessionLength}</div>
          </div>

          <div id="s-d-container">
            <button id="session-decrement" onClick={this.sDec.bind(this)}>
              <i class="far fa-minus fa-2x incdec"></i>
            </button>
          </div>

          <div id="s-i-container">
            <button id="session-increment" onClick={this.sInc.bind(this)}>
              <i class="far fa-plus fa-2x incdec"></i>
            </button>
          </div>

          <div id="play-container">
            <button id="start_stop" onClick={this.hitPlay.bind(this)}>
              <i class="fas fa-play fa-2x"></i>{" "}
              <i class="fas fa-pause fa-2x"></i>
            </button>
          </div>

          <div id="reset-container">
            <button id="reset" onClick={this.reset.bind(this)}>
              <i class="fas fa-undo fa-2x"></i>
            </button>
          </div>
          <div id="timer-label-container">
            <div id="timer-label">{this.state.timerLabel}</div>

            <div id="time-left">
              {minutesDisplay}:{secondsDisplay}
            </div>
          </div>
        </div>
        <div>
          <audio
            ref="audio_tag"
            src="https://raw.githubusercontent.com/jonathanrace77/jonathanrace77.github.io/master/audio/pomodoro_ding.mp3"
            id="beep"
            controls
            autoPlay
          />
        </div>
      </div>
    );
  }
}

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

              
            
!
999px

Console