JSFiddle - React, Tailwind, and code Playground

by lavezzi

HTML

<script src="https://cdn.jsdelivr.net/vue/1.0.20/vue.js"></script>
<script src=" https://cdn.jsdelivr.net/vue.router/0.7.12/vue-router.min.js"></script>
<div id="app">
  <aside class="sidebar" v-show="isActive" transition="expand-menu">
    <a href="#" @click.prevent="close" class="sidebar__close"><i class="material-icons">menu</i></a>
    <a class="sidebar__item" v-link="{ path: '/page-one' }" @click="close">Go to page one</a>
    <a class="sidebar__item" v-link="{ path: '/page-two' }" @click="close">Go to page two</a>
    <a class="sidebar__item" v-link="{ path: '/page-three' }" @click="close">Go to page three</a>
  </aside>
  <div class="content">
    <div class="overlay" v-show="isActive" transition="toggle-overlay" @click="close">
    </div>
    <a href="#" @click.prevent="toggle">
      Toggle!
    </a>
    <router-view></router-view>

  </div>
</div>

SCSS

@import url(https://fonts.googleapis.com/css?family=Roboto);
@import url(https://fonts.googleapis.com/css?family=Material+Icons);

body {
  font-family: 'Roboto', sans-serif;
}

.expand-menu-transition {
  transition: transform 1s ease-in-out;
  transform: translateX(0);
}

.expand-menu-enter, .expand-menu-leave {
  transform: translateX(-100%);
}

.toggle-overlay-transition {
  transition: opacity 1s ease-in-out;
  opacity: 1;
}

.toggle-overlay-enter, .toggle-overlay-leave {
  opacity: 0;
}

.v-link-active {
  background-color: #0af;
  color: #fff;
}

body {
  min-height: 100vh
}

a {
  color: #0af;
  text-decoration: none;
}

.sidebar {
  z-index: 999;
  position: absolute;
  background-color: #f1f1f1;
  padding: 16px 0;
  height: calc(100vh - 16px);
  display: inline-block;
  &__item {
    margin: 0;
    margin-top: 8px;
    padding: 8px 16px;
    display: block;
    &:first-child {
      padding-top: 0;
    }
  }
  &__close {
    margin: 16px;
  }
}

.overlay {
  position: absolute;
  display: block;
  top:0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
}

.content {
  padding: 16px;
  display: block;
  vertical-align: top;
  position: relative;
  height: calc(100vh - 32px);
}

Babel + JSX

// Define some components
var PageOne = Vue.extend({
  template: '<p>This is page one!</p>'
})

var PageTwo = Vue.extend({
  template: '<p>This is page two!</p>'
})

var PageThree = Vue.extend({
    template: '<p>This is page three!</p>'
  })
  // The router needs a root component to render.
  // For demo purposes, we will just use an empty one
  // because we are using the HTML as the app template.
var App = Vue.extend({
  data() {
      return {
        isActive: true,
      };
    },

    methods: {
      toggle() {
        this.isActive = !this.isActive;
      },
      close() {
      this.isActive = false;
      }
    },
})

// Create a router instance.
// You can pass in additional options here, but let's
// keep it simple for now.
var router = new VueRouter()

// Define some routes.
// Each route should map to a component. The "component" can
// either be an actual component constructor created via
// Vue.extend(), or just a component options object.
// We'll talk about nested routes later.
router.map({
  '/': {
    component: PageOne
  },
  '/page-one': {
    component: PageOne
  },
  '/page-two': {
    component: PageTwo
  },
  '/page-three': {
    component: PageThree
  }
})

// Now we can start the app!
// The router will create an instance of App and mount to
// the element matching the selector #app.
router.start(App, '#app')