| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <!--
- Menu principal de l'application
- Prend en paramètre une liste de ItemMenu et les met en forme
- -->
- <template>
- <v-navigation-drawer
- :mini-variant.sync="miniVariant"
- v-model="open"
- class="bg-ot-dark-grey text-ot-menu-color"
- >
- <template #prepend>
- <slot name="title"></slot>
- </template>
- <v-list class="left-menu">
- <div v-for="(item, i) in menu.children" :key="i">
- <!-- Cas 1 : l'item n'a pas d'enfants, c'est un lien -->
- <v-list-item
- v-if="!item.children"
- :href="isExternalLink(item) ? item.to : undefined"
- :to="!isExternalLink(item) ? item.to : undefined"
- exact
- >
- <template v-slot:prepend>
- <v-list-item-action start>
- <v-icon :icon="item.icon.name" class="text-ot-menu-color" small />
- </v-list-item-action>
- </template>
- <v-list-item-title
- v-text="item.title"
- class="text-ot-menu-color"
- />
- </v-list-item>
- <!-- Cas 2 : l'item a des enfants, c'est un groupe -->
- <v-list-group
- v-else
- v-model="item.active"
- >
- <template #activator>
- <v-list-item-action>
- <v-icon :icon="item.icon.name" class="text-ot-menu-color" small />
- </v-list-item-action>
- <v-list-item-title class="text-ot-menu-color" v-text="item.title" />
- </template>
- <v-list-item
- v-for="child in item.children"
- :key="child.label"
- :href="isExternalLink(child) ? child.to : undefined"
- :to="!isExternalLink(child) ? child.to : undefined"
- router
- exact
- >
- <v-list-item-action>
- <v-icon :icon="child.icon.name" class="text-ot-white" small />
- </v-list-item-action>
- <v-list-item-title class="text-ot-white" v-text="child.title" />
- </v-list-item>
- <template #appendIcon>
- <v-icon class="text-ot-menu-color" small>mdi-chevron-down</v-icon>
- </template>
- </v-list-group>
- </div>
- </v-list>
- <template #append>
- <slot name="foot"></slot>
- </template>
- </v-navigation-drawer>
- </template>
- <script setup lang="ts">
- import {onUnmounted, watch, WatchStopHandle} from "@vue/runtime-core";
- import {ref, toRefs} from "@vue/reactivity";
- import {MENU_LINK_TYPE, MenuGroup, MenuItem} from "~/types/menus";
- const props = defineProps({
- menu: {
- type: Object as () => MenuGroup,
- required: true
- },
- miniVariant: {
- type: Boolean,
- required: true
- },
- openMenu: {
- type: Boolean,
- required: true
- }
- })
- const { openMenu } = toRefs(props)
- const open = ref(true)
- // Par défaut si l'écran est trop petit au chargement de la page, le menu doit être fermé.
- if(process.client)
- open.value = window.innerWidth >= 1264
- // TODO : ajouter une petite explication de ce qu'on fait dans ce watch
- const unwatch: WatchStopHandle = watch(openMenu, (newValue, oldValue) => {
- if (newValue !== oldValue) {
- open.value = true
- }
- })
- const isExternalLink = (menuItem: MenuItem | MenuGroup) => 'type' in menuItem && menuItem.type === MENU_LINK_TYPE.EXTERNAL
- onUnmounted(() => {
- unwatch()
- })
- </script>
- <style scoped>
- .v-list-item__action, .v-list-group__header__prepend-icon {
- margin-right: 10px !important;
- }
- .v-application--is-ltr .v-list-group--no-action > .v-list-group__header {
- margin-left: 0;
- padding-left: 0;
- }
- .v-application--is-ltr .v-list-group--no-action > .v-list-group__items > .v-list-item {
- padding-left: 30px;
- }
- .v-list-item__title {
- font-size: 14px;
- }
- .v-list-item {
- min-height: 10px !important;
- }
- .v-list-item__action {
- margin: 10px 0;
- }
- .v-list-item__content {
- padding: 8px 0;
- }
- .home_menu {
- font-size: 23px;
- }
- </style>
|