Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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 id="root"></div>
              
            
!

CSS

              
                @function gray($color) {
  @return rgb($color, $color, $color);
}
$grey: rgb(99, 102, 106);
$red: rgb(239, 83, 80);
$orange: rgb(255, 160, 0);
$yellow: rgb(253, 216, 53);
$green: rgb(42, 252, 152);
$indigo: rgb(57, 73, 171);
$violet: rgb(103, 58, 183);

/* -- */

$blue: rgb(66, 165, 245);

@keyframes blink {
  from,
  25%,
  to {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(720deg);
  }

  to {
    transform: rotate(1440deg);
  }
}

@keyframes bounce {
  from,
  6.66%,
  17.66%,
  33.33% {
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    transform: translate3d(0, 0, 0);
  }

  13.33%,
  14.33% {
    animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
    transform: translate3d(0, -30px, 0) scaleY(1.1);
  }

  23.33% {
    animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
    transform: translate3d(0, -15px, 0) scaleY(1.05);
  }

  26.66% {
    transition-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    transform: translate3d(0, 0, 0) scaleY(0.95);
  }

  30% {
    transform: translate3d(0, -4px, 0) scaleY(1.02);
  }
}

body {
  margin: 0px;
  overflow-x: hidden;
  padding: 0px;

  &::-webkit-scrollbar-track {
    background-color: gray(30);
  }

  &::-webkit-scrollbar-thumb {
    background-color: rgba(white, 0.2);
    border-radius: 100px;
  }

  &::-webkit-scrollbar {
    height: 4px;
    width: 4px;
  }

  input,
  h1,
  h3,
  a,
  span {
    color: gray(90);
    font-family: "Rubik", sans-serif;
    font-weight: 400;
    margin: 0px;
    padding: 0px;
  }
}

$backgroundImage: "https://assets.codepen.io/7773162/mesa-arch-3840x2160-5k-4k-wallpaper-utah-usa-mountains-sunset-6125.jpg";

