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://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" /> 
<body id="body">
  
<div class="bg"></div>
    <div class="bg bg2"></div>
    <div class="bg bg3"></div>
    <svg viewBox="0 0 1160 400">
      <symbol id="s-text">
        <text text-anchor="middle" x="50%" y="80%">Pomodoro Clock</text>
      </symbol>

      <g class="g-ants">
        <use xlink:href="#s-text" class="text-copy"></use>
        <use xlink:href="#s-text" class="text-copy"></use>
        <use xlink:href="#s-text" class="text-copy"></use>
        <use xlink:href="#s-text" class="text-copy"></use>
        <use xlink:href="#s-text" class="text-copy"></use>
      </g>
    </svg>

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

<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>


<!-- 

Hello Camper!

For now, the test suite only works in Chrome! Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

-->

              
            
!

CSS

              
                
.bg {
  /* Background made by Chris Smith https://codepen.io/chris22smith/pen/RZogMa */
  animation: slide 3s ease-in-out infinite alternate;
  background-image: linear-gradient(-60deg, #6c3 50%, #09f 50%);
  bottom: 0;
  left: -50%;
  opacity: 0.5;
  position: fixed;
  right: -50%;
  top: 0;
  z-index: -1;
}

.bg2 {
  animation-direction: alternate-reverse;
  animation-duration: 4s;
}

.bg3 {
  animation-duration: 5s;
}

.content {
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 0.25em;
  box-shadow: 0 0 0.25em rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
  left: 50%;
  padding: 10vmin;
  position: fixed;
  text-align: center;
  top: 50%;
  transform: translate(-50%, -50%);
}

.container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 45%;
  height: 65%;

  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 35px repeat(3, 1fr);
  grid-gap: 5px;

  justify-items: center;
}

#titleHeader {
  font-family: Cambria, Cochin, Georgia, Times, "Times New Roman", serif;
  font-size: 45px;
  grid-column: span 2;
  margin: 0 auto;
  color: #fff;
}
.flexMe {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: -20px;
}

.sessionTimerMain {
  background-color: rgba(210, 200, 245, 0.34);
  grid-column: span 2;
  font-size: 25px;
  border-radius: 6px;
  text-align: center;
  padding: 20px;
  justify-self: stretch;
}

#break-length,
#session-length {
  font-size: 35px;
}

.small-btn {
  display: flex;
  justify-items: center;
  align-items: center;
}

#icon {
  margin: 0;
}

#break-length,
#session-length {
  padding: 15px;
}

#start_stop {
  align-self: center;
}
#reset {
  align-self: center;
}

#time-left {
  font-size: 65px;
}
@keyframes slide {
  0% {
    transform: translateX(-25%);
  }
  100% {
    transform: translateX(25%);
  }
}
/* TEXT  ANIMATION  Made by Claire Larsen https://codepen.io/ClaireLarsen/pen/XmVyVX/?editors=1100 */
svg {
  display: block;
  font: 8.5em "Montserrat";
  width: 960px;
  height: 300px;
  margin: -100px auto;
}

.text-copy {
  fill: none;
  stroke: white;
  stroke-dasharray: 6% 29%;
  stroke-width: 5px;
  stroke-dashoffset: 0%;
  animation: stroke-offset 5.5s infinite linear;
}

.text-copy:nth-child(1) {
  stroke: #4d163d;
  animation-delay: -1;
}

.text-copy:nth-child(2) {
  stroke: #840037;
  animation-delay: -2s;
}

.text-copy:nth-child(3) {
  stroke: #bd0034;
  animation-delay: -3s;
}

.text-copy:nth-child(4) {
  stroke: #bd0034;
  animation-delay: -4s;
}

.text-copy:nth-child(5) {
  stroke: #fdb731;
  animation-delay: -5s;
}

@keyframes stroke-offset {
  100% {
    stroke-dashoffset: -35%;
  }
}

              
            
!

