Menu.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!--
  2. Menu déroulant générique pour l'affichage des menus du
  3. header principal (configuration, paramètres du compte...)
  4. -->
  5. <template>
  6. <div v-if="displayMenu">
  7. <v-btn ref="btn" icon size="small" class="ml-2">
  8. <v-avatar
  9. v-if="menu.icon.avatarId || menu.icon.avatarByDefault"
  10. size="30"
  11. >
  12. <UiImage
  13. :image-id="menu.icon.avatarId"
  14. :size="IMAGE_SIZE.SM"
  15. :default-image="menu.icon.avatarByDefault"
  16. :width="30"
  17. />
  18. </v-avatar>
  19. <v-icon v-else :icon="menu.icon.name" class="on-primary" />
  20. </v-btn>
  21. <v-tooltip :activator="btn" :text="$t(menu.label)" location="bottom" />
  22. <v-menu
  23. :activator="btn"
  24. :model-value="isOpened()"
  25. @update:model-value="onStateUpdated"
  26. >
  27. <v-card>
  28. <v-card-title class="theme-neutral text-body-2 font-weight-bold">
  29. {{ $t(menu.label) }}
  30. </v-card-title>
  31. <v-card-text class="ma-0 pa-0 header-menu">
  32. <v-list density="compact" :subheader="true">
  33. <template v-for="(child, index) in menu.children" :key="index">
  34. <v-list-item
  35. :id="child.label"
  36. :href="!isInternalLink(child) ? child.to : undefined"
  37. :to="isInternalLink(child) ? child.to : undefined"
  38. :class="{
  39. 'end-of-section':
  40. 'endOfSubsection' in child && child.endOfSubsection,
  41. }"
  42. >
  43. <span v-if="child.icon" class="pr-2 d-flex align-center">
  44. <v-avatar
  45. v-if="menu.icon.avatarId || child.icon.avatarByDefault"
  46. size="30"
  47. >
  48. <UiImage
  49. :image-id="child.icon.avatarId"
  50. :default-image="child.icon.avatarByDefault"
  51. :width="30"
  52. />
  53. </v-avatar>
  54. <v-icon v-else class="on-primary" size="small">
  55. {{ child.icon.name }}
  56. </v-icon>
  57. </span>
  58. <span>{{
  59. translateLabel ? $t(child.label) : child.label
  60. }}</span>
  61. </v-list-item>
  62. </template>
  63. </v-list>
  64. </v-card-text>
  65. <v-card-actions
  66. v-if="menu.actions.length > 0"
  67. class="ma-0 pa-0 theme-primary"
  68. >
  69. <template v-for="(action, index) in menu.actions" :key="index">
  70. <v-list-item
  71. :id="action.label"
  72. :href="!isInternalLink(action) ? action.to : undefined"
  73. :to="isInternalLink(action) ? action.to : undefined"
  74. >
  75. <v-list-item-title class="text-body-2">
  76. {{ $t(action.label) }}
  77. </v-list-item-title>
  78. </v-list-item>
  79. </template>
  80. </v-card-actions>
  81. </v-card>
  82. </v-menu>
  83. </div>
  84. </template>
  85. <script setup lang="ts">
  86. import { computed, ref } from 'vue'
  87. import { useMenu } from '~/composables/layout/useMenu'
  88. import { IMAGE_SIZE } from '~/types/enum/enums'
  89. const props = defineProps({
  90. name: {
  91. type: String,
  92. required: true,
  93. },
  94. translateLabel: {
  95. type: Boolean,
  96. required: false,
  97. default: true,
  98. },
  99. })
  100. const { getMenu, isInternalLink, hasMenu, setMenuState, isMenuOpened } =
  101. useMenu()
  102. const menu = getMenu(props.name)
  103. const displayMenu = computed(() => hasMenu(props.name))
  104. const isOpened = () => isMenuOpened(props.name)
  105. const onStateUpdated = (e: boolean) => {
  106. setMenuState(props.name, e)
  107. }
  108. const btn = ref(null)
  109. </script>
  110. <style scoped lang="scss">
  111. :deep(.v-btn .v-icon) {
  112. font-size: 1rem !important;
  113. }
  114. .v-list {
  115. padding: 0;
  116. }
  117. .v-list-item {
  118. width: 100%;
  119. }
  120. .header-menu .v-list .v-list-item:last-child {
  121. border-bottom: none;
  122. }
  123. </style>