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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <div id="app"></div>
            
          
!

CSS

            
              html, body {
  background-color: #fff;
  color: #fff;
  font-family: 'Roboto', sans-serif;
  font-size: 32px;
  height: 100%;
  margin: 0;
  width: 100%;
}

#app {
  align-items: center;
  display: flex;
  justify-content: center;
  height: 100%;
  user-select: none;
}

#clock {
  align-items: center;
  background-image: url(https://goo.gl/unZnZC); /* image courtesy of vectorstock: https://www.vectorstock.com/royalty-free-vector/tomato-vector-514940 */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  flex-direction: column;
  height: 500px;
  justify-content: center;
  padding: 60px;
  width: 600px;
}

.length-container {
  align-self: stretch;
  display: flex;
  justify-content: space-around;
  margin-top: 60px;
  padding: 30px 30px 0;
}

.length {
  align-items: center;
  display: flex;
  flex-direction: column;
  padding: 15px;
}

.length span {
  padding: 15px;
}

#session {
  padding: 0 30px 30px;
  text-align: center;
}

#time-container {
  background-color: rgba(255, 255, 255, 0.29);
  border-radius: 5px;
  display: flex;
  font-size: 60px;
  justify-content: center;
  margin-top: 15px;
  padding: 30px;
}

#controls {
  display: flex;
}

#controls i {
  padding: 15px;
}
            
          
!

JS

            
              /* REDUX */

// logger middlware - courtesy of https://redux.js.org/api/applymiddleware
function logger({ getState }) {
  return next => action => {
    
    const returnValue = next(action)
    
    return returnValue
  }
}

let middleware = [logger, ReduxThunk.default]
// end logger middleware

// action & action creators

const INCREMENT_BREAK = 'INCREMENT_BREAK'
const DECREMENT_BREAK = 'DECREMENT_BREAK'
const INCREMENT_SESSION = 'INCREMENT_SESSION'
const DECREMENT_SESSION = 'DECREMENT_SESSION'
const TIMER_CONTROL = 'TIMER_CONTROL'
const START = 'START'
const PAUSE = 'PAUSE'
const RESET = 'RESET'
const TIMER_TICK = 'TIMER_TICK'

let timer = null

const tick = () => dispatch => {
  dispatch({ type: TIMER_TICK })
}

const timerControl = timerOn => {
  if (!timerOn) {
    return dispatch => {
      clearInterval(timer)
      timer = setInterval(() => dispatch(tick()), 1000)
      dispatch({ type: START })
    }
  } else {
    return dispatch => {
      clearInterval(timer)
      dispatch({ type: PAUSE })
    }
  }
}

const resetTimer = () => {
  clearInterval(timer)
  return { type: RESET }
}


// reducers

const defaultState = {
  breakLength: 5,
  sessionLength: 25,
  session: moment.duration(25, 'minutes'),
  timerOn: false,
  startBreak: false
}

const reducer = (state = defaultState, action) => {
  switch (action.type) {
    case INCREMENT_BREAK:
      return {
        ...state,
        breakLength: state.breakLength > 59 ? 60 : state.breakLength + 1
      }
    case DECREMENT_BREAK:
      return {
        ...state,
        breakLength: state.breakLength <= 1 ? 1 : state.breakLength - 1
      }
    case INCREMENT_SESSION:
      return {
        ...state,
        sessionLength: state.sessionLength > 59 ? 60 : state.sessionLength + 1,
        session: state.sessionLength > 59 ? moment.duration(60, 'minutes') : moment.duration(state.sessionLength + 1, 'minutes')
      }
    case DECREMENT_SESSION:
      return {
        ...state,
        sessionLength: state.sessionLength <= 1 ? 1 : state.sessionLength - 1,
        session: state.sessionLength <= 1 ? moment.duration(1, 'minutes') :  moment.duration(state.sessionLength - 1, 'minutes')
      }
    case START:
      return {
        ...state,
        timerOn: true
      }
    case PAUSE:
      return {
        ...state,
        timerOn: false
      }
    case TIMER_TICK:
      if (state.session._milliseconds === 0 && state.startBreak === false) {
        return {
          ...state,
          session: moment.duration(state.breakLength, 'minutes'),
          startBreak: true
        }
      } else if (state.session._milliseconds === 0 && state.startBreak === true) {        
        return {
          ...state,
          session: moment.duration(state.sessionLength, 'minutes'),
          startBreak: false
        }
      } else {
        return {
          ...state,
          session: moment.duration(state.session).subtract(1, 'seconds')
        }
      }
    case RESET:
      return defaultState
    default:
      return state
  }
}


