forked from algolia/vue-instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStateResults.stories.js
122 lines (121 loc) · 3.12 KB
/
StateResults.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
import { previewWrapper } from './utils';
import { storiesOf } from '@storybook/vue';
storiesOf('ais-state-results', module)
.addDecorator(
previewWrapper({
indexName: 'demo-query-rules',
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 + ')' }"
/>
<div class="playground-hits-desc">
<p>
<ais-highlight attribute="title" :hit="item" />
</p>
</div>
</li>
</ol>
`,
})
)
.add('default display', () => ({
template: `<ais-state-results />`,
}))
.add('custom "autocomplete"', () => ({
template: `
<div>
<ais-search-box />
<ais-state-results>
<template slot-scope="{ state: { query } }">
<ais-hits v-if="query">
<h3
slot="item"
slot-scope="{ item }"
:tabindex="0"
@click="alert(item)"
@keyup.enter="alert(item)"
>
<ais-highlight :hit="item" attribute="title"/>
</h3>
</ais-hits>
</template>
</ais-state-results>
</div>
`,
methods: {
alert(item) {
// eslint-disable-next-line no-alert
alert(item.name);
},
},
}))
.add('banner', () => ({
template: `
<div>
<ais-search-box />
<p>type "documentary"</p>
<ais-state-results>
<template slot-scope="{ results: { userData } }">
<div>
<img
v-for="{ banner_img_slug: src } in userData"
:key="src"
:src="'https://preview.algolia.com/query-rules/' + src"
/>
</div>
</template>
</ais-state-results>
</div>
`,
}))
.add('no results', () => ({
template: `
<div>
<ais-search-box />
<ais-state-results>
<template slot-scope="{ state: { query }, results: { hits } }">
<p v-if="hits.length === 0">
No results found for the query: <q>{{ query }}</q>
</p>
</template>
</ais-state-results>
<ais-hits />
</div>
`,
}))
.add('ssr debugger', () => ({
template: `
<ais-state-results>
<div slot-scope="{ state }">
<p>copy this to <code>findResultsState</code></p>
<pre>{{ cleanup(state) }}</pre>
</div>
</ais-state-results>
`,
methods: {
cleanup(state) {
// loop over all values of the state, keep only those which aren't empty
return Object.fromEntries(
Object.entries(state)
.map(
([k, v]) =>
v === null || v === undefined || Object.keys(v).length === 0
? undefined
: [k, v]
)
.filter(Boolean)
);
},
},
}));