Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id='app'>
  <blog-articles :dates-articles='datesArticles'></blog-articles>
</div>

<template id='my-template'>
  <div class='container'>
    <input v-model='searchQuery' class='search-box' placeholder='Search for articles...'>
    <div class='timeline' v-if='anyArticle()'>
      <div v-for='(dateWithArticles, date) in searchedArticles'>
        <p v-if='dateWithArticles.length > 0' class='date'>{{ date }}</p>
        <div v-for='article in dateWithArticles' class='article'>
          <span class='dot'></span>
          <p class='article-date'>{{ article.published_at }}</p>
          <h3><a :href="'#' + article.slug">{{ article.title }}</a></h3>
          <p>{{ article.teaser }}</p>
        </div>
      </div>
    </div>
    <p v-else>No articles found.</p>
  </div>
</template>
            
          
!
            
              *
  outline: none
  box-sizing: border-box

.container
  margin: 0 auto
  width: 100%
  max-width: 500px
 
  .search-box
    padding: 10px
    margin: 20px 0
    border: 1px solid black
    border-radius: 5px

  .timeline
    position: relative
    border-left: 1px solid black

    .date
      display: inline-block
      border: 1px solid black
      border-radius: 5px
      padding: 5px
      position: relative
      left: 15px
      margin: 15px 0

      &:before
        content: ''
        position: absolute
        top: 50%
        left: -16px
        border: 1px solid black
        width: 14px

    .article
      position: relative
      left: 20px
      box-shadow: 0px 5px 10px 0px rgba(0,0,0,0.2)
      border-radius: 5px
      padding: 10px
      margin: 10px 0

      &:hover
        box-shadow: 0px 5px 10px 0px rgba(0,0,0,0.4)
      
      a
        color: green
        text-decoration: none

      .article-date
        font-weight: 300
        font-size: 14px

      .dot
        display: block
        position: absolute
        width: 10px
        height: 10px
        border-radius: 50%
        background: green
        left: -25.5px
        top: calc(50% - 5px)
            
          
!
            
              Vue.component('blog-articles', {
  template: '#my-template',
  props: ['datesArticles'],
  data() {
    return {
      searchQuery: ''
    }
  },
  computed: {
    searchedArticles() {
      var searchRegex = new RegExp(this.searchQuery, 'i');
      var searchedObj = {};

      if(this.searchQuery == '') {
         return this.datesArticles;
      }

      for(var date in this.datesArticles) {
        searchedObj[date] = this.datesArticles[date].filter((article) => {
          return searchRegex.test(article.title) ||
                 searchRegex.test(article.teaser) ||
                 searchRegex.test(article.published_at) ||
                 searchRegex.test(date);
        });
      }
      return searchedObj;
    }
  },
  methods: {
    anyArticle() {
      return this.countAllArticles() ? true : false;
    },
    countAllArticles() {
      var count = 0;
      for(var date in this.searchedArticles) {
        count += this.searchedArticles[date].length;
      }
      return count;
    }
  }
});

new Vue({
  el: '#app',
  data: {
    datesArticles: {
      'September, 2016': [
        {
          title: 'Five',
          slug: 'five',
          teaser: 'five',
          published_at: '30.09.2016.'
        },
        {
          title: 'Four',
          slug: 'four',
          teaser: 'four',
          published_at: '15.09.2016.'
        }
      ],
      'April, 2016': [
        {
          title: 'Three',
          slug: 'three',
          teaser: 'three',
          published_at: '14.04.2016.'
        },
        {
          title: 'Two and a half',
          slug: 'two-and-a-half',
          teaser: 'two and a half',
          published_at: '02.04.2016.'
        }
      ],
      'December, 2015': [
        {
          title: 'Two',
          slug: 'two',
          teaser: 'two',
          published_at: '25.12.2015.'
        },
        {
          title: 'One',
          slug: 'one',
          teaser: 'one',
          published_at: '01.12.2015.'
        }
      ]
    }
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console