forked from algolia/vue-instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigureRelatedItems.stories.js
100 lines (93 loc) · 2.91 KB
/
ConfigureRelatedItems.stories.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { storiesOf } from '@storybook/vue';
import algoliasearch from 'algoliasearch';
storiesOf('ais-configure-related-items', module).add('default', () => ({
template: `
<div>
<ais-instant-search :search-client="searchClient" index-name="instant_search">
<ais-index index-name="instant_search">
<ais-configure :hitsPerPage="1"/>
<ais-search-box />
<ais-hits>
<template slot="item" slot-scope="{ item }">
<div :ref="setReferenceHit(item)">
<div
class="playground-hits-image"
:style="{ backgroundImage: 'url(' + item.image + ')' }"
/>
<div class="playground-hits-desc">
<p>
<ais-highlight attribute="name" :hit="item" />
</p>
<p>Rating: {{ item.rating }}✭</p>
<p>Price: {{ item.price }}$</p>
</div>
</div>
</template>
</ais-hits>
</ais-index>
<ais-index index-name="instant_search" v-if="hit">
<h2>Related items</h2>
<ais-configure :hitsPerPage="4"/>
<ais-experimental-configure-related-items :hit="hit" :matchingPatterns="matchingPatterns" />
<div class="related-items">
<ais-pagination>
<div slot-scope="{ currentRefinement, isFirstPage, refine }">
<button
class="ais-RelatedHits-button"
:disabled="isFirstPage"
@click="refine(currentRefinement - 1)"
>
←
</button>
</div>
</ais-pagination>
<ais-hits>
<template slot="item" slot-scope="{ item }">
<div class="ais-RelatedHits-item-image">
<img :src="item.image" alt="item.name" />
</div>
<div class="ais-RelatedHits-item-title">
<h4>
<ais-highlight attribute="name" :hit="item" />
</h4>
</div>
</template>
</ais-hits>
<ais-pagination>
<div slot-scope="{ currentRefinement, isLastPage, refine }">
<button
class="ais-RelatedHits-button"
:disabled="isLastPage"
@click="refine(currentRefinement + 1)"
>
→
</button>
</div>
</ais-pagination>
</div>
</ais-index>
</ais-instant-search>
</div>
`,
data() {
return {
searchClient: algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
),
hit: null,
matchingPatterns: {
brand: { score: 3 },
type: { score: 10 },
categories: { score: 2 },
},
};
},
methods: {
setReferenceHit(item) {
if (!this.hit || this.hit.objectID !== item.objectID) {
this.hit = item;
}
},
},
}));