Vue.use(window['vue-js-toggle-button'].default)
new Vue({
el: "#container",
data: {
include: true,
filterTags: 'even odd',
articles: [{
id: 0,
title: 'Test0',
tags: ['even']
},
{
id: 1,
title: 'Test1',
tags: ['odd']
},
{
id: 2,
title: 'Test2',
tags: ['even']
},
{
id: 3,
title: 'Test3',
tags: ['odd']
},
{
id: 4,
title: 'Test4',
tags: ['no number']
}
]
},
computed: {
filtered () {
return this.articles.filter((article) =>
article.tags.some((tag) =>
{
let result = this.filterTags && this.filterTags.indexOf(tag) !== -1
return this.include ? result: !result;
})
)
}
},
methods: {
updateFilterInclude ({value}) {
console.log(value)
this.include = value
}
}
})
body {
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
.vue-js-switch#changed-font {
font-size: 16px !important;
}
ul {
list-style-type: none;
}
.flip-list-move {
transition: transform 0.5s;
}
#container {
width: 200px;
position: absolute;
left: 0;
padding: 5px;
}
.animation {
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.left-position {
background-color: green;
margin-left: 0;
}
.right-position {
background: red;
margin-left: calc(75% - 20px);
}
input {
width: calc(100% - 14px);
padding: 5px;
}
.slider {
border: 1px solid gray;
margin-top: 5px;
padding: 5px;
border-radius: 10px;
}
.element {
width: 25%;
cursor: pointer;
padding: 10px;
border-radius: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script>
<script src="https://rawgit.com/euvl/vue-js-toggle-button/master/dist/index.js"></script>
<div id="container">
Filter tags<input v-model="filterTags"/>
<div class="slider">
<div class="element animation" @click="include = !include" :class="{'left-position': include, 'right-position': !include}">
{{include ? 'include' : 'exlude'}}
</div>
</div>
<hr/>
<toggle-button
id="changed-font"
:width="200"
:height="40"
:color="{checked: 'green', unchecked: 'red'}"
:labels="{checked: 'include', unchecked: 'exclude'}" :value="include" @change="updateFilterInclude"> {{include ? 'include' : 'exlude'}}</toggle-button>
<transition-group name="flip-list" tag="ul">
<li v-for="article in filtered" :key="article">
{{article.tags.join(' ')}} - {{article.title}}
</li>
</transition-group>
</div>