.background-image {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.clear-button {
  backdrop-filter: blur(3px);
  background-color: rgba(white, 0.1);
  border: 1px solid rgba(white, 0.1);
  border-radius: 100px;
  box-shadow: 2px 2px 2px rgba(black, 0.1);
  cursor: pointer;

  &:hover {
    background-color: rgba(white, 0.2);
    border: 1px solid rgba(white, 0.3);
  }
}

#app {
  background-color: gray(30);

  &.logged-out {
    #app-info {
      margin-left: 40px;
      opacity: 1;
      transform: translateX(0%);
    }

    #app-background {
      cursor: pointer;
    }

    #sign-in-button-wrapper {
      opacity: 1;
      pointer-events: all;
      transform: translate(-50%, -40px);
    }
  }

  &.logging-in,
  &.verifying-log-in,
  &.log-in-error {
    #app-background {
      #app-background-image {
        filter: blur(8px);
        transform: scale(1.2);
      }
    }
  }

  &.logging-in,
  &.log-in-error {
    #app-pin-wrapper {
      opacity: 1;
      pointer-events: all;
      transform: translate(-50%, -50%) scale(1);
    }
  }

  &.verifying-log-in {
    #app-loading-icon {
      opacity: 1;
      transform: translate(-50%, -50%);
    }
  }

  &.log-in-error {
    #app-pin-wrapper {
      #app-pin {
        .app-pin-digit {
          background-color: rgba($red, 0.05);
          border-color: rgba($red, 0.5);
        }
      }
    }
  }

  &.logged-in {
    #app-menu {
      height: auto;
      overflow: initial;
      opacity: 1;
      pointer-events: all;
      transform: translateY(0%);
    }
  }

  .scrollable-component {
    cursor: grab;
    overflow: auto;
    user-select: none;
    width: 100%;

    &:active {
      cursor: grabbing;
    }

    &::-webkit-scrollbar {
      height: 0px;
      width: 0px;
    }
  }

  #app-loading-icon {
    left: 50%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translate(-50%, 0%);
    transition: opacity 250ms, transform 250ms;
    z-index: 2;

    i {
      animation: 2s spin ease-in-out infinite;
      color: white;
      font-size: 2em;
    }
  }

  #app-background {
    height: 100%;
    left: 0px;
    overflow: hidden;
    position: fixed;
    top: 0px;
    width: 100%;
    z-index: 1;

    #app-background-image {
      background-image: url($backgroundImage);
      height: 100%;
      transition: filter 250ms, transform 250ms;
      width: 100%;
    }
  }

  #app-info {
    bottom: 0px;
    left: 0px;
    margin: 40px;
    margin-left: 0px;
    opacity: 0;
    position: absolute;
    transform: translateX(-100%);
    transition: margin 250ms, opacity 250ms, transform 250ms;
    z-index: 2;
  }

  .user-status-button {
    cursor: pointer;
    margin-top: 10px;
    outline: none;
    padding: 10px;
    width: 100px;

    i {
      color: gray(245);
      font-size: 1.25em;
    }
  }

  #sign-in-button-wrapper {
    bottom: 0px;
    left: 50%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    transform: translate(-50%, 40px);
    transition: opacity 250ms, transform 250ms;
    z-index: 2;

    #sign-in-button {
      &:not(:hover) {
        animation: bounce 3s infinite;
        animation-delay: 3s;
      }
    }
  }

  .info {
    align-items: flex-end;
    display: flex;

    .time {
      color: gray(245);
      font-size: 6em;
      height: 80px;
      line-height: 80px;
      text-shadow: 2px 2px 2px rgba(black, 0.1);
    }

    .weather {
      display: inline-flex;
      height: 20px;
      margin-bottom: 6px;
      margin-left: 20px;

      i,
      span {
        align-items: center;
        display: inline-flex;
      }

      i {
        color: $yellow;
        font-size: 0.9em;
      }

      span {
        color: white;
      }

      .weather-type {
        height: 20px;
      }

      .weather-temperature-value {
        font-size: 1.5em;
        height: 20px;
        margin-left: 5px;
      }

      .weather-temperature-unit {
        align-items: flex-start;
        font-size: 0.8em;
        margin-left: 3px;
      }
    }
  }

  .reminder {
    display: flex;
    gap: 6px;
    margin-top: 10px;

    i,
    div {
      display: inline-flex;
    }

    i {
      color: gray(245);
      font-size: 0.8em;
      height: 12px;
      line-height: 12px;
    }

    span {
      color: rgba(white, 0.8);
      font-size: 1.25em;
    }

    .reminder-icon {
      align-items: center;
      height: 20px;
    }

    .reminder-time {
      align-items: flex-end;
      color: gray(30);
      font-size: 0.8em;
      height: 20px;
    }
  }

  #quick-nav {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    overflow: auto;
    padding-bottom: 5px;
    width: 100%;
    z-index: 3;

    .quick-nav-item {
      padding: 10px 20px;

      &:last-of-type {
        margin-right: 10px;
      }

      .quick-nav-item-label {
        color: gray(245);
        text-shadow: 0px 0px 2px rgba(black, 0.1);
      }
    }
  }

  .menu-section {
    margin-top: 60px;

    .menu-section-title {
      align-items: center;
      display: flex;
      gap: 6px;

      i,
      span {
        color: gray(245);
      }

      i {
        font-size: 1em;
      }

      .menu-section-title-text {
        color: rgba(white, 0.8);
        font-size: 1.25em;
      }
    }

    .menu-section-content {
      margin-top: 15px;
      padding-top: 5px;
    }
  }

  #restaurants-section {
    .menu-section-content {
      display: flex;
      gap: 1em;

      .restaurant-card {
        border-radius: 10px;
        box-shadow: 2px 2px 4px rgba(black, 0.25);
        cursor: pointer;
        height: 14vw;
        max-height: 240px;
        position: relative;
        transition: transform 250ms;
        width: 25%;

        &:hover {
          transform: translateY(-5px);

          .restaurant-card-content {
            .restaurant-card-content-items {
              margin-bottom: 30px;
            }
          }
        }

        .restaurant-card-content {
          background: linear-gradient(to top, rgba(black, 0.8), transparent);
          border-radius: 10px;
          height: 100%;
          width: 100%;

          .restaurant-card-content-items {
            bottom: 0px;
            display: flex;
            flex-direction: column;
            margin: 20px;
            position: absolute;
            right: 0px;
            text-align: right;
            transition: margin 250ms;

            .restaurant-card-title {
              color: gray(245);
              font-size: 1.5em;
            }

            .restaurant-card-desc {
              color: $blue;
              font-size: 0.9em;
            }
          }
        }
      }
    }
  }

  #weather-section {
    .menu-section-content {
      display: flex;
      gap: 1em;
      padding: 5px 0px;
      width: 100%;

      .day-card {
        backdrop-filter: blur(3px);
        background-color: rgba(white, 0.1);
        border: 1px solid rgba(white, 0.2);
        border-radius: 10px;
        box-shadow: 2px 2px 4px rgba(black, 0.25);
        height: 8vw;
        max-height: 160px;
        min-height: 140px;
        min-width: 180px;
        position: relative;
        transition: transform 250ms;
        width: calc(100% / 7);

        &:last-of-type {
          margin-right: 5px;
        }
        &:hover {
          transform: translateY(-5px);

          .day-card-background {
            filter: grayscale(25%);
          }
        }

        .day-card-content {
          display: flex;
          flex-direction: column;
          height: calc(100% - 20px);
          justify-content: space-evenly;
          padding: 10px;

          i,
          span {
            color: gray(245);
            text-align: center;
          }

          .day-weather-temperature {
            align-items: flex-start;
            display: flex;
            font-size: 0.9em;
            justify-content: center;

            .day-weather-temperature-unit {
              font-size: 0.8em;
              margin-left: 3px;
            }
          }

          .day-weather-icon {
            font-size: 3.5em;
            text-shadow: 2px 2px 2px rgba(black, 0.1);

            &.sunny {
              color: $yellow;
            }

            &.rainy,
            &.stormy {
              color: $blue;
            }
          }

          .day-name {
            font-size: 0.9em;
            text-transform: uppercase;
          }
        }
      }
    }
  }

  #tools-section {
    .menu-section-content {
      display: flex;
      gap: 1em;

      .tool-card {
        background-color: gray(30);
        border-radius: 10px;
        box-shadow: 2px 2px 4px rgba(black, 0.25);
        cursor: pointer;
        height: 8vw;
        max-height: 160px;
        min-height: 140px;
        overflow: hidden;
        position: relative;
        transition: transform 250ms;
        width: calc(100% / 6);

        &:hover {
          transform: translateY(-5px);

          .tool-card-background {
            filter: grayscale(25%);
          }
        }

        .tool-card-background {
          border-radius: 10px;
          filter: grayscale(100%);
          height: 100%;
          left: 0px;
          opacity: 0.5;
          position: absolute;
          top: 0px;
          transition: filter 250ms;
          width: 100%;
        }

        .tool-card-content {
          background: linear-gradient(
            to right,
            rgba(black, 0.4),
            rgba(black, 0.1)
          );
          border-radius: 10px;
          display: flex;
          flex-direction: column;
          height: calc(100% - 40px);
          justify-content: space-between;
          padding: 20px;
          position: relative;
          width: calc(100% - 40px);
          z-index: 2;

          .tool-card-content-header {
            display: flex;
            flex-direction: column;
            gap: 2px;

            .tool-card-label {
              color: $blue;
              font-size: 0.8em;
              text-transform: uppercase;
            }

            .tool-card-name {
              color: gray(245);
              font-size: 1.25em;
            }
          }

          .tool-card-icon {
            color: gray(245);
            font-size: 2em;
          }
        }
      }
    }
  }

  #movies-section {
    .menu-section-content {
      display: flex;
      gap: 1em;

      #movie-card-1 {
        .movie-card-content {
          background: linear-gradient(
            to top,
            rgba($grey, 0.4),
            transparent,
            rgba(black, 0.4)
          );
        }
      }

      #movie-card-2 {
        .movie-card-content {
          background: linear-gradient(
            to top,
            rgba($grey, 0.4),
            transparent,
            rgba(black, 0.4)
          );
        }
      }

      #movie-card-3 {
        .movie-card-content {
          background: linear-gradient(
            to top,
            rgba($grey, 0.4),
            transparent,
            rgba(black, 0.4)
          );
        }
      }

      #movie-card-4 {
        .movie-card-content {
          background: linear-gradient(
            to top,
            rgba($grey, 0.4),
            rgba(black, 0.1),
            rgba(black, 0.4)
          );
        }
      }

      .movie-card {
        background-color: gray(30);
        border-radius: 10px;
        box-shadow: 2px 2px 4px rgba(black, 0.25);
        cursor: pointer;
        height: 40vw;
        max-height: 600px;
        min-height: 460px;
        min-width: 260px;
        overflow: hidden;
        position: relative;
        transition: transform 250ms;
        width: calc(100% / 4);

        &:hover {
          transform: translateY(-5px);

          .movie-card-background {
            transform: scale(1.05);
          }

          .movie-card-content {
            i {
              transform: translate(-20%, -20%) scale(1.2);
            }
          }
        }

        .movie-card-background {
          border-radius: 10px;
          height: 100%;
          left: 0px;
          position: absolute;
          top: 0px;
          transition: transform 250ms;
          width: 100%;
          z-index: 1;
        }

        .movie-card-content {
          background: linear-gradient(
            to top,
            rgba(black, 0.5),
            rgba(black, 0.1),
            rgba(black, 0.4)
          );
          border-radius: 10px;
          height: 100%;
          position: relative;
          z-index: 2;

          .movie-card-info {
            display: flex;
            flex-direction: column;
            gap: 5px;
            padding: 30px;

            span {
              text-shadow: 2px 2px 2px rgba(black, 0.1);
            }

            .movie-card-title {
              color: gray(245);
              font-size: 2em;
            }

            .movie-card-desc {
              color: gray(200);
              font-size: 0.9em;
            }
          }

          i {
            bottom: 0px;
            color: gray(245);
            font-size: 5em;
            padding: 30px;
            position: absolute;
            right: 0px;
            text-shadow: 2px 2px 2px rgba(black, 0.1);
            transition: transform 250ms;
          }
        }
      }
    }
  }

  #app-pin-wrapper {
    left: 50%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -30%) scale(0.8);
    transition: opacity 250ms, transform 250ms;
    z-index: 2;

    #app-pin-label {
      color: gray(245);
      font-size: 0.9em;
      margin: 10px;
      text-shadow: 2px 2px 2px rgba(black, 0.1);

      #app-pin-cancel-text {
        cursor: pointer;
        margin-left: 2px;

        &:hover {
          text-decoration: underline;
        }
      }

      #app-pin-error-text {
        color: $red;
      }
    }

    #app-pin-hidden-input {
      background-color: transparent;
      border: none;
      height: 0px;
      outline: none;
      pointer-events: none;
      position: absolute;
      width: 0px;
    }

    #app-pin {
      display: flex;
      gap: 10px;

      .app-pin-digit {
        align-items: center;
        background-color: rgba(white, 0.05);
        border: 1px solid rgba(white, 0.2);
        border-radius: 10px;
        box-shadow: 2px 2px 2px rgba(black, 0.06);
        display: inline-flex;
        font-size: 3em;
        height: 80px;
        justify-content: center;
        position: relative;
        transition: background-color 250ms, border-color 250ms;
        width: 60px;

        &:after,
        &:before {
          box-shadow: 2px 2px 2px rgba(black, 0.06);
          content: "";
          position: absolute;
          transition: opacity 250ms, transform 250ms;
          z-index: 2;
        }

        &:before {
          background-color: gray(245);
          border-radius: 10px;
          bottom: 0px;
          height: 3px;
          left: 15%;
          opacity: 0;
          transform: translateY(0px);
          width: 70%;
        }

        &:after {
          background-color: gray(245);
          border-radius: 20px;
          height: 20px;
          opacity: 0;
          transform: scale(0.25);
          width: 20px;
        }

        &.focused {
          &:before {
            animation: blink 2s ease-in-out infinite;
            opacity: 1;
            transform: translateY(-10px);
          }
        }

        &.hidden {
          &:after {
            opacity: 1;
            transform: scale(1);
          }

          .app-pin-digit-value {
            opacity: 0;
            transform: scale(0.25);
          }
        }

        .app-pin-digit-value {
          color: gray(245);
          transition: opacity 250ms, transform 250ms;
        }
      }
    }
  }

  #app-menu {
    height: 100vh;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    position: relative;
    transform: translateY(-10%);
    transition: opacity 250ms, transform 250ms;
    z-index: 2;

    #app-menu-content-wrapper {
      background: linear-gradient(to bottom, transparent, gray(30));
      margin-top: 15vh;
      min-height: 80vh;
      padding: 80px;
      padding-top: 0px;

      #app-menu-content {
        margin: auto;
        max-width: 1600px;
        position: relative;

        #app-menu-content-header {
          display: flex;
          justify-content: space-between;
        }
      }
    }
  }
}

