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 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

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

              
                <template id="help-centre-menu">
  <div class="container-fluid" id="help-centre">
    <div class="row my-3">
      <div class="col-3 menu">
        <h4 class="my-3">{{title}}</h4>
        <ul class="nav flex-column">
          <menu-item v-for="m in menuItems"
                     v-bind="m"
                     :key="m.label"
                     v-on:navigate="onNavigate($event)"></menu-item>
        </ul>
      </div>
      <div class="col-9 content">
        <div class="container my-3">
          <div v-for="i in contentItems" class="mb-2">
            <content-item v-bind="i"></content-item>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<template id="content-item-template">
  <div>
    <h4 :id="tag" class="pt-3"><i v-if="tag" class="fas fa-hashtag mr-2"></i>{{label}}</h4>
    <div v-html="content"></div>
    <div v-if="children" class="mt-4">
      <content-item v-for="item in children" v-bind="item"></content-item>
    </di>
  </div>
</template>

<template id="menu-item-template">
  <li class="nav-item menu-i">
    <a class="nav-link"
       :class="{ selected: active }"
       @click="onSelected(tag)">
      <span :class="{ strong: hasChildren }">{{label}}</span>
      <span class="mi-i" v-show="hasChildren && collapsed">
        <i class="far fa-plus-square"></i>
      </span>
      <span class="mi-i" v-show="hasChildren && !collapsed">
        <i class="far fa-minus-square"></i>
      </span>
    </a>
    <div class="collapse" :class="{ show: !collapsed }">
      <ul v-if="hasChildren" class="nav flex-column ml-3">
        <menu-item v-for="c in children"
                   v-bind="c"
                   v-on:navigate="onSelected($event)"></menu-item>
      </ul>
    </div>
  </li>
</template>

<div id="app">
  <help-centre></help-centre>
</div>

              
            
!

CSS

              
                #help-centre {
  height: 100vh;
  overflow: hidden;
  .menu {
    height: 100vh;
    background-color: #FFFFFF;
    
    .menu-i {
      cursor: pointer;
      .strong {
        font-weight: 500;
      }
      a {
        color: black;
      }
      .selected {
        color: #42b983;
      }
      .mi-i {
        float: right;
        color: darkgray;
      }
    }
  }
  .content {
    background-color: #EEEEEE;
    max-height: 100vh;
    overflow-y: auto;
    
    .fa-hashtag {
      color: lightgray;
    }
  }
}
              
            
!

