ActionMenu.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!--
  2. Menu d'actions rapides (appel, contact, ...), qui reste accroché au bord droit
  3. de l'écran (ou au bas de l'écran sur les petits écrans)
  4. -->
  5. <template>
  6. <div v-show="showMenu">
  7. <!-- Écrans larges : menu lateral, accroché au bord droit de l'écran -->
  8. <div
  9. v-if="lgAndUp && isVisible"
  10. class="sticky-menu lateral"
  11. >
  12. <v-row
  13. v-for="(action, index) in actionsOrDefault"
  14. :key="index"
  15. :class="['square', action.color]"
  16. @click="() => onActionClick(action)"
  17. >
  18. <NuxtLink class="link">
  19. <div>
  20. <v-icon :class="action.icon" />
  21. <p class="text-square mt-2">
  22. {{ action.text }}
  23. </p>
  24. </div>
  25. </NuxtLink>
  26. </v-row>
  27. </div>
  28. <!-- Petits écrans : menu sous forme de bandeau en pied de page (sauf si le footer du site est visible) -->
  29. <div v-else-if="isVisible" class="sticky-menu band">
  30. <v-btn
  31. v-for="(action, index) in actionsOrDefault"
  32. :key="index"
  33. :class="[action.color]"
  34. @click="() => onActionClick(action)"
  35. >
  36. <span v-if="mdAndUp">{{ action.text }}</span>
  37. <v-icon v-else :aria-label="action.text">{{ action.icon }}</v-icon>
  38. </v-btn>
  39. </div>
  40. <v-btn
  41. v-if="isVisible"
  42. :to="{ path: '', hash: '#top' }"
  43. aria-label="Revenir en début de page"
  44. class="back-to-the-top secondary"
  45. >
  46. <v-icon>fas fa-arrow-up</v-icon>
  47. </v-btn>
  48. </div>
  49. </template>
  50. <script setup lang="ts">
  51. import { useRouter } from 'vue-router'
  52. import { useDisplay } from 'vuetify'
  53. import type { ComputedRef } from 'vue'
  54. import { useLayoutStore } from '~/stores/layoutStore'
  55. import { ActionMenuItemType } from '~/types/enum/layout'
  56. import type { ActionMenuItem } from '~/types/interface'
  57. const { lgAndUp, mdAndUp } = useDisplay()
  58. const router = useRouter()
  59. const layoutStore = useLayoutStore()
  60. const { isMobileDevice } = useClientDevice()
  61. const telephoneNumber = '09 72 12 60 17'
  62. const isVisible: ComputedRef<boolean> = computed(
  63. () =>
  64. !layoutStore.isHeaderVisible &&
  65. !layoutStore.isBannerVisible &&
  66. !layoutStore.isFooterVisible
  67. )
  68. // Attend l'hydratation avant d'afficher
  69. const showMenu = ref(false)
  70. onNuxtReady(() => {
  71. showMenu.value = true
  72. })
  73. // Actions par défaut du menu, peut-être surchargé via la propriété `actions`
  74. const defaultActions: Array<ActionMenuItem> = [
  75. {
  76. type: ActionMenuItemType.FOLLOW_LINK,
  77. color: 'secondary',
  78. icon: 'far fa-comments',
  79. text: 'Nous contacter',
  80. url: { path: 'nous-contacter', hash: '#form' },
  81. },
  82. {
  83. type: ActionMenuItemType.CALL_US,
  84. color: 'primary',
  85. icon: 'fas fa-phone',
  86. text: 'Nous Appeler',
  87. },
  88. ]
  89. const props = defineProps({
  90. /**
  91. * Actions accessibles via le menu (par défaut : "Nous contacter", "Nous appeler")
  92. */
  93. actions: {
  94. type: Array<ActionMenuItem>,
  95. required: false,
  96. default: [],
  97. },
  98. })
  99. const actionsOrDefault: ComputedRef<Array<ActionMenuItem>> = computed(() => {
  100. return props.actions.length > 0 ? props.actions : defaultActions
  101. })
  102. const callUs = () => {
  103. if (isMobileDevice()) {
  104. window.location.href = `tel:${telephoneNumber}`
  105. } else {
  106. navigateTo({ path: 'nous-contacter', hash: '#details' })
  107. }
  108. }
  109. /**
  110. * On a cliqué sur une des actions du menu
  111. * @param action
  112. */
  113. const onActionClick = (action: ActionMenuItem) => {
  114. switch (action.type) {
  115. case ActionMenuItemType.ASK_FOR_A_DEMO:
  116. router.push({ path: action.url as string, query: { request: 'demo' } })
  117. break
  118. case ActionMenuItemType.CALL_US:
  119. callUs()
  120. break
  121. case ActionMenuItemType.FOLLOW_LINK:
  122. if (!action.url) {
  123. throw new Error('Missing prop : url')
  124. }
  125. navigateTo(action.url, {
  126. open: { target: '_blank' },
  127. })
  128. break
  129. default:
  130. throw new Error('Unrecognized action')
  131. }
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. .sticky-menu {
  136. z-index: 100;
  137. }
  138. // Menu format lateral (pour affichage écrans larges)
  139. .sticky-menu.lateral {
  140. position: fixed;
  141. right: 0;
  142. top: 60%;
  143. transform: translateY(-50%);
  144. float: right;
  145. display: flex;
  146. flex-direction: column;
  147. color: var(--on-primary-color);
  148. font-weight: 500;
  149. font-size: 0.7rem;
  150. line-height: 15px;
  151. text-align: center !important;
  152. letter-spacing: 0.2em;
  153. text-transform: uppercase;
  154. }
  155. // Menu format ruban (pour affichage petits écrans)
  156. .sticky-menu.band {
  157. position: fixed;
  158. height: 46px;
  159. bottom: 0;
  160. width: 100%;
  161. display: flex;
  162. justify-content: center;
  163. background-color: var(--neutral-color);
  164. max-width: 100vw;
  165. padding: 0 6px;
  166. .v-btn {
  167. margin: 6px 2%;
  168. }
  169. }
  170. .square {
  171. position: relative;
  172. width: 7rem;
  173. padding: 1rem;
  174. cursor: pointer;
  175. transition: transform 0.3s ease-in-out;
  176. box-shadow: -1px 2px 6px 1px var(--on-neutral-color-light);
  177. }
  178. .square:hover {
  179. transform: translateX(-10px);
  180. }
  181. .link {
  182. text-decoration: none;
  183. color: var(--on-primary-color);
  184. * {
  185. text-align: center;
  186. }
  187. }
  188. .back-to-the-top {
  189. position: fixed;
  190. right: 12px;
  191. bottom: 58px;
  192. z-index: 100;
  193. height: 48px;
  194. width: 48px;
  195. border-radius: 32px;
  196. }
  197. .primary {
  198. background: var(--action-menu-primary-color);
  199. color: var(--action-menu-on-primary-color);
  200. a {
  201. color: var(--action-menu-on-primary-color);
  202. }
  203. }
  204. .secondary {
  205. background: var(--action-menu-secondary-color);
  206. color: var(--action-menu-on-secondary-color);
  207. a {
  208. color: var(--action-menu-on-secondary-color);
  209. }
  210. }
  211. </style>