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="app" :data-state="current.value.wake">
  <div class="buttons">
    <div class="button vol-up"></div>
    <div class="button vol-down"></div>
    <div class="button silence"></div>
    <div class="button sleep" @click="sleepWake"></div>
  </div>
  
  <div class="screen">
    <div class="login">
      <h1 class="brand">BRAND</h1>
      <form @submit.prevent="send">
        <div class="input-group">
          <input id="email" name="email" type="text" placeholder="ANYTHING" v-model="form.email">
        </div>

        <div class="input-group">
          <input id="password" name="password" type="password" placeholder="PASSWORD" v-model="form.password">
        </div>

        <div class="error">
          That's not right.<br>I literally gave you the password!
        </div>
        <input type="submit" value="SUBMIT">
      </form>

      <div class="legal">
        <p>* Don't use your bank password.</p>
        <p>(We didn't spend much on security for this app.)</p>
      </div>
    </div>
    <div class="logged-in">
      <h1 class="brand">BRAND</h1>
      <main>
        <div class="avatar">
          <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1116884/IMG_2973.JPG' alt=''>
        </div>
        
        <div class="greeting">
          WELCOME!
          <p>that's it...</p>
          <p>that's the entire application</p>
        </div>
        <button @click="signout">LOGOUT</button>
      </main>
    </div>
    <div class="loading">
      <h1 class="brand">BRAND</h1>
      <div class="spinner-1"></div>
      <div class="spinner-2"></div>
    </div>
  </div>
</div>
<div class="message">your password is hotdogs</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Gruppo|Alegreya+Sans:300|Alegreya+Sans+SC:100&display=swap');

html {
  box-sizing: border-box;
}

*, *:before, *:after {
  position: relative;
  box-sizing: inherit;
}

html, body {
  height: 100%;
}

body {
  --transition: opacity 150ms ease-in-out;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(#5F64B7, #8E93E6);
  color: white;
}

input,
button {
  cursor: none;
  
  &:focus {
    outline: none;
  }
}

#app {
  position: relative;
  height: 100vh;
  width: 100vw;
  padding: 0;
  margin-bottom: 2vmin;
  display: flex;
  background: #ccc;
  font-size: 2.5vmin;

  
  @media screen and (min-width: 400px) {
    height: 90vmin;
    width: 50vmin;
    padding: 1.5vmin;
    border-radius: 3.5vmin;
    box-shadow: 
      inset 6px -6px 6px rgba(black, 0.25),
      inset -4px 4px 8px rgba(white, 0.9), 
      -4px 4px 20px rgba(black, 0.26);
  }
 
  
  &[data-state="idle"],
  &[data-state="fail"] {
    .screen::after {
      opacity: 1;
    }

    .login {
      opacity: 1;
    }
  }
  
  &[data-state="fail"] {
    .error {
      display: inline;
    }
  }
  
  &[data-state="success"] {
    .screen::after {
      opacity: 1;
    }

    .logged-in {
      opacity: 1;
      pointer-events: all;
    }
  }
  
  &[data-state="loading"] {
    .screen::after {
      opacity: 1;
    }

    .loading {
      opacity: 1;
      pointer-events: all;
    }
  }
}

.buttons {
  position: absolute;
  width: 100%;
  height: 100%;
}

.button {
  position: absolute;
  width: 0.8vmin;
  background-color: #ccc;
  box-shadow: inset 0 2px 4px rgba(white, 0.5);
  cursor: pointer;
  
  &:active {
    background-color: #ddd;
    width: 0.4vmin;
  }
}

.vol-up, .vol-down, .silence {
  height: 6vmin;
  left: -2.2vmin;
  border-radius: 0.2rem 1px 1px 0.2rem;
  box-shadow: 
    inset 0 2px 4px rgba(white, 0.5),
    inset -2px 0 4px rgba(black, 0.35);
  
  &:active {
    border-radius: 0.4vmin 0 0 0.4vmin;
    left: -1.8vmin;
  }
}

.silence {
  top: 9vmin;
  height: 6vmin;
}

.vol-up {
  top: 22vmin;
}

.vol-down {
  top: 30vmin;
}

.sleep {
  top: 12vmin;
  right: 0.8vmin;
  height: 12vmin;
  border-radius: 1px 0.2rem 0.2rem 1px;

  &:active {
    right: 1.1vmin;
    border-radius: 0 0.4vmin 0.4vmin 0;
  }
}

.screen {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: black;

  overflow: hidden;
  
  @media screen and (min-width: 400px) {
    border-radius: 2.5vmin;
    box-shadow: 0 0 3px 3px rgba(white, 0.6),
    0 -2px 8px rgba(white, 0.1);
  }
  
  &:after {
    position: absolute;
    content: '';
    bottom: 5px;
    left: 50%;
    height: 3px;
    width: 20vmin;
    // max-width: 110px;
    border-radius: 3px;
    background-color: #6067B2;
    transform: translateX(-50%);
    opacity: 0;
  }
}

.brand {
  margin: 0;
  text-align: center;
  opacity: 0.8;
  font-size: 36px;
  font-family: 'Gruppo', cursive;
  letter-spacing: 6px;
  user-select: none;
}

/* LOGIN SCREEN
============================ */

.login {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  padding: 1rem;
  padding-bottom: 5vmin;
  background: linear-gradient(#43427B, #272754);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
  opacity: 0;
}

.login .brand {
  font-size: 6vmin;
  color: white;
}

.login form {
  display: flex;
  flex-direction: column;
}

.login form .input-group {
  margin-bottom: 5vmin;
  opacity: 0.5;
  transition: var(--transition);
  
  &::before {
    position: absolute;
    bottom: 0;
    left: 0;
    content: '';
    background-color: rgba(255, 255, 255, 0.5);
    height: 1px;
    width: 100%; 
  }
  
  &::after {
    position: absolute;
    bottom: 0;
    left: 0;
    content: '';
    background-color: white;
    height: 1px;
    width: 0;
    transition: width 300ms cubic-bezier(0.5, 0, 0.5, 1);
  }
  
  &:focus-within {
    opacity: 1;
    
    &::after {
      width: 100%;
    }
  }
}

.login form .input-group input {
  padding-left: 5%;
  font-family: 'Alegreya Sans', sans-serif;
}

.login form .input-group input::placeholder {
  font-family: 'Alegreya Sans SC', sans-serif;
  font-size: 2.5vmin;
  color: white;
}

.login form .input-group input[type="password"] {
  letter-spacing: 4px;
}

.login form .input-group input[type="password"]::placeholder {
  letter-spacing: 0;
}

.login form .input-group input[type="text"],
.login form .input-group input[type="password"] {
  width: 100%;
  font-size: 20px;
  background-color: transparent;
  border: none;
  color: white;
  
  &:focus {
    outline: none;
  }
}

.login form .error {
  text-align: center;
  font-size: 2vmin;
  margin-bottom: 1.6rem;
  color: red;
  display: none;
}

.login form input[type="submit"] {
  padding: 2.3vmin 6.5vmin;
  line-height: 1;
  align-self: center;
  justify-self: center;
  background-color: transparent;
  border-radius: 1vmin;
  border: 1px solid white;
  font-size: 3vmin;
  color: white;
  font-family: 'Alegreya Sans', sans-serif;
  opacity: 0.5;
  transition: var(--transition);
  
  &:hover {
    opacity: 1;
  }
}

.login .legal {
  text-align: center;
  font-size: 0.4rem;
  opacity: 0.4;
  font-family: 'Alegreya Sans', sans-serif;
  user-select: none;
}

.login .legal p {
  margin: 0;
}

/* LOGGED IN SCREEN
============================ */

.logged-in {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  padding: 2vmin;
  padding-bottom: 4vmin;
  background: linear-gradient(#8E94E3, #272754);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  opacity: 0;
  pointer-events: none;
}

.logged-in .brand {
  font-size: 6vmin;
}

.logged-in main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.logged-in main .avatar {
  height: 25vmin;
  width: 25vmin;
  border-radius: 50%;
  padding: 1vmin;
  margin-bottom: 1vmin;
  overflow: hidden;
  border: 0.4vmin solid white;
}

.logged-in main .avatar img {
  height: 100%;
  width: 100%;
  border-radius: 50%;
}

.logged-in main .greeting {
    font-family: 'Alegreya Sans', sans-serif;
  font-size: 6vmin;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  text-align: center;
}

.logged-in main .greeting p {
  margin: 0;
  font-size: 2.5vmin;
  opacity: 0.5;
}

.logged-in main button {
  padding: 1.3vmin 2vmin 1vmin 2vmin;
  margin: 0.8rem 0;
  background: transparent;
  font-family: 'Alegreya Sans', sans-serif;
  font-size: 3vmin;
  color: white;
  border: 0.2vmin solid white;
  border-radius: 1vmin;
  opacity: 0.5;
  
  &:active,
  &:hover {
    opacity: 1;
  }
}

/* LOADING SCREEN
============================ */

.loading {
  position: absolute;
  height: 100%;
  width: 100%;
  padding: 2vmin;
  top: 0;
  left: 0;
  background-color: rgba(white, 1);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
}

.loading .brand {
  font-size: 6vmin;
  color: #272754;
}

.loading .spinner-1,
.loading .spinner-2 {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 90px;
  width: 90px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  background-color: #272754;
  opacity: 0.2;
  animation: loader 1000ms ease-in-out alternate infinite;
}

.loading .spinner-1 {
  opacity: 0.2;
}

.loading .spinner-2 {
  opacity: 0.4;
  animation-direction: alternate-reverse;
}

.message {
  font-family: 'Alegreya Sans', sans-serif;
  opacity: 0.4;
}

@keyframes loader {
  to {
    height: 40px;
    width: 40px;
  }
}

/* TOUCH
============================ */

:root {
  --mouse-x: calc(50vw + 1px);
  --mouse-y: calc(50vh + 1px);
  cursor: none;
}

.mouse-tracker {
  position: fixed;
  display: none;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  border: 2px solid white;
  opacity: 0.8;
  z-index: 999;
  transform: 
    translate(-50%, -50%)
    translate(
      var(--mouse-x),
      var(--mouse-y)
    )
    scale( calc( 1 - (var(--mouse-down) * 0.2)) );
  pointer-events: none;
  transition: transform 100ms ease;
 
  @media screen and (min-width: 576px) {
    display: inline;
  }
}
              
            
!

JS

              
                const authenticate = data => new Promise((resolve, reject) => {
  setTimeout(() => {
    if(data.password === 'hotdogs') {
     resolve('awesome data') 
    } else {
      reject('oh crap')
    }
  }, 3000) 
});

const machine = XState.Machine(
  {
    id: 'login',
    initial: 'wake',
    context: {
      email: null,
      password: null
    },
    states: {
      wake: {
        initial: 'idle',
        states: {
          idle: {
            entry: 'clearContext',
            on: {
              SUBMIT: [
                {
                  target: 'loading',
                  cond: 'validateForm',
                  actions: [
                    XState.assign({ 
                      email: (_, event) => event.email,
                      password: (_, event) => event.password
                    }),
                  ],
                },
                { target: 'fail' },
              ],
            },
          },
          loading: {
             invoke: {
              id: 'authenticate',
              src: context => authenticate(context),
              onDone: {
                target: 'success'
              },
              onError: {
                target: 'fail'
              },
            },
          },
          fail: {
            on: {
              SUBMIT: [
                {
                  target: 'loading',
                  cond: (ctx, event) => event.email && event.password !== '',
                  actions: [
                    XState.assign({ 
                      email: (ctx, event) => event.email,
                      password: (ctx, event) => event.password
                    }),
                  ],
                },
                { target: 'fail' },
              ],
            },
          },
          success: {
            on: {
              SIGNOUT: 'idle'
            }
          },
          hist: {
            type: 'history',
            target: 'idle'
          },
        },
        on: {
          POWER: 'sleep'
        }
      },
      sleep: {
        on: {
          POWER: 'wake.hist'
        }
      }
    }
  },
  {
    actions: {
      clearContext: XState.assign({
        email: null,
        password: null
      })
  },
    guards: {
      validateForm: (ctx, event) => event.email !== '' && event.password !== ''
  }
  }
)

new Vue({
  el: '#app',
  data() {
    return {
      loginService: XState.interpret(machine),
      current: machine.initialState,
      form: {
        email: '',
        password: ''
      }
    }
  },
  created() {
    this.loginService
      .onTransition(state => {
        this.current = state;
      })
      .start();
  },
  destroyed() {
    this.loginService.stop();
  },
  methods: {
    send() {
      this.loginService.send('SUBMIT', this.form);
    },
    signout() {
      this.form.email = '';
      this.form.password = '';
      this.loginService.send('SIGNOUT');
    },
    sleepWake() {
        this.form.email = '';
        this.form.password = '';
        this.loginService.send('POWER');

    }
  }
});

// touch
document.body.insertAdjacentHTML('beforeend', '<div class="mouse-tracker"></div>');

document.addEventListener('mousemove', event => {
  document.documentElement.style.setProperty('--mouse-x', `${event.clientX}px`);
  document.documentElement.style.setProperty('--mouse-y', `${event.clientY}px`);
})

document.addEventListener('mousedown', event => {
  document.documentElement.style.setProperty('--mouse-down', 1);
})

document.addEventListener('mouseup', event => {
  document.documentElement.style.setProperty('--mouse-down', 0);
})
              
            
!
999px

Console