JS

              
                const ContentItems = [
  {
    label: "Installation",
    tag: "installation",
    content: `
    <hr/>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam interdum mauris lacus, nec hendrerit est tincidunt in. Maecenas a massa sem. Nam vel facilisis neque. Proin hendrerit dolor lectus, sit amet imperdiet massa viverra a. Aliquam vel molestie ligula, a aliquam lacus. Integer at sapien vitae ipsum accumsan tristique. Fusce convallis viverra dolor a laoreet. Sed pharetra ipsum ut odio mattis lobortis. Donec non vestibulum eros. Ut pretium lorem mi, quis varius elit maximus quis. Curabitur vulputate, nibh ac luctus convallis, leo dolor fermentum nisl, sed cursus erat diam posuere nulla.<br/><br/>
In sollicitudin viverra massa, sed accumsan nibh commodo sed. Ut arcu augue, imperdiet sed convallis et, volutpat vitae neque. Nullam at leo elit. Phasellus sem arcu, feugiat pharetra tortor at, tempus gravida eros. Nullam massa nunc, commodo vitae sapien sed, sagittis pellentesque dui. Nunc a mi lorem. Sed eu mi sit amet tellus bibendum finibus. Vivamus efficitur, dolor nec porta pellentesque, ligula metus viverra felis, at congue augue est a eros.</p>
    `
  },
  {
    label: "Introduction",
    tag: "intro",
    content: `
    <hr/>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam interdum mauris lacus, nec hendrerit est tincidunt in. Maecenas a massa sem. Nam vel facilisis neque. Proin hendrerit dolor lectus, sit amet imperdiet massa viverra a. Aliquam vel molestie ligula, a aliquam lacus. Integer at sapien vitae ipsum accumsan tristique. Fusce convallis viverra dolor a laoreet. Sed pharetra ipsum ut odio mattis lobortis. Donec non vestibulum eros. Ut pretium lorem mi, quis varius elit maximus quis. Curabitur vulputate, nibh ac luctus convallis, leo dolor fermentum nisl, sed cursus erat diam posuere nulla.<br/><br/>
In sollicitudin viverra massa, sed accumsan nibh commodo sed. Ut arcu augue, imperdiet sed convallis et, volutpat vitae neque. Nullam at leo elit. Phasellus sem arcu, feugiat pharetra tortor at, tempus gravida eros. Nullam massa nunc, commodo vitae sapien sed, sagittis pellentesque dui. Nunc a mi lorem. Sed eu mi sit amet tellus bibendum finibus. Vivamus efficitur, dolor nec porta pellentesque, ligula metus viverra felis, at congue augue est a eros.</p>
    `
  },
  {
    label: "Components",
    children: [
      {
        label: "Input",
        tag: "input",
        content: `
<hr/>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam interdum mauris lacus, nec hendrerit est tincidunt in. Maecenas a massa sem. Nam vel facilisis neque. Proin hendrerit dolor lectus, sit amet imperdiet massa viverra a. Aliquam vel molestie ligula, a aliquam lacus. Integer at sapien vitae ipsum accumsan tristique. Fusce convallis viverra dolor a laoreet. Sed pharetra ipsum ut odio mattis lobortis. Donec non vestibulum eros. Ut pretium lorem mi, quis varius elit maximus quis. Curabitur vulputate, nibh ac luctus convallis, leo dolor fermentum nisl, sed cursus erat diam posuere nulla.
`
      },
      {
        label: "Buttons",
        tag: "btn",
        content: `
<hr/>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam interdum mauris lacus, nec hendrerit est tincidunt in. Maecenas a massa sem. Nam vel facilisis neque. Proin hendrerit dolor lectus, sit amet imperdiet massa viverra a. Aliquam vel molestie ligula, a aliquam lacus. Integer at sapien vitae ipsum accumsan tristique. Fusce convallis viverra dolor a laoreet. Sed pharetra ipsum ut odio mattis lobortis. Donec non vestibulum eros. Ut pretium lorem mi, quis varius elit maximus quis. Curabitur vulputate, nibh ac luctus convallis, leo dolor fermentum nisl, sed cursus erat diam posuere nulla.
`
      },
      {
        label: "Panels",
        tag: "panels",
        content: `
<hr/>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam interdum mauris lacus, nec hendrerit est tincidunt in. Maecenas a massa sem. Nam vel facilisis neque. Proin hendrerit dolor lectus, sit amet imperdiet massa viverra a. Aliquam vel molestie ligula, a aliquam lacus. Integer at sapien vitae ipsum accumsan tristique. Fusce convallis viverra dolor a laoreet. Sed pharetra ipsum ut odio mattis lobortis. Donec non vestibulum eros. Ut pretium lorem mi, quis varius elit maximus quis. Curabitur vulputate, nibh ac luctus convallis, leo dolor fermentum nisl, sed cursus erat diam posuere nulla.
`
      },
    ]
  },
  {
    label: "License",
    tag: "license",
    content: `
    <hr/>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam interdum mauris lacus, nec hendrerit est tincidunt in. Maecenas a massa sem. Nam vel facilisis neque. Proin hendrerit dolor lectus, sit amet imperdiet massa viverra a. Aliquam vel molestie ligula, a aliquam lacus. Integer at sapien vitae ipsum accumsan tristique. Fusce convallis viverra dolor a laoreet. Sed pharetra ipsum ut odio mattis lobortis. Donec non vestibulum eros. Ut pretium lorem mi, quis varius elit maximus quis. Curabitur vulputate, nibh ac luctus convallis, leo dolor fermentum nisl, sed cursus erat diam posuere nulla.<br/><br/>
In sollicitudin viverra massa, sed accumsan nibh commodo sed. Ut arcu augue, imperdiet sed convallis et, volutpat vitae neque. Nullam at leo elit. Phasellus sem arcu, feugiat pharetra tortor at, tempus gravida eros. Nullam massa nunc, commodo vitae sapien sed, sagittis pellentesque dui. Nunc a mi lorem. Sed eu mi sit amet tellus bibendum finibus. Vivamus efficitur, dolor nec porta pellentesque, ligula metus viverra felis, at congue augue est a eros.</p>
    `
  },
]

const extractMenuItem = (contentItem) => {
  const r = {
    active: false,
    label: contentItem.label,
    tag: contentItem.tag
  };
  let children = [];
  if (contentItem.children) {
    contentItem.children.forEach(c => children.push(extractMenuItem(c)));
    r.children = children;
  }
  
  return r;
}

Vue.component('menu-item', {
  template: '#menu-item-template',
  props: {
    tag: String,
    label: String,
    children: Array,
    active: Boolean
  },
  data: () => ({ collapsed: true }),
  methods: {
    onSelected(tag) {
      if (this.hasChildren && this.tag === tag) {
        this.collapsed = !this.collapsed;
      }
      this.$emit('navigate', tag);
    }
  },
  computed: {
    hasChildren() {
      return this.children && this.children.length > 0;
    },
    isSelected() {
      const i = window.location.href.indexOf(this.tag);
      return i >= 0;
    }
  }
});

Vue.component('content-item', {
  template: '#content-item-template',
  props: {
    tag: String,
    label: String,
    content: String,
    children: Array
  }
});

Vue.component('help-centre', {
  template: '#help-centre-menu',
  data: () => ({
    title: 'AwesomeLib',
    contentItems: null,
    menuItems: null
  }),
  mounted () {
    this.contentItems = [...ContentItems];
    this.menuItems = ContentItems.map(i => extractMenuItem(i));
    console.log(this.menuItems);
  },
  methods: {
    onNavigate(anchor) {
      const el = document.getElementById(anchor);
      if (el) {
        this.setActive(anchor);
        el.scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
      }
    },
    setActive (tag) {
      this.menuItems.forEach(i => {
        if (i.children && i.tag !== tag) {
          i.active = false;
          i.children.forEach(c => {
            c.active = c.tag === tag;
          })
        } else {
          i.active = i.tag === tag;
        }
      });
    },
  }
});

new Vue({ el: "#app" })
              
            
!
999px

Console