vue-istope-chemistry-example

by David Desmaisons

HTML

<script src="https://npmcdn.com/isotope-layout@3.0/dist/isotope.pkgd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.min.js"></script>
<script src="https://cdn.rawgit.com/David-Desmaisons/Vue.Isotope/master/src/vue_isotope.js"></script>
 <div id="main">
        <h1>Vue isotope For</h1>

        <h2>Filter</h2>
        <div class="button-group">  
            <button v-for="(key, val) in option.getFilterData" class="button" :class="[key===filterOption? 'is-checked' : '']"  @click="filter(key)">{{key}}
            </button>
        </div>

        <h2>Sort</h2>
        <div class="button-group">
          <button class="button" :class="[sortOption==='original-order'? 'is-checked' : '']"  @click="sort('original-order')">original order</button> 
          <button v-for="(key, val) in option.getSortData" class="button" :class="[key===sortOption? 'is-checked' : '']"  @click="sort(key)">{{key}}</button>
        </div>
       
        <div id="root_isotope1">
            <div v-isotope-for="element in list" :options='option' v-bind:class='[element.category]'>
                <h3 class="name">{{element.name}}</h3>
                <p class="symbol">{{element.symbol}}</p>
                <p class="number">{{element.number}}</p>
                <p class="weight">{{element.weight}}</p>
            </div>
        </div>
    </div>

CSS

.item {
  background-color: #eee;
  padding: 10px;
  width: 200px;
  height: 200px;
  margin-bottom: 10px;
  box-sizing: border-box;
  font-family: monospace;
  color: #333;
}

* { box-sizing: border-box; }

body {
  font-family: sans-serif;
}

/* ---- button ---- */

.button {
  display: inline-block;
  padding: 0.5em 1.0em;
  background: #EEE;
  border: none;
  border-radius: 7px;
  background-image: linear-gradient( to bottom, hsla(0, 0%, 0%, 0), hsla(0, 0%, 0%, 0.2) );
  color: #222;
  font-family: sans-serif;
  font-size: 16px;
  text-shadow: 0 1px white;
  cursor: pointer;
}

.button:hover {
  background-color: #8CF;
  text-shadow: 0 1px hsla(0, 0%, 100%, 0.5);
  color: #222;
}

.button:active,
.button.is-checked {
  background-color: #28F;
}

.is-checked {
  background-color: #28F;
}

.button.is-checked {
  color: white;
  text-shadow: 0 -1px hsla(0, 0%, 0%, 0.8);
}

.button:active {
  box-shadow: inset 0 1px 10px hsla(0, 0%, 0%, 0.8);
}

/* ---- button-group ---- */

.button-group {
  margin-bottom: 20px;
}

.button-group:after {
  content: '';
  display: block;
  clear: both;
}

.button-group .button {
  float: left;
  border-radius: 0;
  margin-left: 0;
  margin-right: 1px;
}

.button-group .button:first-child { border-radius: 0.5em 0 0 0.5em; }
.button-group .button:last-child { border-radius: 0 0.5em 0.5em 0; }

/* ---- isotope ---- */

.grid {
  border: 1px solid #333;
}

/* clear fix */
.grid:after {
  content: '';
  display: block;
  clear: both;
}

.isoDefault {
  min-height: 210px;
}

/* ---- .element-item ---- */

.element-item {
  position: relative;
  float: left;
  width: 100px;
  height: 100px;
  margin: 5px;
  padding: 10px;
  background: #888;
  color: #262524;
}

.element-item > * {
  margin: 0;
  padding: 0;
}

.element-item .name {
  position: absolute;

  left: 10px;
  top: 60px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: normal;
}

.element-item .symbol {
  position: absolute;
  left: 10px;
  top:...

JavaScript

var count = 0;

var vm = new Vue({
  el: "#main",
  data: {
    list: [{
      name: "Mercury",
      symbol: "Hg",
      number: 80,
      weight: 200.59,
      category: "transition",
      metal: true
    }, {
      name: "Tellurium",
      symbol: "Te",
      number: 52,
      weight: 127.6,
      category: "metalloid"
    }, {
      name: "Bismuth",
      symbol: "Bi",
      number: 83,
      weight: 208.980,
      category: "post-transition",
      metal: true
    }, {
      name: "Lead",
      symbol: "Pb",
      number: 82,
      weight: 207.2,
      category: "post-transition",
      metal: true
    }, {
      name: "Gold",
      symbol: "Au",
      number: 79,
      weight: 196.967,
      category: "transition",
      metal: true
    }, {
      name: "Potassium",
      symbol: "K",
      number: 19,
      weight: 39.0983,
      category: "alkali",
      metal: true
    }, {
      name: "Sodium",
      symbol: "Na",
      number: 11,
      weight: 22.99,
      category: "alkali",
      metal: true
    }, {
      name: "Cadmium",
      symbol: "Cd",
      number: 48,
      weight: 112.411,
      category: "transition",
      metal: true
    }, {
      name: "Calcium",
      symbol: "Ca",
      number: 20,
      weight: 40.078,
      category: "alkaline-earth",
      metal: true
    }, {
      name: "Rhenium",
      symbol: "Re",
      number: 75,
      weight: 186.207,
      category: "transition",
      metal: true
    }, {
      name: "Ytterbium",
      symbol: "Yb",
      number: 70,
      weight: 173.054,
      category: "lanthanoid"
    }, ],
    selected: null,
    sortOption: "original-order",
    filterOption: "show all",
    option: {
      itemSelector: ".element-item",
      getFilterData: {
        "show all": function() {
          return true;
        },
        metal: function(el) {
          return !!el.metal;
        },
        transition: function(el) {
          return el.category === "transition";
        },
        "alkali and...