forked from algolia/vue-instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrentRefinements.stories.js
128 lines (127 loc) · 3.59 KB
/
CurrentRefinements.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
import { storiesOf } from '@storybook/vue';
import { previewWrapper } from './utils';
import { withKnobs } from '@storybook/addon-knobs/vue';
storiesOf('ais-current-refinements', module)
.addDecorator(previewWrapper())
.addDecorator(withKnobs)
.add('default', () => ({
template: `
<ais-current-refinements />
`,
}))
.add('with a refinement to clear', () => ({
template: `
<ais-current-refinements :excluded-attributes="[]" />
`,
}))
.add('with multiple refinements to clear', () => ({
template: `
<div>
<ais-current-refinements :excluded-attributes="[]" />
<hr />
<ais-hierarchical-menu
:attributes="[
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2',
]"
/>
<hr />
<ais-range-input attribute="price" />
</div>
`,
}))
.add('with excluded attributes', () => ({
template: `
<div>
<p><strong>excludes: Brand</strong>
<ais-current-refinements
:excluded-attributes="['brand']"
/>
<hr />
<ais-hierarchical-menu
:attributes="[
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2',
]"
/>
<hr />
<ais-range-input attribute="price" />
</div>
`,
}))
.add('with transform items', () => ({
template: `
<ais-current-refinements :transform-items="transformItems" />
`,
methods: {
transformItems(items) {
return items.map(item =>
Object.assign({}, item, {
label: item.label.toLocaleUpperCase(),
refinements: item.refinements.map(refinement =>
Object.assign({}, refinement, {
label: refinement.label.toLocaleUpperCase(),
})
),
})
);
},
},
}))
.add('with custom item rendering', () => ({
template: `
<ais-current-refinements :excluded-attributes="[]">
<template slot="item" slot-scope="{ item, refine }">
<span style="color: white">
{{item.label}}
<ul>
<li v-for="(refinement, index) in item.refinements" :key="index">
<button @click="refine(refinement)">
{{refinement.label}} ╳
</button>
</li>
</ul>
</span>
</template>
</ais-current-refinements>
`,
}))
.add('with custom refinement rendering', () => ({
template: `
<ais-current-refinements :excluded-attributes="[]">
<template slot="refinement" slot-scope="{ refinement, refine }">
<button
@click="refine(refinement)"
style="color: white"
>
{{refinement.label}} ╳
</button>
</template>
</ais-current-refinements>
`,
}))
.add('with full custom rendering', () => ({
template: `
<ais-current-refinements :excluded-attributes="[]">
<template slot-scope="{ refine, items, createURL }">
<ul>
<li
v-for="item in items"
:key="item.attribute"
>
{{item.attribute}}:
<button
v-for="refinement in item.refinements"
@click="item.refine(refinement)"
:key="refinement.value"
>
{{refinement.label}} ╳
</button>
</li>
</ul>
</template>
</ais-current-refinements>
`,
}));