@media (max-width: 1300px) {
  #app {
    &.logged-out {
      #sign-in-button-wrapper {
        transform: translate(-40px, 0px);
      }
    }

    #sign-in-button-wrapper {
      bottom: 40px;
      left: auto;
      right: 0px;
      transform: translate(40px, 0px);
    }

    #app-menu {
      #app-menu-content-wrapper {
        padding: 30px;

        #app-menu-content {
          #restaurants-section {
            .menu-section-content {
              flex-wrap: wrap;

              .restaurant-card {
                height: 30vw;
                max-height: 300px;
                position: relative;
                width: calc(50% - 0.5em);
              }
            }
          }

          #tools-section {
            .menu-section-content {
              flex-wrap: wrap;

              .tool-card {
                width: calc(33.33% - 0.69em);
              }
            }
          }
        }
      }
    }
  }
}

@media (max-width: 600px) {
  #app {
    .info {
      .time {
        font-size: 4em;
        height: 60px;
        line-height: 60px;
      }
    }

    .user-status-button {
      width: 60px;
    }

    #app-menu {
      #app-menu-content-wrapper {
        #app-menu-content {
          #restaurants-section {
            .menu-section-content {
              flex-direction: column;

              .restaurant-card {
                height: 40vw;
                position: relative;
                width: 100%;
              }
            }
          }

          #tools-section {
            .menu-section-content {
              flex-wrap: wrap;

              .tool-card {
                width: calc(50% - 0.5em);
              }
            }
          }
        }
      }
    }
  }
}

