This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathHitsPerPage.vue
74 lines (72 loc) · 1.54 KB
/
HitsPerPage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<template>
<div
v-if="state"
:class="suit()"
>
<slot
:items="state.items"
:refine="state.refine"
:hasNoResults="state.hasNoResults"
>
<select
:class="suit('select')"
v-model="selected"
@change="handleChange"
>
<option
v-for="item in state.items"
:key="item.value"
:class="suit('option')"
:value="item.value"
>{{ item.label }}</option>
</select>
</slot>
</div>
</template>
<script>
import { connectHitsPerPage } from 'instantsearch.js/es/connectors';
import { createPanelConsumerMixin } from '../mixins/panel';
import { createWidgetMixin } from '../mixins/widget';
import { createSuitMixin } from '../mixins/suit';
export default {
name: 'AisHitsPerPage',
mixins: [
createSuitMixin({ name: 'HitsPerPage' }),
createWidgetMixin({ connector: connectHitsPerPage }),
createPanelConsumerMixin({
mapStateToCanRefine: state => !state.hasNoResults,
}),
],
props: {
items: {
type: Array,
required: true,
default: () => [],
},
transformItems: {
type: Function,
default(items) {
return items;
},
},
},
data() {
return {
selected: this.items.find(item => item.default === true).value,
};
},
computed: {
widgetParams() {
return {
items: this.items,
transformItems: this.transformItems,
};
},
},
methods: {
handleChange() {
this.state.refine(this.selected);
},
},
};
</script>