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 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

              
                header#title
main#timer
footer#author
              
            
!

CSS

              
                @import 'breakpoint';
/* Fonts */
@import url('https://fonts.googleapis.com/css?family=Lobster|Poppins:500,700&subset=cyrillic');

$stackPoppins: 'Poppins', sans-serif;
$stackLobster:'Lobster', cursive;
/* Colors */

$purple: #ab00ff;
$yellow: #ffc900;
$cyan: #00d4ff;
$shadow: rgba(0, 0, 0, .5);
/* Breakpoints */
$lg: 1200px;
$md: 992px 1199px;
$sm: 768px 991px;
$xs: max-width 767px;
$xxs: max-width 449px;

/* Grid */
@mixin round() {
  border-radius: 50%;
}
/* Customs */
body, html {
  min-height: 100%;
  box-sizing: border-box;
   & * {
    outline: 0;
    border: 0;
    margin: 0;
    padding: 0;
    text-decoration: none;
    box-sizing: border-box;
    &:active {
      outline: 0;
    }
    &:focus {
      outline: 0;
    }
     &:hover {
       text-decoration: none;
     }
  }
}
body {
  font: {
    family: $stackPoppins;
    size: 16px;
  }
  line-height: 135%;
  font-size-adjust: 100%;
  word-break: break-word;
  hyphens: auto;
  -webkit-hyphenate-after: 3;
  -webkit-hyphenate-before: 2;
  hyphenate-lines: 3;
  padding: 5% 0 15%;
  background-color: $yellow;
  color: $purple;
  @include breakpoint($xxs) {
    padding-bottom: 30%;
  }
}

h1 {
  font-family: $stackLobster;
}
button, .display__time {
  cursor: pointer;
}

.title {
  font-size: (70em / 16);
  text-shadow: -3px 0 0 $shadow;
   @include breakpoint($xxs) {
    font-size: 20vw;
  }
}
.author, .offer {
  background-color: $purple;
  border: 1px solid darken($purple, 10%)
}

.offer {
  font-size: (25em / 16);
  padding: (38em / 87) (48em / 345);
  max-width: 345px;
  width: 24.99%;
  padding: 4% 0;
  margin: ((100% / 768) * 100) auto 0;
  box-shadow: 0px -3px 9px $shadow;
  color: $yellow;
  @include breakpoint($lg) {
     margin-top: (50% / 768) * 100;
  }
  @include breakpoint($md) {
     margin-top: (60% / 768) * 100;
  }
  @include breakpoint($sm) {
    width: 39%;
  }
  @include breakpoint($xs) {
    width: 58%;
  }
  @include breakpoint($xxs) {
    width: 80vw;
    max-width: 220px; 
  }
}

.author {
  font-size: (23em / 16);
  padding: ((20% / 117) * 10) ((70% / 338) * 10);
  max-width: 338px;
  color: $cyan; 
  position: fixed;
  bottom: 0;
  right: 0;
  line-height: 160%;
  @include breakpoint($xxs) {
    width: 100vw;
    max-width: none;
  }
}
.author__name, .settings > .active {
  color: $yellow;
  transition: color 0.5s;
  &:hover {
    color: #cecece;
  }
} 
.author__name {
  font: {
    family: $stackLobster;
    size: (25em / 16);
  }
  &:focus {
    color: $yellow;
    text-decoration: none;
  }
  &:active {
    color: currentColor;
  }
}

#timer {
  margin-top: 5%;
}

.timer {
  margin: 0 auto;
  transform-style: preserve-3d;
  min-height: 230px;
  perspective: 100px;
  width: 33.33%;
  @include breakpoint($sm) {
    width: 50%;
  }
  @include breakpoint($xs) {
    min-width: 270px;
    width: 75%;
  }
  @include breakpoint($xxs) {
    width: 91.66%;
  }
}

