-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMeiliSearchBox.vue
301 lines (279 loc) · 8.79 KB
/
MeiliSearchBox.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<template>
<form
id="search-form"
class="meilisearch-search-wrapper search-box"
role="search"
:class="'theme-' + theme"
>
<input
id="meilisearch-search-input"
class="search-query"
:placeholder="placeholder"
/>
</form>
</template>
<script>
export default {
name: 'MeiliSearchBox',
data() {
return {
theme: false,
placeholder: undefined
}
},
watch: {
options(newValue) {
this.update(newValue)
}
},
mounted() {
const options = {
hostUrl: HOST_URL,
apiKey: API_KEY,
indexUid: INDEX_UID,
clientAgents: CLIENT_AGENTS,
meilisearchOptions: {
limit:
MAX_SUGGESTIONS || this.$site.themeConfig.searchMaxSuggestions || 5,
cropLength: CROP_LENGTH
},
autocompleteOptions: {
keyboardShortcuts: HOT_KEYS
},
layout: LAYOUT,
debug: DEBUG,
enableDarkMode: ENABLE_DARK_MODE
}
this.updateTheme(options)
this.initialize(options)
this.placeholder =
PLACEHOLDER || this.$site.themeConfig.searchPlaceholder || ''
},
methods: {
initialize(userOptions) {
Promise.all([
import(
/* webpackChunkName: "docs-searchbar" */ 'docs-searchbar.js/dist/cdn/docs-searchbar.min.js'
),
import(
/* webpackChunkName: "docs-searchbar" */ 'docs-searchbar.js/dist/cdn/docs-searchbar.min.css'
)
]).then(([docsSearchBar]) => {
docsSearchBar = docsSearchBar.default
const input = Object.assign({}, userOptions, {
inputSelector: '#meilisearch-search-input',
handleSelected: (input, event, suggestion) => {
const { pathname, hash } = new URL(suggestion.url)
const routepath = pathname.replace(this.$site.base, '/')
this.$router.push(`${routepath}${hash}`)
}
})
docsSearchBar(input)
})
},
update(options) {
this.updateTheme(options)
this.$el.innerHTML =
'<input id="meilisearch-search-input" class="search-query">'
this.initialize(options)
},
updateTheme(options) {
if (options.enableDarkMode === true) {
this.theme = 'dark'
} else if (options.enableDarkMode === false) {
this.theme = 'light'
} else {
this.theme = 'auto'
}
}
}
}
</script>
<style lang="stylus">
@require './styles/palette.styl'
light-input()
color lighten($textColor, 25%)
border 1px solid darken($borderColor, 10%)
background-color #fff
&:focus
border-color $accentColor
dark-input()
color $textDarkColor
border 1px solid $borderDarkColor
background-color $inputDarkBgColor
&:focus
border-color $accentDarkColor
// Searchbox
#meilisearch-search-input
cursor text
width 10rem
height: 2rem
display inline-block
border-radius 2rem
font-size 0.9rem
line-height 2rem
padding 0 0.5rem 0 2rem
outline none
transition border .2s ease
background: url(assets/search.svg) 0.6rem 0.5rem no-repeat
&:focus
cursor auto
background-size 1rem
.meilisearch-search-wrapper.theme-light
#meilisearch-search-input
light-input()
.meilisearch-search-wrapper.theme-dark
#meilisearch-search-input
dark-input()
@media (prefers-color-scheme: dark)
.meilisearch-search-wrapper.theme-auto
#meilisearch-search-input
dark-input()
@media (prefers-color-scheme: light)
.meilisearch-search-wrapper.theme-auto
#meilisearch-search-input
light-input()
.meilisearch-search-wrapper
display: inline-block;
position: relative;
margin-right 1rem
& > div > span
vertical-align middle
.dsb-cursor
background rgba($accentColor, 0.05)
.meilisearch-autocomplete
line-height: 2
// Layout "columns"
.docs-searchbar-suggestion:not(.suggestion-layout-simple)
border-color $borderColor
.docs-searchbar-suggestion--category-header
background #f1f3f5
padding 5px 10px
border-radius 4px
background lighten($accentColor, 20%)
font-weight 600
color #fff
.docs-searchbar-suggestion--highlight
box-shadow none
background lighten($accentColor, 70%)
.docs-searchbar-suggestion--wrapper
display flex
padding 0
.docs-searchbar-suggestion--highlight
color darken($accentColor, 20%)
.docs-searchbar-suggestion--title
margin-bottom 0
color $textColor
.docs-searchbar-suggestion--subcategory-column
border-color $borderColor
.docs-searchbar-suggestion--subcategory-column-text
color #555
.docs-searchbar-suggestion--text
.docs-searchbar-suggestion--highlight
box-shadow inset 0 -2px 0 0 lighten($accentColor, 20%)
color: inherit
// Layout simple
.suggestion-layout-simple
.docs-searchbar-suggestion--title
color: $accentColor
&:before
color: darken($accentColor, 20%)
.docs-searchbar-suggestion--category-header
.docs-searchbar-suggestion--highlight
box-shadow unset
color: darken($accentColor, 20%)
background-color rgba($accentColor, 0.05)
.docs-searchbar-suggestion--category-header-lvl0, .docs-searchbar-suggestion--category-header-lvl1
.docs-searchbar-suggestion--highlight
background-color: transparent
box-shadow inset 0 -2px 0 0 lighten($accentColor, 20%)
color inherit
// Footer
.docs-searchbar-footer
.docs-searchbar-footer-logo
margin-bottom -4px
.dsb-cursor .docs-searchbar-suggestion--content
background-color #e7edf3
color $textColor
// Dark theme
div[data-ds-theme="dark"]
.meilisearch-autocomplete
.dsb-dropdown-menu [class^=dsb-dataset-], .docs-searchbar-suggestion
background $dropdownBgDarkColor
// Layout "columns"
.docs-searchbar-suggestion:not(.suggestion-layout-simple)
border-color $borderDarkColor
.docs-searchbar-suggestion--wrapper
.docs-searchbar-suggestion--highlight
color $accentDarkColor
.docs-searchbar-suggestion--category-header
background $accentDarkColor
.docs-searchbar-suggestion--highlight
background lighten($accentDarkColor, 20%)
.docs-searchbar-suggestion--title
color $textDarkColor
.docs-searchbar-suggestion--subcategory-column
border-color $borderDarkColor // Simple ?
.docs-searchbar-suggestion--subcategory-column-text
color $textDarkColor
.docs-searchbar-suggestion--text
.docs-searchbar-suggestion--highlight
box-shadow inset 0 -2px 0 0 lighten($accentDarkColor, 20%)
// Layout "simple"
.suggestion-layout-simple
.docs-searchbar-suggestion--category-header
.docs-searchbar-suggestion--category-header-lvl0, .docs-searchbar-suggestion--category-header-lvl1
.docs-searchbar-suggestion--highlight
box-shadow inset 0 -2px 0 0 darken($accentDarkColor, 10%)
.docs-searchbar-suggestion--title
.docs-searchbar-suggestion--highlight
color lighten($accentDarkColor, 20%)
background rgba($accentDarkColor, 10%)
.docs-searchbar-suggestion--category-header-lvl0, .docs-searchbar-suggestion--category-header-lvl1
.docs-searchbar-suggestion--highlight
color inherit
// Suggestion on hover
.dsb-dropdown-menu .dsb-suggestions .dsb-cursor
.docs-searchbar-suggestion.suggestion-layout-simple
background-color rgba($accentDarkColor, 30%)
.docs-searchbar-suggestion:not(.suggestion-layout-simple)
.docs-searchbar-suggestion--content
background-color rgba($accentDarkColor, 30%)
@media (min-width: $MQMobile)
.meilisearch-search-wrapper
.meilisearch-autocomplete
.docs-searchbar-suggestion
.docs-searchbar-suggestion--subcategory-column
float none
width 150px
min-width 150px
display table-cell
.docs-searchbar-suggestion--content
float none
display table-cell
width 100%
vertical-align top
.dsb-dropdown-menu
min-width 515px
@media (max-width: $MQMobile)
.meilisearch-search-wrapper
.dsb-dropdown-menu
min-width calc(100vw - 4rem)
max-width calc(100vw - 4rem)
.docs-searchbar-suggestion--wrapper
padding 5px 7px 5px 5px
.docs-searchbar-suggestion--subcategory-column
padding 0
background white
.docs-searchbar-suggestion--subcategory-column-text:after
content " > "
font-size 10px
line-height 14.4px
display inline-block
width 5px
margin -3px 3px 0
vertical-align middle
div[data-ds-theme="dark"]
.docs-searchbar-suggestion--subcategory-column
background transparent
</style>