css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="hero is-info is-fullheight is-bold">
  <div id="app" class="hero-body"></div>
</div>
            
          
!
            
              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);
}
            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console