JS

              
                class Clock extends React.Component {
  constructor(props) {
    super(props);

    this.myRef = React.createRef();

    this.state = {
      sessionLength: 25,
      breakLength: 5,
      timerRunning: false,
      timeLeft: `25:00`,
      intervalID: null,
      breakGoingOn: false
    };
  }
  decBreak = () => {
    if (this.state.breakLength > 1)
      this.setState({ breakLength: this.state.breakLength - 1 });
  };
  incBreak = () => {
    if (this.state.breakLength < 60)
      this.setState({ breakLength: this.state.breakLength + 1 });
  };
  decSession = () => {
    if (this.state.sessionLength > 1)
      this.setState({
        timeLeft: `${String(this.state.sessionLength - 1).padStart(2, "0")}:00`,
        sessionLength: this.state.sessionLength - 1
      });
  };
  incSession = () => {
    if (this.state.sessionLength < 60)
      this.setState({
        timeLeft: `${String(this.state.sessionLength + 1).padStart(2, "0")}:00`,
        sessionLength: this.state.sessionLength + 1
      });
  };

  reset = () => {
    clearInterval(this.state.intervalID);
    this.setState({
      sessionLength: 25,
      breakLength: 5,
      timerRunning: false,
      timeLeft: `25:00`,
      intervalID: null,
      breakGoingOn: false,
      totalSessionSeconds: undefined, // IT MIRACULOUSLY WORKS NOW
      totalBreakSeconds: undefined // IT MIRACULOUSLY WORKS NOW
    });
    this.myRef.current.load(); // Rewind audio if playing
  };

  startStop = () => {
    this.setState({
      timerRunning: !this.state.timerRunning,
      //SEKUNDARE PRERAČUNAVANJE
      totalSessionSeconds:
        this.state.totalSessionSeconds || this.state.sessionLength * 60,
      totalBreakSeconds:
        this.state.totalBreakSeconds || this.state.breakLength * 60
    }); // TOGGLE THE TIMER

    console.log(
      `SessionLength: ${this.state.sessionLength} with seconds: ${this.state
        .sessionLength * 60}
      `
    );

    if (!this.state.timerRunning) {
      // TIMERRUNNING IS TRUE
      console.log(`Timer running is now : ${!this.state.timerRunning}`);

      this.setState({
        intervalID: setInterval(() => {
          if (!this.state.breakGoingOn) {
            // IF TRUE AT START - SESSION IS HAPPENING

            if (this.state.totalSessionSeconds > 0) {
              if (
                this.state.totalSessionSeconds ===
                this.state.sessionLength * 60 - 1
              ) {
                this.setState({
                  // SESSION SECONDS ARE CALCULATED AT TOTAL BREAK SECONDS - 1, NOT TOO EARLY
                  totalBreakSeconds: this.state.breakLength * 60,
                  totalSessionSeconds: this.state.totalSessionSeconds - 1
                });
              } else {
                this.setState({
                  totalSessionSeconds: this.state.totalSessionSeconds - 1
                });
              }
            } else {
              // SESSION REACHED ZERO
              this.myRef.current.play();
              this.setState({
                breakGoingOn: true,
                totalBreakSeconds: this.state.breakLength * 60
              });
            }
          } else {
            // BREAK IS HAPPENING

            if (this.state.totalBreakSeconds > 0) {
              if (
                this.state.totalBreakSeconds ===
                this.state.breakLength * 60 - 1
              ) {
                this.setState({
                  // BREAK SECONDS ARE CALCULATED AT TOTAL SESSION SECONDS - 1, NOT TOO EARLY
                  totalSessionSeconds: this.state.sessionLength * 60,
                  totalBreakSeconds: this.state.totalBreakSeconds - 1
                });
              } else {
                this.setState({
                  totalBreakSeconds: this.state.totalBreakSeconds - 1
                });
              }
            } else {
              // BREAK REACHED ZERO

              this.myRef.current.play();
              this.setState({
                breakGoingOn: false,
                totalSessionSeconds: this.state.sessionLength * 60
              });
            }
          }
          console.log(
            `SessionLength: ${this.state.sessionLength} with seconds: ${
              this.state.totalSessionSeconds
            }, BreakLength: ${this.state.breakLength} with break seconds: ${
              this.state.totalBreakSeconds
            }`
          );
        }, 1000)
      });
    } else {
      // TIMERRUNNING IS FALSE
      clearInterval(this.state.intervalID);
      console.log(`Timer running : ${this.state.timerRunning}`);
    }
  };

  render() {
    return (
      <div className="container">
        <h1 id="titleHeader"> &nbsp; </h1>
        <div className="breakBox">
          <h1 id="break-label">Break Length</h1>
          <div className="flexMe">
            <button
              class="small-btn ui button"
              id="break-decrement"
              onClick={this.decBreak}
            >
              <i id="icon" class="angle down icon" />
            </button>

            <span id="break-length"> {this.state.breakLength} </span>
            <button
              class="small-btn ui button"
              id="break-increment"
              onClick={this.incBreak}
            >
              <i id="icon" class="angle up icon" />
            </button>
          </div>
        </div>
        <div className="sessionBox">
          <h1 id="session-label">Session Length</h1>
          <div className="flexMe">
            <button
              class="small-btn ui button"
              id="session-decrement"
              onClick={this.decSession}
            >
              <i id="icon" class="angle down icon" />
            </button>

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

            <button
              class="small-btn ui button"
              id="session-increment"
              onClick={this.incSession}
            >
              <i id="icon" class="angle up icon" />
            </button>
          </div>
        </div>
        <div className="sessionTimerMain">
          <h1 id="timer-label">
            {this.state.breakGoingOn ? "Break" : "Session"}
          </h1>
          <div id="time-left">
            {this.state.breakGoingOn // IF BREAK IS GOING ON
              ? this.state.totalBreakSeconds !== undefined // NOT EQUAL TO UNDEFINED
                ? `${String(
                    Math.floor(this.state.totalBreakSeconds / 60)
                  ).padStart(2, "0")}:${String(
                    this.state.totalBreakSeconds % 60
                  ).padStart(2, "0")}`
                : `${String(this.state.breakLength).padStart(2, "0")}:00` //EQUAL TO UNDEFINED
              : this.state.totalSessionSeconds !== undefined //ELSE IF SESSION IS GOING ON, AND WE HAVE A TOTALSESSIONSECONDS IN STATE
              ? `${String(
                  Math.floor(this.state.totalSessionSeconds / 60)
                ).padStart(2, "0")}:${String(
                  this.state.totalSessionSeconds % 60
                ).padStart(2, "0")}`
              : `${String(this.state.sessionLength).padStart(2, "0")}:00`}
          </div>
        </div>

        <button
          id="start_stop"
          className="ui labeled icon button"
          onClick={this.startStop}
        >
          <i class="pause icon" />
          Play/Pause
        </button>

        <button id="reset" className="ui button" onClick={this.reset}>
          <i class="stop icon" />
          Reset
        </button>

        <audio
          id="beep"
          ref={this.myRef}
          src="http://soundbible.com/mp3/Horn%20Honk-SoundBible.com-1162546405.mp3"
        />
      </div>
    );
  }
};

const App = () => {
  return (
    <div>
      <Clock />
    </div>
  );
};

ReactDOM.render(<App />, document.querySelector("#root"));
              
            
!
999px

Console