Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
feat(widgets): add Menu widget
Browse files Browse the repository at this point in the history
  • Loading branch information
iam4x committed Oct 18, 2017
1 parent 4a3574b commit 50c4c14
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/components/Menu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<script>
import algoliaComponent from '../component';
import {FACET_TREE} from '../store';
export default {
mixins: [algoliaComponent],
props: {
attribute: {
type: String,
},
limit: {
type: Number,
default: 10
},
sortBy: {
default() {
return ['name:asc']
}
}
},
computed: {
facetValues() {
const {data = []} = this.searchStore.getFacetValues(
this.attribute,
this.sortBy
);
return data;
}
},
methods: {
handleClick(event, path) {
event.preventDefault();
this.searchStore.toggleFacetRefinement(this.attribute, path);
}
},
data() {
return {
blockClassName: 'ais-menu',
};
},
created() {
this.searchStore.addFacet({
name: this.attribute,
attributes: [this.attribute]
}, FACET_TREE);
},
destroyed() {
this.searchStore.removeFacet(this.attribute);
},
render(h) {
if (this.show === false) return undefined;
const children = [];
if (this.$slots.header) children.push(this.$slots.header);
children.push(this.facetValues.map(({name, path, count, isRefined}) => (
h(
'div',
{ class: [this.bem('item'), isRefined ? this.bem('item', 'active') : ''] },
[
h(
'a',
{
class: this.bem('link'),
domProps: { href: '#' },
on: { click: (event) => this.handleClick(event, path) }
},
[
name,
h('span', {class: this.bem('count')}, count)
]
)
]
)
)));
if (this.$slots.footer) children.push(this.$slots.footer);
return h('div', { class: this.bem() }, children);
}
}
</script>
4 changes: 4 additions & 0 deletions src/instantsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Stats from './components/Stats.vue';
import Pagination from './components/Pagination.vue';
import ResultsPerPageSelector from './components/ResultsPerPageSelector.vue';
import TreeMenu from './components/TreeMenu.vue';
import Menu from './components/Menu.vue';
import SortBySelector from './components/SortBySelector.vue';
import SearchBox from './components/SearchBox.vue';
import Clear from './components/Clear.vue';
Expand All @@ -38,6 +39,7 @@ const InstantSearch = {
Pagination,
ResultsPerPageSelector,
TreeMenu,
Menu,
SortBySelector,
SearchBox,
Clear,
Expand All @@ -57,6 +59,7 @@ const InstantSearch = {
Vue.component('ais-pagination', Pagination);
Vue.component('ais-results-per-page-selector', ResultsPerPageSelector);
Vue.component('ais-tree-menu', TreeMenu);
Vue.component('ais-menu', Menu);
Vue.component('ais-sort-by-selector', SortBySelector);
Vue.component('ais-search-box', SearchBox);
Vue.component('ais-clear', Clear);
Expand Down Expand Up @@ -88,6 +91,7 @@ export {
Pagination,
ResultsPerPageSelector,
TreeMenu,
Menu,
SortBySelector,
SearchBox,
Clear,
Expand Down

0 comments on commit 50c4c14

Please sign in to comment.