@media (max-width: 400px) {
  #app {
    #app-menu {
      #app-menu-content-wrapper {
        #app-menu-content {
          #tools-section {
            .menu-section-content {
              flex-wrap: wrap;

              .tool-card {
                width: 100%;
              }
            }
          }
        }
      }
    }
  }
}

              
            
!

JS

              
                enum UserStatus {  
  LoggedIn = "Logged In",
  LoggingIn = "Logging In",
  LoggedOut = "Logged Out",
  LogInError = "Log In Error",
  VerifyingLogIn = "Verifying Log In"
}

enum Default {
  PIN = "1234"
}

enum WeatherType {
  Cloudy = "Cloudy",
  Rainy = "Rainy",
  Stormy = "Stormy",
  Sunny = "Sunny"
}

interface IPosition {
  left: number;
  x: number;
}

const defaultPosition = (): IPosition => ({
  left: 0,
  x: 0
});

interface INumberUtility {
  clamp: (min: number, value: number, max: number) => number;
  rand: (min: number, max: number) => number;
}

const N: INumberUtility = {
  clamp: (min: number, value: number, max: number) => Math.min(Math.max(min, value), max),
  rand: (min: number, max: number) => Math.floor(Math.random() * (max - min + 1) + min)
}

interface ITimeUtility {
  format: (date: Date) => string;
  formatHours: (hours: number) => string;
  formatSegment: (segment: number) => string;
}

