-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuHeader.vue
More file actions
401 lines (382 loc) · 13.6 KB
/
Copy pathLuHeader.vue
File metadata and controls
401 lines (382 loc) · 13.6 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<template>
<header class="header nav-undecorated">
<LuNavbar
v-if="navbarmenu"
:menu="navbarmenu"
/>
<div class="border-bottom">
<div class="container-fluid mw-xl">
<div
class="row m-0"
:class="[compact ? 'py-2' : 'py-3 py-lg-5']"
>
<div class="col p-0">
<div class="d-flex justify-content-between align-items-center h-100">
<div class="header-logo header-logo-lu flex-grow-1 flex-lg-grow-0">
<a
:href="logoUrl"
:title="logoTitle"
>
<img
v-if="logoSrc"
:src="logoSrc"
:alt="logoTitle"
class="mw-100"
>
</a>
</div>
<div
class="flex-shrink-1 flex-lg-shrink-0 flex-grow-0 d-flex flex-column justify-content-between h-100 mh-120"
>
<div
class="h-lg-auto flex-column justify-content-between align-items-end font-size-sm font-size-sm-base flex-grow-0"
>
<nav
class="nav text-center h-100 h-lg-auto align-items-center d-lg-none flex-nowrap"
>
<div
v-if="hasLogin"
class="nav-item"
>
<a
v-if="isLoggedIn"
class="ms-2 p-1 d-block nav-undecorated"
href="#"
aria-controls="header-logout"
aria-expanded="false"
:aria-label="t('luvt.header.logout')"
@click.prevent="emit('logout')"
>
<BAvatar
v-if="avatar"
size="sm"
variant="primary"
:text="avatar"
/>
<fa-icon
v-else
:icon="['fal', 'sign-out']"
/>
<br>
{{ t('luvt.header.logout') }}
</a>
<a
v-else
class="ms-2 p-1 d-block nav-undecorated"
href="#"
aria-controls="header-login"
aria-expanded="false"
:aria-label="t('luvt.header.login')"
@click.prevent="emit('login')"
>
<fa-icon :icon="['fal', 'sign-in']" />
<br>
{{ t('luvt.header.login') }}
</a>
</div>
<div
v-if="hasSearch"
class="nav-item"
>
<a
class="ms-2 p-1 d-block nav-undecorated"
href="#"
data-toggle="collapse"
aria-controls="header-search-form"
aria-expanded="false"
:aria-label="t('luvt.header.show_hide_search')"
@click.prevent="toggleSearch"
>
<fa-icon :icon="['fal', 'search']" />
<br>
{{ t('luvt.header.search') }}
</a>
</div>
<div class="nav-item">
<a
class="ms-2 p-1 d-block nav-undecorated"
href="#"
aria-controls="nav-mobile"
aria-expanded="false"
:aria-label="t('luvt.header.show_menu')"
@click.prevent="showNavMobileMenu"
>
<fa-icon :icon="['fal', 'bars']" />
<br>
{{ t('luvt.header.menu') }}
</a>
</div>
</nav>
<div class="d-none d-lg-flex flex-column flex-xl-row w-100 justify-content-end">
<nav
v-if="hasSearch"
class="nav align-items-center justify-content-end flex-1 mb-3 mb-xl-0"
>
<div class="nav-item flex-xl-grow-1">
<form
class="form-inline pe-xl-3"
@submit.prevent="search"
>
<div class="input-group input-group-round input-group-sm w-100 flex">
<input
id="header-search-field"
ref="headerSearchField"
v-model="searchField"
type="search"
class="form-control form-control-sm border-end-0"
:placeholder="searchPlaceholder"
>
<div class="input-group-append">
<button
class="btn btn-primary px-2"
type="submit"
>
<span class="me-2">{{ t('luvt.header.search') }}</span>
<fa-icon :icon="['fal', 'search']" />
</button>
</div>
</div>
</form>
</div>
</nav>
<nav class="nav align-items-center justify-content-end">
<div
v-if="hasLogin"
class="nav-item d-none d-lg-block"
>
<a
v-if="isLoggedIn"
class="nav-link px-0 ms-4"
href="#"
@click.prevent="emit('logout')"
>
<span class="me-1">
<BAvatar
v-if="avatar"
size="1.8em"
variant="primary"
:text="avatar"
/>
<fa-icon
v-else
class="fa-lg"
:icon="['fal', 'sign-out']"
/>
</span>
{{ t('luvt.header.logout') }}
</a>
<a
v-else
class="nav-link px-0 ms-4"
href="#"
@click.prevent="emit('login')"
>
<span class="me-1">
<fa-icon
class="fa-lg"
:icon="['fal', 'sign-in']"
/>
</span>
{{ t('luvt.header.login') }}
</a>
</div>
<div class="nav-item d-none d-lg-block">
<a
v-if="isSwedish"
class="nav-link px-0 ms-4"
href="#"
@click.prevent="switchLocale"
>
<span class="me-1">
<fa-icon
class="fa-lg"
:icon="['fal', 'globe']"
/>
</span> English
</a>
<a
v-else
class="nav-link px-0 ms-4"
href="#"
@click.prevent="switchLocale"
>
<span class="me-1">
<fa-icon
class="fa-lg"
:icon="['fal', 'globe']"
/>
</span> Svenska
</a>
</div>
<div class="nav-item d-none d-lg-block d-xl-none border-start ms-3 ps-3">
<a
class="nav-link"
href="#"
aria-controls="nav-mobile"
aria-expanded="false"
:aria-label="t('luvt.header.show_menu')"
@click.prevent="showNavMobileMenu"
>
<fa-icon :icon="['fal', 'bars']" />
{{ t('luvt.header.menu') }}
</a>
</div>
</nav>
</div>
</div>
<LuTopMenu
v-if="topmenu"
:menu="topmenu"
/>
</div>
</div>
</div>
</div>
</div>
<transition name="slide">
<div
v-show="! searchCollapsed"
id="header-search-form"
class="header-search-form collapse-lg pb-2 px-2"
>
<form
class="form-inline px-lg-3"
@submit.prevent="search"
>
<div class="input-group input-group-round input-group-sm w-100 flex">
<input
id="header-search-field-mobile"
ref="searchFieldMobile"
v-model="searchField"
type="search"
class="form-control form-control-sm border-end-0"
:placeholder="searchPlaceholder"
>
<div class="input-group-append">
<button
class="btn btn-primary px-2"
type="submit"
>
<span class="me-2">{{ t('luvt.header.search') }}</span>
<fa-icon :icon="['fal', 'search']" />
</button>
</div>
</div>
</form>
</div>
</transition>
</div>
<LuNavMobileMenu
ref="navMobileMenu"
:menu="mobilemenu"
/>
<div style="display: none">
<!-- bury the button for browsealoud -->
<div id="__ba_launchpad" />
</div>
</header>
</template>
<script setup>
import { computed, nextTick, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import BAvatar from './BAvatar.vue'
import LuNavbar from './LuNavbar.vue'
import LuTopMenu from './LuTopMenu.vue'
import LuNavMobileMenu from './LuNavMobileMenu.vue'
const props = defineProps({
topmenu: { type: Array, default: null },
mobilemenu: { type: Array, default: null },
navbarmenu: { type: Array, default: null },
hasLogin: { type: Boolean, default: false },
isLoggedIn: { type: Boolean, default: false },
avatar: { type: String, default: '' },
hasSearch: { type: Boolean, default: false },
emptySearch: { type: Boolean, default: false },
searchPlaceholder: { type: String, default: '' },
logoUrl: { type: String, required: true },
logoTitle: { type: String, required: true },
logoSrc: { type: String, required: true },
compact: { type: Boolean, default: false },
})
const emit = defineEmits(['login', 'logout', 'search'])
const route = useRoute()
const router = useRouter()
const { t, locale } = useI18n()
const searchField = ref('')
const searchCollapsed = ref(true)
const navMobileMenu = ref(null)
const searchFieldMobile = ref(null)
const headerSearchField = ref(null)
const isSwedish = computed(() => locale.value === 'sv')
const updateDocumentTitle = function () {
const current = router.currentRoute.value
const metaTitle = typeof current.meta?.title === 'string' ? current.meta.title : null
if (metaTitle) {
document.title = t(metaTitle)
return
}
const routeName = current.name
if (typeof routeName === 'string') {
document.title = t(routeName)
}
}
watch(
() => route.fullPath,
() => {
updateDocumentTitle()
},
{ immediate: true },
)
const switchLocale = function () {
const nextLocale = isSwedish.value ? 'en' : 'sv'
locale.value = nextLocale
document.documentElement.lang = nextLocale
localStorage.setItem('language', nextLocale)
updateDocumentTitle()
}
const showNavMobileMenu = function () {
navMobileMenu.value?.show()
}
const toggleSearch = function () {
searchCollapsed.value = !searchCollapsed.value
if (!searchCollapsed.value) {
nextTick(() => {
searchFieldMobile.value?.focus()
})
}
}
const search = function () {
const value = searchField.value.trim()
if (!value) {
return
}
emit('search', value)
if (props.emptySearch) {
searchField.value = ''
return
}
nextTick(() => {
searchFieldMobile.value?.select()
headerSearchField.value?.select()
})
}
</script>
<style scoped>
.slide-enter-active {
transition-duration: 0.2s;
transition-timing-function: linear;
}
.slide-leave-active {
transition-duration: 0.2s;
transition-timing-function: linear;
}
.slide-enter-to, .slide-leave {
max-height: 50px;
overflow: hidden;
}
.slide-enter, .slide-leave-to {
overflow: hidden;
max-height: 0;
}
</style>