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

              
                #app
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Exo:900')

*
  box-sizing border-box

body
  background linear-gradient(35deg, #111111, #fafafa)
  display flex
  font-family 'Exo', sans-serif
  margin 0
  min-height 100vh
  padding 0

#app
  align-items center
  display grid
  grid-gap 1rem
  grid-template-columns repeat(auto-fit, minmax(auto, 150px))
  justify-content center
  justify-items center
  padding 1rem 0
  width 100%

  & > div
    background repeating-linear-gradient(30deg, var(--strapColor) 0, var(--strapColor) 5px, transparent 5px, transparent 10px) 5px 0 / 90% 100% no-repeat,
      repeating-linear-gradient(-30deg, transparent 0, transparent 5px, var(--strapColor) 5px, var(--strapColor) 10px) 5px 0 / 90% 100% no-repeat, var(--strapBg)
    &:nth-of-type(1)
      --strapColor rgba(165, 55, 253, .25)
      --strapBg rgba(190, 144, 212,1)
    &:nth-of-type(2)
      --strapColor rgba(41, 241, 195, .25)
      --strapBg #29c3b9
    &:nth-of-type(3)
      --strapColor rgba(89, 171, 227, .25)
      --strapBg rgba(129, 207, 224, 1)
    &:nth-of-type(4)
      --strapColor rgba(246, 36, 89, .25)
      --strapBg rgba(226, 106, 106, 1)
    &:nth-of-type(5)
      --strapColor rgba(245, 229, 27, .25)
      --strapBg rgba(254, 241, 96, 1)
              
            
!

JS

              
                const { moment, PropTypes, styled: { default: styled }, React, ReactDOM } = window
const { Component, Fragment } = React
const { render } = ReactDOM

const clip =
  'polygon(0 5%, 5% 0, 95% 0, 100% 5%, 100% 95%, 95% 100%, 5% 100%, 0 95%)'

const Strap = styled.div`
  clip-path: ${clip};
  height: 300px;
  overflow: hidden;
  position: relative;
  width: 100px;
`

const Hand = styled.div`
  width: ${p => (p.type === 'seconds' ? 2 : 5)}px;
  height: ${p => (p.type ? 40 : 20)}px;
  background: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: bottom;
  transform: translate(-50%, -100%) rotate(${p => p.value}deg);
`

const Bezel = styled.div`
  background: silver;
  height: 60%;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  clip-path: ${clip};
  width: 102%;
`
const Screen = styled.div`
  height: 100%;
  position: absolute;
  top: 50%;
  left: 50%;
  overflow: hidden;
  transform: translate(-50%, -50%);
  width: 90%;
  background: #000;
  color: #fff;
`

const Face = styled.div`
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
`

const Value = styled.div`
  font-size: ${p => (p.small ? 2 : 3)}rem;
  line-height: ${p => (p.small ? 2 : 3)}rem;
  text-transform: uppercase;
  text-align: center;
  opacity: ${p => (p.opaque ? 0.5 : 1)};
`

const Day = styled.div`
  text-transform: uppercase;
  text-align: center;
`

const watchfacePropTypes = {
  date: PropTypes.object,
}

const DefaultFace = ({ date }) => (
  <Fragment>
    <Value>{date.format('HH')}</Value>
    <Value>{date.format('mm')}</Value>
  </Fragment>
)
DefaultFace.propTypes = watchfacePropTypes

const DateFace = ({ date }) => {
  const hours = date.format('HH')
  const minutes = date.format('mm')
  const monthYear = date.format('MMM DD')
  return (
    <Fragment>
      <Value>{hours}</Value>
      <Day>{monthYear}</Day>
      <Value>{minutes}</Value>
    </Fragment>
  )
}
DateFace.propTypes = watchfacePropTypes

const SecondsFace = ({ date }) => {
  const hours = date.format('HH')
  const minutes = date.format('mm')
  const seconds = date.format('ss')
  return (
    <Fragment>
      <Value>{hours}</Value>
      <Value>{minutes}</Value>
      <Value>{seconds}</Value>
    </Fragment>
  )
}
SecondsFace.propTypes = watchfacePropTypes

const AnalogFace = ({ date }) => {
  const seconds = (360 / 60) * date.seconds()
  const minutes = (360 / 60) * date.minutes()
  const hours = (360 / 12) * date.format('h')
  return (
    <Fragment>
      <Hand type="seconds" value={seconds} />
      <Hand type="minutes" value={minutes} />
      <Hand value={hours} />
    </Fragment>
  )
}
AnalogFace.propTypes = watchfacePropTypes

const DayFace = ({ date }) => {
  const hours = date.format('H')
  const minutes = date.format('mm')
  const dayN = date.format('dd')
  const day = date.format('DD')
  return (
    <Fragment>
      <Value small>{hours}</Value>
      <Value small>{minutes}</Value>
      <Value small opaque>
        {dayN}
      </Value>
      <Value small opaque>
        {day}
      </Value>
    </Fragment>
  )
}
DayFace.propTypes = watchfacePropTypes

class Watch extends Component {
  state = {
    date: moment(),
  }
  static propTypes = {
    face: PropTypes.func,
  }
  static defaultProps = {
    face: date => <DefaultFace date={date} />,
  }
  componentDidMount = () => (this.TICK = setInterval(this.update, 1000))
  componentWillUnmount = () => clearInterval(this.TICK)
  update = () => this.setState({ date: moment() })
  render = () => (
    <Strap>
      <Bezel>
        <Screen>
          <Face>{this.props.face(this.state.date)}</Face>
        </Screen>
      </Bezel>
    </Strap>
  )
}

class App extends Component {
  render = () => (
    <Fragment>
      <Watch face={date => <DayFace date={date} />} />
      <Watch />
      <Watch face={date => <AnalogFace date={date} />} />
      <Watch face={date => <DateFace date={date} />} />
      <Watch face={date => <SecondsFace date={date} />} />
    </Fragment>
  )
}

const rootNode = document.getElementById('app')
render(<App />, rootNode)

              
            
!
999px

Console