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="pomodoro-app" ng-app="pomodoroApp">
  <div id="container">
     <pomodoro-comp minutes="25"></pomodoro-comp>
  </div>
  <script type="text/ng-template" id="/componentGrid.html">
     <div id="timer">
      <div id="time">
        <span>{{$ctrl.toDoubleDigit($ctrl.minutes)}}</span>
        <span>:</span>
        <span>{{$ctrl.toDoubleDigit($ctrl.seconds)}}</span>
      </div>
      <div id="filler" ng-style="{height : $ctrl.fillerHeight + 'px'}"></div>
    </div>

    <div id="buttons">
      <button id="work" ng-click="$ctrl.startWork()">Work</button>
      <button id="shortBreak" ng-click="$ctrl.startShortBreak()">Short Break</button>
      <button id="longBreak" ng-click="$ctrl.startLongBreak()">Long Break</button>
      <button id="stop" ng-click="$ctrl.stopTimer()">Stop</button>
    </div>
  </script>
</div>

              
            
!

CSS

              
                #container{
  border:1px solid #333;
  border-radius :20px;
  width:400px;
  margin:20px auto;
  padding:20px;
  text-align:center;
  background : #333;
}

#timer{ 
  color:#f00; 
  font-size:50px; 
  margin:10px auto;
  border : 5px solid red;
  border-radius:50%;
  width:200px;
  height:200px;
  overflow:hidden;
  position:relative;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor:default;
}

#time{
  margin-top:70px;
  z-index : 1;
  position:relative;
}

/*
	filler width is set to 200px (i.e. equal to width of the timer) so that it completely covers 	the timer in background. The height is initially set to 0px and it increases as timer 		progresses to give background fill effect.
*/


#filler{
  background : #ddffcc;
  height: 0px;
  width: 200px;
  position:absolute;
  bottom:0;
}

#buttons button { 
  background:#4da6ff; 
  border:none; 
  color:#fff; 
  cursor:pointer; 
  padding:5px; 
  width:90px; 
  margin:10px auto;
  font-size:14px;
  height : 50px;
  border-radius : 50px;
}

#buttons button#shortBreak{
  background : #0c0;
}

#buttons button#longBreak{
  background : #080;
}

#buttons button#stop{
  background : #f00;
}

              
            
!

JS

              
                var app = angular.module("pomodoroApp", []);
/* Define a module named pomodoroApp*/

/* Defind the angular component*/
app.component('pomodoroComp', {
  bindings: {},
  templateUrl: '/componentGrid.html',
  controller : ['$interval',function(interval){
 
    var self = this;
    self.started = false;
  /* 	
  started variable stores the state of the timer. If it is true, it means that some task (work, short break, long break) is going on with pomodoro timer. If it is false, it means that the pomodoro is not yet started or it is stopped (by clicking stop button)
 */
  
  self.minutes = 25;
  /*
	minutes variable stores current minute which is displayed in the pomodoro.	
*/
  
  self.seconds = 0;
  /*
	seconds variable stores current second which is displayed in the pomodoro.
*/
  
  self.fillerIncrement = 200/(self.minutes*60);
  /*
	fillerIncrement variable stores the value by which fillerHeight should increase.
*/
  
  self.fillerHeight = 0; 
  /*
	fillerHeight variable stores the height of the background filler. Initially it is set to 0. As soon as a pomodoro task starts, its height starts increasing (by a value which is stored in fillerIncrement variable) and it keeps increasing till that particular task ends. On click of stop button, it is again set to 0.

*/

  
  /*
  resetVariables function will be called for each of the actions (work, Short Break, Long Break, Stop) to set the value of variables to values corresponding to that particular action
  */
  
self.resetVariables = function(mins, secs, started){
    self.minutes = mins;
    self.seconds = secs;
    self.started = started;
    self.fillerIncrement = 200/(self.minutes*60);
    self.fillerHeight = 0;
}

/* handler to be called when user clicks ‘Work’ button */
self.startWork = function(){
    self.resetVariables(25, 0, true);
};

/* handler to be called when user clicks ‘Short Break’ button */
self.startShortBreak = function(){
    self.resetVariables(5, 0, true);
};

/* handler to be called when user clicks ‘Long Break’ button */
self.startLongBreak = function(){
    self.resetVariables(15, 0, true);
};

/* handler to be called when user clicks ‘Stop’ button */
self.stopTimer = function(){
    self.resetVariables(25, 0, false);
};

self.timerComplete = function(){
    self.started = false;
};

/*
 intervalCallback function is called each second, updates the values of minutes and seconds variables and reflect the updates in timer
 */
self.intervalCallback = function(){ 
  if(!self.started) return false;
    if(self.seconds == 0) {
        if(self.minutes == 0) {
            self.timerComplete();
            return;
        }
        self.seconds = 59;
        self.minutes--;
    } else {
        self.seconds--;
    }
  
    self.fillerHeight += self.fillerIncrement;
};

/* 
 toDoubleDigit function converts a number to double digit. If num is single digit (0-9), it is prepended with a ‘0’ and resulting string is returned. If num is double digit, it is returned as such. This function is needed as we want to display ’05’ instead of ‘5’ in timer 
 */
self.toDoubleDigit = function(num){
    return num < 10 ? '0' + parseInt(num,10) : num;
};


/*
 Init method initializes the timer using $interval function such that a callback function (intervalCallback) is called after every second
 */

self.$onInit = function(){
    self.interval = interval( self.intervalCallback, 1000);
/*
 $onInit is automatically called when component is initialized. interval variable stores the reference id of the currently running interval. If we need to clear the interval, we will need this variable. Although in the demo, we are not clearing the interval, it’s always a good idea to clear the interval at some point.
 */


  };
    
  }]
});
              
            
!
999px

Console