ldc-showroom/components/layout/AppHeader.vue
Jérémy Munsch 9bfc68e31c
Better layout
2024-01-12 16:36:16 +01:00

154 lines
4.1 KiB
Vue

<template>
<nav
id="top-navbar"
class="navbar navbar-expand-lg"
:style="`background-color: ${activeBrand?.color} !important`"
>
<div class="container-fluid">
<!-- UNE MARQUE EST SELECTIONNEE -->
<div
v-if="activeBrand"
:class="{
'navbar-brand d-flex flex-row flex-grow-1 justify-content-between align-items-center': true,
'mx-auto': !activeRange,
}"
>
<NuxtLink
:to="`/brands/${activeBrand.slug}`"
class="d-inline-block"
data-bs-toggle="tooltip"
:title="`Voir les gammes de la marque ${activeBrand.name}`"
>
<img class="img-fluid" :src="`/data/${activeBrand.picture}`" :alt="`Marque ${activeBrand.name}`" :title="`Le logo de la marque ${activeBrand.name}`">
</NuxtLink>
<span v-if="activeRange" class="fs-1 d-block text-center flex-grow-1">{{ activeRange.name }}</span>
</div>
<!-- HOME (PAS DE MARQUE) -->
<div v-else class="navbar-brand mx-auto">
<NuxtLink
to="/"
class="d-inline-block"
data-bs-toggle="tooltip"
:title="settings.title"
>
<img src="assets/pictures/layout/ldc-intl.png" alt="Logo LDC" class="img-fluid main-logo">
</NuxtLink>
</div>
<button
class="navbar-toggler"
data-bs-toggle="collapse"
data-bs-target="#navbar-menu"
type="button"
aria-controls="navbar-menu"
aria-expanded="false"
aria-label="Afficher / Masquer les langues"
>
<span class="navbar-toggler-icon" />
</button>
<div class="navbar-collapse collapse flex-grow-0">
<ul class="navbar-nav ms-auto">
<li
v-for="(locale,localeIndex) of locales"
:key="localeIndex"
class="nav-item"
>
<button
class="btn btn-link"
:title="locale.label"
data-bs-toggle="tooltip"
@click.prevent="switchLocale(locale.iso)"
>
<span :class="`fi fi-${locale.iso}`" />
</button>
</li>
</ul>
</div>
</div>
</nav>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import type { RouteLocationNormalizedLoaded } from "vue-router";
import Toast, { ToastTypeEnum } from "~/classes/Toast";
import { useAppStore } from "~/stores/useAppStore";
import bsTooltips from "~/vueModules/bsTooltips";
export default defineComponent({
name: "AppHeader",
data(): {
versions: typeof window.versions;
settings: TypeSettings;
locales: Array<{
iso: string,
label: string,
}>,
route: RouteLocationNormalizedLoaded;
activeBrand: TypeBrand|null;
activeRange: TypeRange|null;
} {
return {
versions: window.versions,
settings: {} as TypeSettings,
locales: [
{
iso: "fr",
label: "Francais"
},
{
iso: "de",
label: "Allemand"
},
{
iso: "gr",
label: "Suédois"
},
],
route: useRoute(),
activeBrand: null,
activeRange: null,
};
},
watch: {
$route(to: RouteLocationNormalizedLoaded) {
if(to.name === "index") {
// * Reset active Brand on main page
useAppStore().setActiveBrand(null);
}
this.activeBrand = useAppStore().activeBrand;
this.activeRange = useAppStore().activeRange;
},
},
mounted() {
this.settings = useAppStore().data.settings();
this.activeBrand = useAppStore().activeBrand;
bsTooltips.methods.initTooltips();
},
methods: {
switchLocale(locale:string) {
Toast.toast(`Switch locale ${locale}`, ToastTypeEnum.default);
}
}
});
</script>
<style lang="postcss">
@import "flag-icons/sass/flag-icons.scss";
</style>
<style lang="scss" scoped>
@import "bootstrap/scss/vendor/rfs";
#top-navbar {
.main-logo {
@include rfs(30rem, max-height);
height: 20vh;
}
.fi {
@include rfs(8rem, line-height);
@include rfs(10rem, width);
}
}
</style>