const T: ITimeUtility = {
  format: (date: Date): string => {
    const hours: string = T.formatHours(date.getHours()),
          minutes: string = date.getMinutes(),
          seconds: string = date.getSeconds();
    
    return `${hours}:${T.formatSegment(minutes)}`;
  },
  formatHours: (hours: number): string => {
    return hours % 12 === 0 ? 12 : hours % 12;
  },
  formatSegment: (segment: number): string => {
    return segment < 10 ? `0${segment}` : segment;
  }
}

interface ILogInUtility {
  verify: (pin: string) => Promise<boolean>;
}

const LogInUtility: ILogInUtility = {
  verify: async (pin: string): Promise<boolean> => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        if(pin === Default.PIN) {
          resolve(true);
        } else {
          reject(`Invalid pin: ${pin}`);
        }
      }, N.rand(300, 700));
    });
  }
}

const useCurrentDateEffect = (): Date => {
  const [date, setDate] = React.useState<Date>(new Date());

  React.useEffect(() => {
    const interval: NodeJS.Timeout = setInterval(() => {
      const update: Date = new Date();

      if(update.getSeconds() !== date.getSeconds()) {
        setDate(update);
      }
    }, 100);

    return () => clearInterval(interval);
  }, [date]);
  
  return date;
}

interface IScrollableComponentState {
  grabbing: boolean;
  position: IPosition;
}

interface IScrollableComponentProps {
  children: any;
  className?: string;
  id?: string;
}

const ScrollableComponent: React.FC<IScrollableComponentProps> = (props: IScrollableComponentProps) => {
  const ref: React.MutableRefObject<HTMLDivElement> = React.useRef<HTMLDivElement>(null);
  
  const [state, setStateTo] = React.useState<IScrollableComponentState>({
    grabbing: false,
    position: defaultPosition()
  });
  
  const handleOnMouseDown = (e: any): void => {
    setStateTo({
      ...state,
      grabbing: true,
      position: {
        x: e.clientX,
        left: ref.current.scrollLeft
      }
    });
  }
  
  const handleOnMouseMove = (e: any): void => {
    if(state.grabbing) {
      const left: number = Math.max(0, state.position.left + (state.position.x - e.clientX));
      
      ref.current.scrollLeft = left;
    }
  }
  
  const handleOnMouseUp = (): void => {
    if(state.grabbing) {
      setStateTo({ ...state, grabbing: false });
    }
  }
  
  return (
    <div 
      ref={ref} 
      className={classNames("scrollable-component", props.className)}
      id={props.id}
      onMouseDown={handleOnMouseDown}
      onMouseMove={handleOnMouseMove}
      onMouseUp={handleOnMouseUp}
      onMouseLeave={handleOnMouseUp}
    >
      {props.children}
    </div>
  );
}

const WeatherSnap: React.FC = () => {  
  const [temperature] = React.useState<number>(N.rand(65, 85));
  
  return(
    <span className="weather">
      <i className="weather-type" className="fa-duotone fa-sun" />
      <span className="weather-temperature-value">{temperature}</span>
      <span className="weather-temperature-unit">°F</span>
    </span>
  )
}

const Reminder: React.FC = () => {
  return(
    <div className="reminder">
      <span className="reminder-text">Welcome to your smart home</span>      
    </div>
  )
}

const Time: React.FC = () => {
  const date: Date = useCurrentDateEffect();
  
  return(
    <span className="time">{T.format(date)}</span>
  )
}

interface IInfoProps {
  id?: string;
}

const Info: React.FC = (props: IInfoProps) => {  
  return(
    <div id={props.id} className="info">
      <Time />
      <WeatherSnap />
    </div>
  )
}

interface IPinDigitProps {
  focused: boolean;
  value: string;
}

const PinDigit: React.FC<IPinDigitProps> = (props: IPinDigitProps) => {
  const [hidden, setHiddenTo] = React.useState<boolean>(false);
  
  React.useEffect(() => {
    if(props.value) {
      const timeout: NodeJS.Interval = setTimeout(() => {
        setHiddenTo(true);
      }, 500);

      return () => {
        setHiddenTo(false);
        
        clearTimeout(timeout);
      }
    }
  }, [props.value]);
  
  return (
    <div className={classNames("app-pin-digit", { focused: props.focused, hidden })}>
      <span className="app-pin-digit-value">{props.value || ""}</span>
    </div>
  ) 
}