.timer__roof{
  background-color: $purple;
  transform: rotateX(20deg);
  height: 70px;
  width: 88%;
  margin: 0 auto -10px;
  z-index: 1;
  box-shadow: 0px -10px 10px $shadow;
}
.display {
  z-index: 3;
  background-color: darken($purple, 10%);
  height: 135px;
  border: 5px solid darken($purple, 15%);
  color: $cyan;
  border-radius: 3%;
  box-shadow: 0 3px 5px $shadow;
}
.settings, .display {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: space-around;
}

.settings {
  width: 100%;
  flex-wrap: no-wrap;
}
.settings__break, .settings__time {
  color: inherit;
  background-color: transparent;
}
.settings__break, .settings__time, .display__time {
  transition: color 0.5s;
  &:hover {
    color: darken($cyan, 10%);
  }
}

.display__time {
  font: {
    size: 60px;
    weight: bold;
  }
}

.display__increase, .display__decrease {
  width: (41% / 280) * 100;
  height: (41% / 135) * 100;
  background-color: $cyan;
  position: relative;
  @include round;
  max-width: 39px;
  transition: background-color 0.5s;
  &:hover {
    background-color: darken($cyan, 10%);
  }
  &:after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    top: 37%;
    left: 37%;
    background-color: darken($purple, 10%);
    @include round;
  }
}
              
            
!

JS

              
                let header = document.getElementById('title'),
    timer = document.getElementById('timer'),
    footer = document.getElementById('author');


function Header(props) {
  return (
    <div className='container text-center'>
      <h1 className='title'>
        The Pomodoro timer 
      </h1>
      <h3 className='offer'>
        Choose a time
      </h3>
    </div>
  );
}

class Footer extends React.Component {
  constructor(props) {
    super(props);
    
    this.openUrl = this.openUrl.bind(this);
  }
  
  openUrl(e) {
    let url = e.target.getAttribute('href');
   
    window.open(url);
    
    e.preventDefault();
  }
  
  
  render() {
    return (
      <p className='author text-center'>
        Design and Coded
        <br/>
        <a href='http://shining-present.ru/' className='author__name' onClick={this.openUrl}>
         by Filipp Zhuravlev
        </a> 
      </p>
    ); 
  }
}

class Timer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      pomodoroTime: '25:00',
      breakTime: '05:00',
      pomodoroMinutes: 25,
      breakMinutes: 5,
      choosenPomodoroMinutes: 25,
      choosenBreakMinutes: 5,
      isPomodoroTimeActive: true,
      isStarted: false
    }
    
    this.increaceTime = this.increaceTime.bind(this);
    this.decreaceTime = this.decreaceTime.bind(this);
    this.toggleTime = this.toggleTime.bind(this);
    this.startTimer = this.startTimer.bind(this);
    this.clearTimer = this.clearTimer.bind(this);
  }
  
  startTimer() {
    let isStarted = this.state.isStarted;
    
    // Just don't start break time. 
    if (!isStarted && !this.state.isPomodoroTimeActive) return false;
    
    // Stop and rerender timer.
    if (isStarted &&
        this.state.pomdoroMinutes !== 0) {
      this.clearTimer();
      return false;
    }
    
     this.setState({isStarted: true});
    
    
      this.timerID = setInterval(
        () => this.tickPomodoro(), 1000
      );
  }
  // Recover display and clear timer.
  clearTimer() {
    clearInterval(this.timerID);
    
    let choosenPomodoroMinutes = this.state.choosenPomodoroMinutes,
        choosenBreakMinutes = this.state.choosenBreakMinutes; 
       
    this.setState({
      isStarted: false,
      isPomodoroTimeActive: true,
      pomodoroTime: convertTime(choosenPomodoroMinutes) ,
      breakTime: convertTime(choosenBreakMinutes),
      pomodoroMinutes: choosenPomodoroMinutes,
      breakMinutes: choosenBreakMinutes
    });
  }
  
  tickPomodoro() {
    if (this.state.pomodoroMinutes < 0.017) {
      clearInterval(this.timerID);
      // Switch time.
      this.setState({isPomodoroTimeActive: false});
      
      this.timerID = setInterval(
        () => this.tickBreak(), 1000
      );
    } else {
      updateTime(this, '', 0, true); 
    }
  }
  
  tickBreak() {
    if (this.state.breakMinutes < 0.017) {
      this.clearTimer();
      return false;
    } else {
     updateTime(this, '', 0, true); 
    }
  }
  
  increaceTime() {
    if (this.state.isStarted) return false;
    
    updateTime(this, 'increace', 55, false);
  }
  
  decreaceTime() {
    if (this.state.isStarted) return false;
    
    updateTime(this, 'decreace', 0, false);
  }
  
  // Toggle between pomdoro time and break time, therefore, to show one of it. 
  toggleTime(e) {
    let isActive = this.state.isPomodoroTimeActive;
    if (e.target.value === 'time') 
      this.setState({isPomodoroTimeActive: true});
    
    if (e.target.value === 'break')
      this.setState({isPomodoroTimeActive: false});
      
  }
  
  render() {
    const pomodoroTime = this.state.pomodoroTime,
          breakTime = this.state.breakTime,
          isActivePomodoroTime = this.state.isPomodoroTimeActive,
          isStarted = this.state.isStarted,
          setTime = <SettingsButton 
                button='time'
                func={this.toggleTime}
                className={isActivePomodoroTime ? 'settings__time active' : 'settings__time' }  />,
          setBreak = <SettingsButton 
                button='break' 
                func={this.toggleTime} 
                  className={!isActivePomodoroTime ? 'settings__break active' : 'settings__break'} />,
          singleSetButton = isActivePomodoroTime ? setTime : setBreak,
          settingButtons = !isStarted ? [ setTime, setBreak] : singleSetButton;
    
      
    return (
      <div className='container'>
        <div className='timer'>
          <div className='timer__roof' />
          <div className='display'>
            <div className='settings'>
              {settingButtons}
            </div>
            <button 
              className='display__decrease' 
              onClick={this.decreaceTime}>
            </button>
            <div className='display__time' onClick={this.startTimer}> 
              {isActivePomodoroTime ? pomodoroTime : breakTime}
            </div>
            <button
              className='display__increase'
              onClick={this.increaceTime}>
            </button>
          </div>
        </div>
      </div>
    );
  }
}

