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 class="hero is-info is-fullheight is-bold">
  <div id="app" class="hero-body"></div>
</div>
              
            
!

CSS

              
                body {
  --width: 2vmin;
  --len: 8vmin;
  --color: #ddd;
}

.timer {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.button {
  margin: 5px;
}

.colon {
  position: relative;
  margin: calc(var(--width) + 1vmin);
}

.colon::before,
.colon::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translate(-50%, 50%);
  width: var(--width);
  height: var(--width);
  background: var(--color);
}

.colon::before {
  top: calc(var(--len) / 2);
}

.colon::after {
  bottom: calc(var(--len) / 2);
}

.digit {
  position: relative;
  width: var(--len);
  margin: calc(var(--len) * 1.5) calc(var(--len) / 2) calc(var(--len) * 1.7);
}

.stick {
  --half-width: calc(var(--width) / 2);
  --origin-left: calc(0vmin - var(--half-width));
  --origin-right: calc(var(--len) + var(--half-width));
  position: absolute;
  width: var(--len);
  height: var(--width);
  background: var(--color);
  border-radius: 11% / 15%;
  transition: transform 0.4s;
}

.stick::before,
.stick::after {
  content: '';
  position: absolute;
  top: 0;
  border: var(--half-width) solid transparent;
}

.stick::before {
  right: 98%;
  border-right: var(--half-width) solid var(--color);
}

.stick::after {
  left: 98%;
  border-left: var(--half-width) solid var(--color);
}

.stick.one {
  transform-origin: var(--origin-right) 50%;
  transform: rotate(90deg);
}

.stick.two {
  transform-origin: var(--origin-right) 50%;
  transform: rotate(270deg);
}

.stick.three {
  transform-origin: var(--origin-left) 50%;
  transform: rotate(90deg);
}

.stick.four {
  transform-origin: var(--origin-left) 50%;
  transform: rotate(270deg);
}

.stick.five {
  transform-origin: var(--origin-right) 50%;
  transform: rotate(270deg);
}

.stick.six {
  transform-origin: var(--origin-right) 50%;
  transform: rotate(0deg);
}

.stick.seven {
  transform-origin: var(--origin-right) 50%;
  transform: rotate(90deg);
}
              
            
!

JS

              
                const { pure, componentFromStream } = Recompose
const { Observable, BehaviorSubject, Scheduler } = Rx

Recompose.setObservableConfig({
  fromESObservable: Rx.Observable.from
})

const pomodoroSeconds = 25 * 60
const defaultSeconds$ = new BehaviorSubject(0)

/* 'started', 'paused' or 'reset' */
const timerState$ = new BehaviorSubject('reset')
  .distinctUntilChanged()

/* A number representing the seconds that had been counted. */
const countDown$ = timerState$
  .map(timerState => timerState === 'reset')
  .distinctUntilChanged()
  .switchMap(isReset =>
    isReset
    ? defaultSeconds$
    : Observable.of(Scheduler.animationFrame.now(), Scheduler.animationFrame)
      // high accuracy timing
      // repetitively calculate the diff
      .repeat()
      // extract seconds
      .map(startTime => ~~((Date.now() - startTime) / 1000))
      .distinctUntilChanged()
      // pause implementation here, two lines!
      .withLatestFrom(timerState$)
      .filter(args => args[1] === 'started')
      // count the output
      .scan(count => count + 1, 0)
      // time's up!
      .take(pomodoroSeconds)
  )

const Title = componentFromStream(() =>
  // distinctUntilChanged is just like shouldComponentUpdate! Yay!
  timerState$.map(timerState => {
    let title
    switch (timerState) {
      case 'started':
        title = 'Greatness is within sight!!'
        break
      case 'paused':
        title = 'Never quite, keep going!!'
        break
      default:
        title = 'Let the countdown begin!!'
        break
    }
    return <h2 className='title is-6'>{title}</h2>
  })
)

const TimerBtn = pure(({ onClick, icon, ariaLabel }) => (
  <button
    className="button is-dark is-large"
    onClick={onClick}
    aria-label={ariaLabel}
  >
    <i className={`fas ${icon}`} />
  </button>
))

const TimerBtnGroup = pure(() => (
  <div>
    <TimerBtn
      icon='fa-play-circle'
      ariaLabel={'Start count down'}
      onClick={() => timerState$.next('started')} />
    <TimerBtn
      icon='fa-pause-circle'
      ariaLabel={'Pause count down'}
      onClick={() => timerState$.next('paused')} />
    <TimerBtn
      icon='fa-undo'
      ariaLabel={'Reset count down'}
      onClick={() => timerState$.next('reset')} />
  </div>
))

const Digit = pure(({ digit }) => (
  <div className="digit">
    <div className="stick one" style={getRotation(digit, 0)}>
      <div className="stick three" style={getRotation(digit, 2)}>
        <div className="stick seven" style={getRotation(digit, 6)} />
      </div>
    </div>
    <div className="stick two" style={getRotation(digit, 1)}>
      <div className="stick four" style={getRotation(digit, 3)}>
        <div className="stick five" style={getRotation(digit, 4)} />
      </div>
    </div>
    <div className="stick six" style={getRotation(digit, 5)} />
  </div>
))

const Timer = componentFromStream(() => countDown$.map(seconds => {
  const secondDiff = pomodoroSeconds - seconds
  const restMinutes = (~~(secondDiff / 60)) % 60
  const restSeconds = (secondDiff - restMinutes * 60) % 60
  return (
    <div
      className='timer'
      role='timer'
      aria-live={restSeconds % 10 === 0 ? 'polite' : 'off'}
      aria-atomic='true'
      aria-label={`${restMinutes} minutes ${restSeconds} seconds left`}
    >
      <Digit digit={~~(restMinutes / 10)} />
      <Digit digit={restMinutes % 10} />
      <div className='colon' />
      <Digit digit={~~(restSeconds / 10)} />
      <Digit digit={restSeconds % 10} />
    </div>
  )
}))

const App = () => (
  <div className='container has-text-centered'>
    <Title />
    <Timer />
    <TimerBtnGroup />
  </div>
)

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

function getRotation (digit, stick) {
  let digitMap = window[Symbol.for('digit_map')]
  if (!digitMap) {
    digitMap = [
      [ 90, 270,  90, 270, 270, 90,  90 ],
      [ 90, -90,   0, 360, 360, 90,   0 ],
      [ 90,   0,  90, 450,  90, 90,   0 ],
      [ 90, 270,  90, 270, 360,  0,   0 ],
      [  0, 270, 270, 360, 360, 90,   0 ],
      [  0, 270, 270, 270, 360,  0, 270 ],
      [  0, 270, -90, 270, 270,  0, -90 ],
      [ 90, 270,  90, 360, 360, 90,   0 ],
      [ 90, 270,  90, 270, 270,  0,  90 ],
      [ 90, 270,  90, 360, 360,  0,  90 ],
    ].map(d => d.map(s => ({ transform: `rotate(${s}deg)` })))
    window[Symbol.for('digit_map')] = digitMap
  }
  return digitMap[digit][stick]
}
              
            
!
999px

Console