Md.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="app-container">
  3. <v-app class="navigation-sm">
  4. <!-- Top bar -->
  5. <v-app-bar>
  6. <template #prepend>
  7. <v-app-bar-nav-icon @click="toggleMenu" />
  8. </template>
  9. <v-app-bar-title>
  10. <nuxt-link to="/">
  11. <v-img
  12. class="logo-md"
  13. src="/images/logos/opentalent/Logo_Opentalent-gris.png"
  14. />
  15. </nuxt-link>
  16. </v-app-bar-title>
  17. <template #append>
  18. <v-btn
  19. href="https://admin.opentalent.fr/#/login/"
  20. icon="fas fa-user"
  21. class="icon"
  22. aria-label="Se connecter"
  23. />
  24. <v-btn
  25. to="/nous-contacter"
  26. icon="fas fa-phone"
  27. aria-label="Nous contacter"
  28. class="icon"
  29. />
  30. <v-btn
  31. :href="runtimeConfig.public.agendaBaseUrl"
  32. icon="fas fa-calendar"
  33. aria-label="L'agenda culturel"
  34. class="icon"
  35. />
  36. </template>
  37. </v-app-bar>
  38. <!-- Tiroir de navigation principal -->
  39. <v-navigation-drawer v-model="isMenuOpen" app temporary>
  40. <v-list nav dense>
  41. <v-list-item
  42. v-if="isSubMenu"
  43. class="menuItem back-item"
  44. @click="onBackItemClick"
  45. >
  46. <v-list-item-title>
  47. <v-icon icon="fas fa-caret-left" class="mr-1" /> Retour
  48. </v-list-item-title>
  49. </v-list-item>
  50. <v-list-item
  51. v-for="(item, index) in activeMenu"
  52. :key="item.label"
  53. :to="item.to"
  54. class="menuItem"
  55. @click="onMenuItemClick(index, item)"
  56. >
  57. <v-list-item-title class="d-flex flex-row w-100">
  58. <span class="flex-grow-1">
  59. {{ item.label }}
  60. </span>
  61. <span v-if="item.children?.length! > 0">
  62. <v-icon icon="fa fa-angle-right" />
  63. </span>
  64. </v-list-item-title>
  65. </v-list-item>
  66. </v-list>
  67. </v-navigation-drawer>
  68. </v-app>
  69. </div>
  70. </template>
  71. <script setup lang="ts">
  72. import type { PropType, Ref } from 'vue'
  73. import type { MainMenuItem } from '~/types/interface'
  74. const runtimeConfig = useRuntimeConfig()
  75. const props = defineProps({
  76. menu: {
  77. type: Array as PropType<Array<MainMenuItem>>,
  78. required: true,
  79. },
  80. })
  81. const isMenuOpen: Ref<boolean> = ref(false)
  82. const toggleMenu = () => {
  83. isMenuOpen.value = !isMenuOpen.value
  84. }
  85. const activeMenuIndex: Ref<number | null> = ref(null)
  86. const activeMenu = computed(() =>
  87. activeMenuIndex.value !== null
  88. ? props.menu![activeMenuIndex.value].children
  89. : props.menu
  90. )
  91. /**
  92. * Determines if the is active menu is a sub-menu .
  93. *
  94. * @function isSubMenu
  95. * @returns {boolean} - True if a sub-menu is active, otherwise false.
  96. */
  97. const isSubMenu = computed(() => activeMenuIndex.value !== null)
  98. /**
  99. * Handles the click event on a menu item.
  100. *
  101. * @param {number} index - The index of the clicked menu item.
  102. * @param {MainMenuItem} item - The clicked menu item.
  103. * @returns {void}
  104. */
  105. const onMenuItemClick = (index: number, item: MainMenuItem): void => {
  106. if (!item.children) {
  107. return
  108. }
  109. withAnimation(() => (activeMenuIndex.value = index))
  110. }
  111. /**
  112. * Function to handle back button click event.
  113. */
  114. const onBackItemClick = (): void => {
  115. withAnimation(() => (activeMenuIndex.value = null))
  116. }
  117. /**
  118. * Déclenche une animation de changement de menu en fermant et rouvrant le drawer
  119. * @param callback
  120. */
  121. const withAnimation = (callback: () => void) => {
  122. isMenuOpen.value = false
  123. callback()
  124. setTimeout(() => {
  125. isMenuOpen.value = true
  126. }, 85)
  127. }
  128. </script>
  129. <style scoped lang="scss">
  130. .app-container {
  131. height: 54px;
  132. }
  133. .v-app-bar {
  134. max-width: 100vw;
  135. }
  136. .navigation-sm {
  137. background-color: var(--neutral-color);
  138. position: fixed;
  139. top: 0;
  140. z-index: 1000;
  141. }
  142. .logo-md {
  143. width: 150px;
  144. height: 50px;
  145. }
  146. .back-item {
  147. border-bottom: solid 1px var(--on-neutral-color-light);
  148. border-radius: 0;
  149. .v-list-item-title {
  150. display: flex;
  151. align-items: center;
  152. }
  153. }
  154. .icon {
  155. color: var(--on-neutral-color-light);
  156. }
  157. </style>