// store

const store = Redux.createStore(reducer, Redux.applyMiddleware(...middleware))


// provider

const Provider = ReactRedux.Provider

const AppWrapper = () => (
  <Provider store={store}>
    <Clock />
  </Provider>
)


// connect

const connect = ReactRedux.connect



/* REACT */

const App = () => (
  <Clock />
)


// clock

class Clock extends React.Component {
  render () {
    return (
      <div id='clock'>
        <div className='length-container'>
          <BreakLengthConnected />
          <SessionLengthConnected />
        </div>
        <SessionConnected />
        <ControlsConnected />
      </div>
    )
  }
}


// break length

class BreakLength extends React.Component {
  increment = () => this.props.dispatch({ type: INCREMENT_BREAK })
  decrement = () => this.props.dispatch({ type: DECREMENT_BREAK })
  render () {
    return (
      <div className='length'>
        <span id='break-label'>Break Length</span>
        <div>
          <i id='break-increment' className='fas fa-arrow-up' onClick={this.increment}></i>
          <span id='break-length'>{this.props.breakLength}</span>
          <i id='break-decrement' className='fas fa-arrow-down' onClick={this.decrement}></i>
        </div>
      </div>
    )
  }
}

const BreakLengthConnected = connect(
  ({ breakLength }) => ({ breakLength }),
  null
)(BreakLength)


// session length

class SessionLength extends React.Component {
  increment = () => this.props.dispatch({ type: INCREMENT_SESSION })
  decrement = () => this.props.dispatch({ type: DECREMENT_SESSION })
  render () {
    return (
      <div className='length'>
        <span id='session-label'>Session Length</span>
        <div>
          <i id='session-increment' className='fas fa-arrow-up' onClick={this.increment}></i>
          <span id='session-length'>{this.props.sessionLength}</span>
          <i id='session-decrement' className='fas fa-arrow-down' onClick={this.decrement}></i>
        </div>
      </div>
    )
  }
}

const SessionLengthConnected = connect(
  ({ sessionLength }) => ({ sessionLength }),
  null
)(SessionLength)


// session

const Session = props => (
  <div id='session'>
    <span id='timer-label'>{ props.startBreak ? 'Break' : 'Session'}</span>
    <div id='time-container'>
      <span id='time-left'>{
          props.session._data.hours > 0
            ? '60:00'
            : moment.utc(props.session.asMilliseconds()).format('mm:ss')
      }</span>
    </div>
  </div>
)

const SessionConnected = connect(
  ({ session, startBreak }) => ({ session, startBreak })
)(Session)


// controls


class Controls extends React.Component {
  playAudio = () => {
    const clip = document.getElementById('beep')
    clip.play()
  }
  resetAudio = () => {
    const clip = document.getElementById('beep')
    clip.pause()
    clip.currentTime = 0
  }
  render () {
    const { session, timerOn, timerControl } = this.props
    session._milliseconds === 0 && this.playAudio()
    return (
      <div id='controls'>
        <div id='start_stop' onClick={() => timerControl(timerOn)}>
          <i className='fas fa-play'></i>
          <i className='fas fa-pause'></i>
        </div>
        <i id='reset' className='fas fa-sync-alt' onClick={
            () => {
              this.props.resetTimer()
              this.resetAudio()
            }
        }></i>
        <audio id='beep' preload='auto' src='https://goo.gl/cy2jQM' />
      </div>
    )
  }
}

const ControlsConnected = connect(
  ({ session, timerOn }) => ({ session, timerOn }),
  dispatch => ({
    timerControl: timerOn => dispatch(timerControl(timerOn)),
    resetTimer: () => dispatch(resetTimer())
  })
)(Controls)


// render

ReactDOM.render(<AppWrapper />, document.getElementById('app'))
            
          
!
999px

Console