const Pin: React.FC = () => {
  const { userStatus, setUserStatusTo } = React.useContext(AppContext);
  
  const [pin, setPinTo] = React.useState<string>("");
  
  const ref: React.MutableRefObject<HTMLInputElement> = React.useRef<HTMLInputElement>(null);
  
  React.useEffect(() => {
    if(userStatus === UserStatus.LoggingIn || userStatus === UserStatus.LogInError) {
      ref.current.focus();
    } else {
      setPinTo("");
    }
  }, [userStatus]);
  
  React.useEffect(() => {
    if(pin.length === 4) {
      const verify = async (): Promise<void> => {
        try {
          setUserStatusTo(UserStatus.VerifyingLogIn);
          
          if(await LogInUtility.verify(pin)) {          
            setUserStatusTo(UserStatus.LoggedIn);
          }
        } catch (err) {
          console.error(err);
          
          setUserStatusTo(UserStatus.LogInError);
        }
      }
      
      verify();
    }
    
    if(userStatus === UserStatus.LogInError) {
      setUserStatusTo(UserStatus.LoggingIn);
    }
  }, [pin]);
  
  const handleOnClick = (): void => {
    ref.current.focus();
  }
  
  const handleOnCancel = (): void => {
    setUserStatusTo(UserStatus.LoggedOut);
  }
  
  const handleOnChange = (e: any): void => {
    if(e.target.value.length <= 4) {
      setPinTo(e.target.value.toString());
    }
  }
  
  const getCancelText = (): JSX.Element => {
    return (
      <span id="app-pin-cancel-text" onClick={handleOnCancel}>Cancel</span>
    )
  }
  
  const getErrorText = (): JSX.Element => {
    if(userStatus === UserStatus.LogInError) {
      return (
        <span id="app-pin-error-text">Invalid</span>
      )
    }
  }
  
  return(
    <div id="app-pin-wrapper">
      <input 
        disabled={userStatus !== UserStatus.LoggingIn && userStatus !== UserStatus.LogInError}
        id="app-pin-hidden-input" 
        maxLength={4} 
        ref={ref}
        type="number" 
        value={pin} 
        onChange={handleOnChange} 
      />
      <div id="app-pin" onClick={handleOnClick}>
        <PinDigit focused={pin.length === 0} value={pin[0]} />
        <PinDigit focused={pin.length === 1} value={pin[1]} />
        <PinDigit focused={pin.length === 2} value={pin[2]} />
        <PinDigit focused={pin.length === 3} value={pin[3]} />
      </div>
      <h3 id="app-pin-label">Enter PIN (1234) {getErrorText()} {getCancelText()}</h3>
    </div>
  )
}

interface IMenuSectionProps {
  children: any;
  icon: string;
  id: string;
  scrollable?: boolean;
  title: string;
}

const MenuSection: React.FC<IMenuSectionProps> = (props: IMenuSectionProps) => {
  const getContent = (): JSX.Element => {
    if(props.scrollable) {
      return (
        <ScrollableComponent className="menu-section-content">
          {props.children}
        </ScrollableComponent>
      );
    }
  
    return (    
      <div className="menu-section-content">
        {props.children}  
      </div>
    );
  }
  
  return (
    <div id={props.id} className="menu-section">
      <div className="menu-section-title">
        <i className={props.icon} />
        <span className="menu-section-title-text">{props.title}</span>
      </div>
      {getContent()}
    </div>
  )
}

const QuickNav: React.FC = () => {  
  const getItems = (): JSX.Element[] => {
    return [{
      id: 1,
      label: "Energy Production"
    }, {
      id: 2,
      label: "Thermostat"
    }, {
      id: 3,
      label: "All-Lights"
    }, {
      id: 4,
      label: "Goodnight"
    }].map((item: any) => {
      return (
        <div key={item.id} className="quick-nav-item clear-button">
          <span className="quick-nav-item-label">{item.label}</span>
        </div>
      );
    })
  }

  return (
    <ScrollableComponent id="quick-nav">
      {getItems()}    
    </ScrollableComponent>
  );
}

const Weather: React.FC = () => { 
  const getDays = (): JSX.Element[] => {
    return [{
      id: 1,
      name: "Mon",
      temperature: N.rand(60, 80),
      weather: WeatherType.Sunny
    }, {
      id: 2,
      name: "Tues",
      temperature: N.rand(60, 80),
      weather: WeatherType.Sunny
    }, {
      id: 3,
      name: "Wed",
      temperature: N.rand(60, 80),
      weather: WeatherType.Cloudy
    }, {
      id: 4,
      name: "Thurs",
      temperature: N.rand(60, 80),
      weather: WeatherType.Rainy
    }, {
      id: 5,
      name: "Fri",
      temperature: N.rand(60, 80),
      weather: WeatherType.Stormy
    }, {
      id: 6,
      name: "Sat",
      temperature: N.rand(60, 80),
      weather: WeatherType.Sunny
    }, {
      id: 7,
      name: "Sun",
      temperature: N.rand(60, 80),
      weather: WeatherType.Cloudy
    }].map((day: any) => {
      const getIcon = (): string => {
        switch(day.weather) {
          case WeatherType.Cloudy:
            return "fa-duotone fa-clouds";
          case WeatherType.Rainy:
            return "fa-duotone fa-cloud-drizzle";
          case WeatherType.Stormy:
            return "fa-duotone fa-cloud-bolt";
          case WeatherType.Sunny:
            return "fa-duotone fa-sun";
        }
      }
      
      return (
        <div key={day.id} className="day-card">
          <div className="day-card-content">
            <span className="day-weather-temperature">{day.temperature}<span className="day-weather-temperature-unit">°F</span></span>
            <i className={classNames("day-weather-icon", getIcon(), day.weather.toLowerCase())} />
            <span className="day-name">{day.name}</span>  
          </div>  
        </div>
      );
    });
  }
  return(
    <MenuSection icon="fa-solid fa-sun" id="weather-section" scrollable title="How's it look out there?">
      {getDays()}
    </MenuSection>
  )
}

