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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <meta name="theme-color" content="#000000" />

    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

    <title>React Clock</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
  </body>
</html>

              
            
!

CSS

              
                $color-lightest-gray: #f0f0f0;
$color-light-gray: #cecece;
$color-medium-gray: #adadad;
$color-dark-gray: #414141;
$color-white: #fff;
$color-black: #000;
$color-dark-purple: #1f2029;
$belt-highlight: #050404;

@mixin black-hands() {
  background-image: linear-gradient(
    -10deg,
    $color-dark-gray 0%,
    $color-black 50%
  );
  border-bottom-right-radius: 40%;
  border-bottom-left-radius: 40%;
}
@mixin rounded-hands() {
  border-bottom-right-radius: 50%;
  border-bottom-left-radius: 50%;
}

@mixin hands-gradient() {
  background-image: linear-gradient(
    -70deg,
    $color-white 15%,
    rgba($color-black, 1) 100%
  );
  box-shadow: inset 0 2px 5px $color-dark-gray, -1px 0 5px $color-black;
}

body {
  height: 100vh;
  width: 100%;
  background: lighten($color-dark-purple, 3);
  z-index: -99;
  overflow: hidden;
}
#root,
.App {
  height: 100vh;
  width: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
main {
  height: 100%;
  width: 100%;
  display: inline-block;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper {
  display: inline-block;
  position: relative;
}

.wrapper {
  &:after,
  &:before {
    content: "";
    position: absolute;
    width: 120px;
    height: 100vh;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 20px;
  }
  &:after {
    background: $belt-highlight;
    background: linear-gradient(
      162deg,
      $belt-highlight 6%,
      $color-black 50%,
      $belt-highlight 100%
    );
    box-shadow: inset 2px 3px 25px lighten($color-black, 15),
      inset -2px 3px 10px lighten($color-black, 15);
  }
  &:before {
    width: 6px;
    height: 100%;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, 70%);
    background: repeating-linear-gradient(
      to bottom,
      lighten($color-black, 15),
      lighten($color-black, 15) 6px,
      transparent 6px,
      transparent 60px
    );
    z-index: 5;
  }
}

.clock {
  width: 230px;
  height: 230px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: linear-gradient(
    -15deg,
    lighten($color-black, 4) 35%,
    $color-lightest-gray 100%
  );
  box-shadow: inset 0 2px 20px $color-dark-gray;
  position: relative;
  z-index: 100;
}

.time {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: #3c3c3c;
  background: linear-gradient(
    162deg,
    #3c3c3c 10%,
    $color-black 68%,
    $color-black 100%
  );
  box-shadow: inset 0 -2px 4px $color-light-gray, inset 0 1px 15px $color-black;
  position: relative;

  .hand {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate3d(-50%, 0, 0) rotate(180deg);
    transform-origin: 50% 0;

    &.seconds {
      height: 90px;
      width: 2px;
      background-image: linear-gradient(
        40deg,
        $color-lightest-gray 35%,
        $color-medium-gray 100%
      );
      box-shadow: -1px 0 1px rgba($color-white, 0.7) inset,
        1px 0 1px rgba($color-medium-gray, 0.8) inset;

      @include rounded-hands;

      &:after {
        position: absolute;
        content: "";
        background-image: linear-gradient(
          -10deg,
          $color-black 35%,
          $color-dark-gray 100%
        );
        box-shadow: 1px 0 3px rgba($color-medium-gray, 0.8) inset,
          -1px 0 3px rgba($color-white, 0.7) inset;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        top: 0;
        left: 50%;
        transform: translate3d(-50%, -50%, 0);
      }
    }
    &.minutes {
      height: 80px;
      width: 6px;
      @include hands-gradient;
      @include rounded-hands;

      &:before {
        content: "";
        position: absolute;
        width: 3px;
        height: 60px;
        top: 15%;
        left: 0;
        transform: translate3d(50%, -15%, 0);
        @include black-hands;
      }
    }
    &.hours {
      height: 60px;
      width: 8px;
      @include hands-gradient;
      @include rounded-hands;

      &:before {
        content: "";
        position: absolute;
        width: 4px;
        height: 35px;
        top: 15%;
        left: 0;
        transform: translate3d(50%, -15%, 0);
        @include black-hands;
      }
    }
  }
}

.hour-lines {
  position: absolute;
  left: 50%;
  top: 50%;
}
.hour-line {
  position: absolute;
  background: $color-white;
  height: 5px;
  width: 2px;
  border-radius: 50%;
  @for $i from 1 through 12 {
    &:nth-of-type(#{$i}) {
      transform: translate(-50%, -50%) rotate(($i - 1) * 30deg) translateY(84px);
      @if ($i % 3 == 1) {
        background: rgb(62, 33, 47);
        background: linear-gradient(
          124deg,
          rgba(62, 33, 47, 1) 0%,
          rgba(70, 16, 32, 1) 100%
        );
        height: 8px;
        width: 2.5px;
      }
    }
  }
}

              
            
!

JS

              
                class ClockHand extends React.Component {
  getStyle = () => {
    return {
      transform: `translateX(-50%) rotate(${this.props.rotate}deg)`,
      transition: `${
        (this.props.rotate > 534 || this.props.rotate <= 182) &&
        this.props.name === "seconds"
          ? "none"
          : 0.2 + "s cubic-bezier(0.4, 2.08, 0.55, 0.44)"
      }`
    };
  };

  render() {
    return (
      <div className={`hand ${this.props.name}`} style={this.getStyle()} />
    );
  }
}

class App extends React.Component {
  state = {
    hours: 0,
    minutes: 0,
    seconds: 0
  };

  componentDidMount() {
    setInterval(() => {
      this.updateClock();
    }, 1000);
  }

  updateClock = () => {
    let hours = new Date().getHours();
    let minutes = new Date().getMinutes();
    let seconds = new Date().getSeconds();
    this.setState({
      hours: hours * 30 + 180,
      minutes: minutes * 6 + 180,
      seconds: seconds * 6 + 180
    });
  };

  render() {
    return (
      <div className="App">
        <main>
          <div className="wrapper">
            <div className="clock">
              <div className="time">
                <div className="hour-lines">
                  {Array(12)
                    .fill()
                    .map((el, i) => (
                      <div className="hour-line" key={i} />
                    ))}
                </div>
                <ClockHand name="hours" rotate={this.state.hours} />
                <ClockHand name="minutes" rotate={this.state.minutes} />
                <ClockHand name="seconds" rotate={this.state.seconds} />
              </div>
            </div>
          </div>
        </main>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("root"));
              
            
!
999px

Console