ActionMenu.vue 5.3 KB

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