const Tools: React.FC = () => {  
  const getTools = (): JSX.Element[] => {
    return [{
      icon: "fa-solid fa-air-conditioner",
      id: 1,
      image: "https://scottbrothersnc.com/wp-content/uploads/AC_A_002-ductless-AC-1.jpg",
      label: "Connected",
      name: "Air Conditioner"
    }, {
      icon: "fa-solid fa-vent-damper",
      id: 2,
      image: "https://blog-123-bucket.s3.amazonaws.com/wp-content/uploads/2020/11/27043913/123design.CleanTech_UVC_air_purifier_hero_01-1024x683.jpg",
      label: "Air Purifier",
      name: "Connected"
    }, {
      icon: "fa-solid fa-tv",
      id: 3,
      image: "https://i.pinimg.com/originals/2f/e1/35/2fe1356ea7e1949bb827bc2ef4394c99.jpg",
      label: "Control",
      name: "Apple TV"
    }, {
      icon: "fa-solid fa-battery-bolt",
      id: 4,
      image: "https://cdn.dribbble.com/users/937241/screenshots/3739479/power_3.jpg?compress=1&resize=800x600&vertical=top",
      label: "Utilities",
      name: "Energy Usage"
    }, {
      icon: "fa-solid fa-router",
      id: 5,
      image: "https://www.netgear.com/ie/media/WiFi_page_thin_banner_mobile_tcm161-129895.jpg",
      label: "Network",
      name: "Wifi"
    }, {
      icon: "fa-solid fa-speaker",
      id: 6,
      image: "https://www.audiocontrol.com/wp-content/uploads/2020/05/new-home-theater-web-slide-v1.jpg",
      label: "Audio",
      name: "Home Speakers"
    }].map((tool: any) => {
      const styles: React.CSSProperties = {
        backgroundImage: `url(${tool.image})`  
      }
      
      return (
        <div key={tool.id} className="tool-card">
          <div className="tool-card-background background-image" style={styles} />
          <div className="tool-card-content">            
            <div className="tool-card-content-header">            
              <span className="tool-card-label">{tool.label}</span>
              <span className="tool-card-name">{tool.name}</span>
            </div>
            <i className={classNames(tool.icon, "tool-card-icon")} />
          </div>
        </div>
      );
    })
  }
  
  return (
    <MenuSection icon="fa-solid fa-rectangles-mixed" id="tools-section" title="Other Controls">
      {getTools()}
    </MenuSection>
  );
}

const Restaurants: React.FC = () => {  
  const getRestaurants = (): JSX.Element[] => {
    return [{
      desc: "Lights",
      id: 1,
      image: "https://hommes.studio/wp-content/uploads/what-is-brutalist-design-brutalist-furniture-1.jpg",
      title: "Living Room"
    } , {
      desc: "Lights",
      id: 2,
      image: "http://cdn.home-designing.com/wp-content/uploads/2019/02/master-bedroom-curtains.jpg",
      title: "Master Bedroom"
    }, {
      desc: "Lights",
      id: 3,
      image: "https://cdn.habitusliving.com/wp-content/uploads/CanadianBayMakerMayccDanielFuge_kitchen-island.jpg",
      title: "Kitchen"
    }, {
      desc: "Lights",
      id: 4,
      image: "http://cdn.home-designing.com/wp-content/uploads/2021/03/black-home-office.jpg",
      title: "Office"
    }].map((restaurant: any) => {
      const styles: React.CSSProperties = {
        backgroundImage: `url(${restaurant.image})`  
      }
      
      return (
        <div key={restaurant.id} className="restaurant-card background-image" style={styles}>
          <div className="restaurant-card-content">
            <div className="restaurant-card-content-items">
              <span className="restaurant-card-title">{restaurant.title}</span>
              <span className="restaurant-card-desc">{restaurant.desc}</span>  
            </div>
          </div>
        </div>
      )
    });
  }
  return(   
    <MenuSection icon="fa-regular fa-lightbulb" id="restaurants-section" title="Home Lighting Controls">
      {getRestaurants()}
    </MenuSection>
  )
}