// Break and Time buttons.
function SettingsButton(props) { 
    return (
      <button 
        value={props.button} 
        onClick={props.func}
        className={props.className}>
        {props.button == 'time' ? 'Time' : 'Break'}
      </button>
    );
}

ReactDOM.render(<Header />, header);
ReactDOM.render(<Timer />, timer);
ReactDOM.render(<Footer />, footer);

// Countdown time when timer is strated.
function countdown(minutes) {
  return (minutes * 60 * 1000 - 1000) / 1000 / 60;
};

function updateTime(that, action, limit, auto) {
  let isPomodoroTimeActive = that.state.isPomodoroTimeActive,
        curMinutes = isPomodoroTimeActive ? that.state.pomodoroMinutes : that.state.breakMinutes,
      minutes = 0;
    if (curMinutes === limit)
      return false;
    
    if (!auto)
      minutes = action === 'increace' ? curMinutes + 5 : curMinutes - 5;
    else       
      minutes = isPomodoroTimeActive ? countdown(that.state.pomodoroMinutes) : countdown(that.state.breakMinutes);
    console.log(minutes);
  
    let time = convertTime(minutes);

    if (isPomodoroTimeActive) {
      if (!auto)
        that.setState({choosenPomodoroMinutes: minutes});
  
      that.setState({
        pomodoroMinutes: minutes,
        pomodoroTime: time    
      });
    } else {
      if (!auto)
        that.setState({choosenBreakMinutes: minutes});
  
      that.setState({
        breakMinutes: minutes,
        breakTime: time    
      });
    }
}

// Convert date to string as xx:xx.
function convertTime(minutes) {
  let milliseconds = minutes * 60 * 1000,
      date = new Date(milliseconds),
      m = date.getMinutes(),
      s = date.getSeconds(),
      mStr = addZero(m),
      sStr = addZero(s);
      
      return mStr + ':' + sStr;
};

function addZero(time) {
  return time.toString().length === 1 ? '0' + time : time;
}
              
            
!
999px

Console