forked from algolia/vue-instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryRuleContext.stories.js
136 lines (134 loc) · 3.79 KB
/
QueryRuleContext.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { previewWrapper } from './utils';
import { storiesOf } from '@storybook/vue';
storiesOf('ais-query-rule-context', module)
.addDecorator(
previewWrapper({
indexName: 'instant_search_movies',
filters: '<ais-refinement-list attribute="genre" />',
hits: `
<ol slot-scope="{ items }" class="playground-hits">
<li
v-for="item in items"
:key="item.objectID"
class="playground-hits-item"
>
<div
class="playground-hits-image"
:style="{ backgroundImage: 'url(' + item.image + ')' }"
/>
<article>
<header>
<strong><ais-highlight attribute="title" :hit="item"/></strong>
</header>
</article>
</li>
</ol>
`,
})
)
.add('default', () => ({
template: `
<div>
<ul>
<li>On empty query, select the "Drama" category and The Shawshank Redemption appears</li>
<li>On empty query, select the "Thriller" category and Pulp Fiction appears</li>
<li>Type <q>music</q> and a banner will appear.</li>
</ul>
<ais-query-rule-context :tracked-filters="trackedFilters" />
<ais-query-rule-custom-data>
<template slot="item" slot-scope="{ item }">
<h2>{{ item.title }}</h2>
<a :href="item.link">
<img
:src="item.banner"
:alt="item.title"
:style="{ width: '100%' }"
/>
</a>
</template>
</ais-query-rule-custom-data>
</div>`,
data() {
return {
trackedFilters: {
genre: () => ['Thriller', 'Drama'],
},
};
},
}))
.add('with initial filter', () => ({
template: `
<div>
<ul>
<li>On empty query, select the "Drama" category and The Shawshank Redemption appears</li>
<li>On empty query, select the "Thriller" category and Pulp Fiction appears</li>
<li>Type <q>music</q> and a banner will appear.</li>
</ul>
<ais-configure
:disjunctive-facets-refinements.camel="{
genre: ['Drama']
}"
/>
<ais-query-rule-context :tracked-filters="trackedFilters" />
<ais-query-rule-custom-data>
<template slot="item" slot-scope="{ item }">
<h2>{{ item.title }}</h2>
<a :href="item.link">
<img
:src="item.banner"
:alt="item.title"
:style="{ width: '100%' }"
/>
</a>
</template>
</ais-query-rule-custom-data>
</div>
`,
data() {
return {
trackedFilters: {
genre: () => ['Thriller', 'Drama'],
},
};
},
}))
.add('with initial rule context', () => ({
template: `
<div>
<ul>
<li>On empty query: "The Shawshank Redemption" appears</li>
<li>On empty query & "Thriller" category: "Pulp Fiction" appears</li>
<li>On query <q>music</q>: "This is it" appears.</li>
</ul>
<ais-query-rule-context
:tracked-filters="trackedFilters"
:transform-rule-contexts="transformRuleContexts"
/>
<ais-query-rule-custom-data>
<template slot="item" slot-scope="{ item }">
<h2>{{ item.title }}</h2>
<a :href="item.link">
<img
:src="item.banner"
:alt="item.title"
:style="{ width: '100%' }"
/>
</a>
</template>
</ais-query-rule-custom-data>
</div>
`,
data() {
return {
trackedFilters: {
genre: values => values,
},
transformRuleContexts: ruleContexts => {
if (ruleContexts.length === 0) {
return ['ais-genre-Drama'];
}
return ruleContexts;
},
};
},
}));