const Movies: React.FC = () => {  
  const getMovies = (): JSX.Element[] => {
    return [{
      desc: "Dashboard Stats",
      id: 1,
      icon: "fa-solid fa-battery-full",
      image: "https://www.tesla.com/sites/default/files/powerwall/hero/D_PW_Hero_2880x1800.jpg",
      title: "Tesla Powerwall"
    }, {
      desc: "Energy Production",
      id: 2,
      icon: "fa-solid fa-solar-panel",
      image: "https://media.wired.com/photos/5db373b7dea30b00096c6bbe/16:9/w_2400,h_1350,c_limit/Transpo-Tesla_solar_roof.jpg",
      title: "Solar Power"
    }, {
      desc: "Your EV Charging Stats",
      id: 3,
      icon: "fa-solid fa-charging-station",
      image: "https://www.solarreviews.com/content/images/blog/post/focus_images/77_77-are-tesla-solar-panels-the-best-option.jpg",
      title: "Your Charging Station"
    }, {
      desc: "Your Home Security Overview",
      id: 4,
      icon: "fa-solid fa-camera-security",
      image: "https://www.safewise.com/app/uploads/facebook-security-control-panel-comparison.jpg",
      title: "Home Security System"
    }].map((movie: any) => {
      const styles: React.CSSProperties = {
        backgroundImage: `url(${movie.image})`  
      }
      
      const id: string = `movie-card-${movie.id}`;
      
      return (
        <div key={movie.id} id={id} className="movie-card">
          <div className="movie-card-background background-image" style={styles} />
          <div className="movie-card-content">
            <div className="movie-card-info">
              <span className="movie-card-title">{movie.title}</span>
              <span className="movie-card-desc">{movie.desc}</span>
            </div>
            <i className={movie.icon} />
          </div>
        </div>
      );
    })
  }

  return (
    <MenuSection icon="fa-solid fa-battery-bolt" id="movies-section" scrollable title="Other Dashboards">
      {getMovies()}    
    </MenuSection>
  );
}

interface IUserStatusButton {
  icon: string;
  id: string;
  userStatus: UserStatus;
}

const UserStatusButton: React.FC<IUserStatusButton> = (props: IUserStatusButton) => {  
  const { userStatus, setUserStatusTo } = React.useContext(AppContext);
  
  const handleOnClick = (): void => {
    setUserStatusTo(props.userStatus);
  }
  
  return(   
    <button   
      id={props.id} 
      className="user-status-button clear-button" 
      disabled={userStatus === props.userStatus}
      type="button" 
      onClick={handleOnClick}
    >      
      <i className={props.icon} />
    </button>
  )
}

const Menu: React.FC = () => {  
  return(   
    <div id="app-menu">      
      <div id="app-menu-content-wrapper">
        <div id="app-menu-content">
          <div id="app-menu-content-header">
            <div className="app-menu-content-header-section">
              <Info id="app-menu-info" />
              <Reminder />
            </div>
            <div className="app-menu-content-header-section">
              <UserStatusButton 
                icon="fa-solid fa-arrow-right" 
                id="sign-out-button" 
                userStatus={UserStatus.LoggedOut}
              />
            </div>
          </div>
          <QuickNav />
          <Weather />                  
          <Restaurants />
          <Tools />
          <Movies />
        </div>
      </div>
    </div>
  )
}

const Background: React.FC = () => {  
  const { userStatus, setUserStatusTo } = React.useContext(AppContext);
  
  const handleOnClick = (): void => {
    if(userStatus === UserStatus.LoggedOut) {
      setUserStatusTo(UserStatus.LoggingIn);
    }
  }
  
  return(   
    <div id="app-background" onClick={handleOnClick}>
      <div id="app-background-image" className="background-image" />
    </div>
  )
}

const Loading: React.FC = () => {  
  return(    
    <div id="app-loading-icon">
      <i className="fa-solid fa-spinner-third" />
    </div>
  )
}

interface IAppContext {
  userStatus: UserStatus;
  setUserStatusTo: (status: UserStatus) => void;
}

const AppContext = React.createContext<IAppContext>(null);

const App: React.FC = () => {
  const [userStatus, setUserStatusTo] = React.useState<UserStatus>(UserStatus.LoggedOut);
  
  const getStatusClass = (): string => {
    return userStatus.replace(/\s+/g, "-").toLowerCase();
  }
  
  return(
    <AppContext.Provider value={{ userStatus, setUserStatusTo }}>
      <div id="app" className={getStatusClass()}>
        <Info id="app-info" />
        <Pin />
        <Menu />
        <Background />   
        <div id="sign-in-button-wrapper">
          <UserStatusButton 
            icon="fa-solid fa-arrow-right" 
            id="sign-in-button" 
            userStatus={UserStatus.LoggingIn}
          />       
        </div>                      
        <Loading />
      </div>
    </AppContext.Provider>
  )
}

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

Console